Extract nbnxm grid.h and pairlistwork.h
[alexxy/gromacs.git] / src / gromacs / nbnxm / grid.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35
36 /*! \internal \file
37  *
38  * \brief Declares the grid and bounding box objects
39  *
40  * \author Berk Hess <hess@kth.se>
41  *
42  * \ingroup module_nbnxm
43  */
44
45 #ifndef GMX_NBNXM_GRID_H
46 #define GMX_NBNXM_GRID_H
47
48 #include <memory>
49 #include <vector>
50
51 #include "gromacs/math/vectypes.h"
52 #include "gromacs/simd/simd.h"
53 #include "gromacs/utility/alignedallocator.h"
54
55
56 struct gmx_domdec_zones_t;
57
58
59 #ifndef DOXYGEN
60
61 /* Pair search box lower and upper corner in x,y,z.
62  * Store this in 4 iso 3 reals, which is useful with 4-wide SIMD.
63  * To avoid complicating the code we also use 4 without 4-wide SIMD.
64  */
65 #define NNBSBB_C         4
66 /* Pair search box lower and upper bound in z only. */
67 #define NNBSBB_D         2
68 /* Pair search box lower and upper corner x,y,z indices, entry 3 is unused */
69 #define BB_X  0
70 #define BB_Y  1
71 #define BB_Z  2
72
73 #endif // !DOXYGEN
74
75
76 /* Bounding box for a nbnxn atom cluster */
77 typedef struct {
78     float lower[NNBSBB_C];
79     float upper[NNBSBB_C];
80 } nbnxn_bb_t;
81
82
83 #ifndef DOXYGEN
84
85 /* Bounding box calculations are (currently) always in single precision, so
86  * we only need to check for single precision support here.
87  * This uses less (cache-)memory and SIMD is faster, at least on x86.
88  */
89 #if GMX_SIMD4_HAVE_FLOAT
90 #    define NBNXN_SEARCH_BB_SIMD4      1
91 /* Memory alignment in bytes as required by SIMD aligned loads/stores */
92 #    define NBNXN_SEARCH_BB_MEM_ALIGN  (GMX_SIMD4_WIDTH*sizeof(float))
93 #else
94 #    define NBNXN_SEARCH_BB_SIMD4      0
95 /* No alignment required, but set it so we can call the same routines */
96 #    define NBNXN_SEARCH_BB_MEM_ALIGN  32
97 #endif
98
99
100 #if NBNXN_SEARCH_BB_SIMD4
101 /* Always use 4-wide SIMD for bounding box calculations */
102
103 #    if !GMX_DOUBLE
104 /* Single precision BBs + coordinates, we can also load coordinates with SIMD */
105 #        define NBNXN_SEARCH_SIMD4_FLOAT_X_BB  1
106 #    else
107 #        define NBNXN_SEARCH_SIMD4_FLOAT_X_BB  0
108 #    endif
109
110 /* The packed bounding box coordinate stride is always set to 4.
111  * With AVX we could use 8, but that turns out not to be faster.
112  */
113 #    define STRIDE_PBB       GMX_SIMD4_WIDTH
114 #    define STRIDE_PBB_2LOG  2
115
116 /* Store bounding boxes corners as quadruplets: xxxxyyyyzzzz */
117 #    define NBNXN_BBXXXX  1
118 /* Size of bounding box corners quadruplet */
119 #    define NNBSBB_XXXX  (NNBSBB_D*DIM*STRIDE_PBB)
120
121 #else  /* NBNXN_SEARCH_BB_SIMD4 */
122
123 #    define NBNXN_SEARCH_SIMD4_FLOAT_X_BB  0
124 #    define NBNXN_BBXXXX                   0
125
126 #endif /* NBNXN_SEARCH_BB_SIMD4 */
127
128 #endif // !DOXYGEN
129
130
131 /* A pair-search grid struct for one domain decomposition zone
132  *
133  * Note that when atom groups, instead of individual atoms, are assigned
134  * to grid cells, individual atoms can be geometrically outside the cell
135  * and grid that they have been assigned to (as determined by the center
136  * or geometry of the atom group they belong to).
137  */
138 struct nbnxn_grid_t
139 {
140     rvec     c0;                   /* The lower corner of the (local) grid        */
141     rvec     c1;                   /* The upper corner of the (local) grid        */
142     rvec     size;                 /* c1 - c0                                     */
143     real     atom_density;         /* The atom number density for the local grid  */
144     real     maxAtomGroupRadius;   /* The maximum distance an atom can be outside
145                                     * of a cell and outside of the grid
146                                     */
147
148     gmx_bool bSimple;              /* Is this grid simple or super/sub            */
149     int      na_c;                 /* Number of atoms per cluster                 */
150     int      na_cj;                /* Number of atoms for list j-clusters         */
151     int      na_sc;                /* Number of atoms per super-cluster           */
152     int      na_c_2log;            /* 2log of na_c                                */
153
154     int      numCells[DIM - 1];    /* Number of cells along x/y                   */
155     int      nc;                   /* Total number of cells                       */
156
157     real     cellSize[DIM - 1];    /* size of a cell                              */
158     real     invCellSize[DIM - 1]; /* 1/cellSize                                  */
159
160     int      cell0;                /* Index in nbs->cell corresponding to cell 0  */
161
162     /* Grid data */
163     std::vector<int> cxy_na;        /* The number of atoms for each column in x,y  */
164     std::vector<int> cxy_ind;       /* Grid (super)cell index, offset from cell0   */
165
166     std::vector<int> nsubc;         /* The number of sub cells for each super cell */
167
168     /* Bounding boxes */
169     std::vector<float>                                    bbcz;                /* Bounding boxes in z for the cells */
170     std::vector < nbnxn_bb_t, gmx::AlignedAllocator < nbnxn_bb_t>> bb;         /* 3D bounding boxes for the sub cells */
171     std::vector < nbnxn_bb_t, gmx::AlignedAllocator < nbnxn_bb_t>> bbjStorage; /* 3D j-bounding boxes for the case where
172                                                                                 * the i- and j-cluster sizes are different */
173     gmx::ArrayRef<nbnxn_bb_t>                              bbj;                /* 3D j-bounding boxes */
174     std::vector < float, gmx::AlignedAllocator < float>>            pbb;       /* 3D b. boxes in xxxx format per super cell   */
175
176     /* Bit-flag information */
177     std::vector<int>          flags;     /* Flags for properties of clusters in each cell */
178     std::vector<unsigned int> fep;       /* FEP signal bits for atoms in each cluster */
179
180     /* Statistics */
181     int                       nsubc_tot; /* Total number of subcell, used for printing  */
182 };
183
184 #endif