2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, 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.
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.
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.
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.
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.
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.
36 #ifndef _nbnxn_internal_h
37 #define _nbnxn_internal_h
40 #include "nbnxn_simd.h"
42 #include "gromacs/timing/cyclecounter.h"
45 /* Bounding box calculations are (currently) always in single precision, so
46 * we only need to check for single precision support here.
47 * This uses less (cache-)memory and SIMD is faster, at least on x86.
49 #ifdef GMX_SIMD4_HAVE_FLOAT
50 #define NBNXN_SEARCH_BB_SIMD4
60 /* Memory alignment in bytes as required by SIMD aligned loads/stores */
61 #define NBNXN_MEM_ALIGN (GMX_SIMD_REAL_WIDTH*sizeof(real))
63 /* No alignment required, but set it so we can call the same routines */
64 #define NBNXN_MEM_ALIGN 32
68 #ifdef NBNXN_SEARCH_BB_SIMD4
69 /* Memory alignment in bytes as required by SIMD aligned loads/stores */
70 #define NBNXN_SEARCH_BB_MEM_ALIGN (GMX_SIMD4_WIDTH*sizeof(float))
72 /* No alignment required, but set it so we can call the same routines */
73 #define NBNXN_SEARCH_BB_MEM_ALIGN 32
77 /* Pair search box lower and upper corner in x,y,z.
78 * Store this in 4 iso 3 reals, which is useful with 4-wide SIMD.
79 * To avoid complicating the code we also use 4 without 4-wide SIMD.
82 /* Pair search box lower and upper bound in z only. */
84 /* Pair search box lower and upper corner x,y,z indices, entry 3 is unused */
89 /* Bounding box for a nbnxn atom cluster */
91 float lower[NNBSBB_C];
92 float upper[NNBSBB_C];
96 /* A pair-search grid struct for one domain decomposition zone */
98 rvec c0; /* The lower corner of the (local) grid */
99 rvec c1; /* The upper corner of the (local) grid */
100 real atom_density; /* The atom number density for the local grid */
102 gmx_bool bSimple; /* Is this grid simple or super/sub */
103 int na_c; /* Number of atoms per cluster */
104 int na_cj; /* Number of atoms for list j-clusters */
105 int na_sc; /* Number of atoms per super-cluster */
106 int na_c_2log; /* 2log of na_c */
108 int ncx; /* Number of (super-)cells along x */
109 int ncy; /* Number of (super-)cells along y */
110 int nc; /* Total number of (super-)cells */
112 real sx; /* x-size of a (super-)cell */
113 real sy; /* y-size of a (super-)cell */
114 real inv_sx; /* 1/sx */
115 real inv_sy; /* 1/sy */
117 int cell0; /* Index in nbs->cell corresponding to cell 0 */
119 int *cxy_na; /* The number of atoms for each column in x,y */
120 int *cxy_ind; /* Grid (super)cell index, offset from cell0 */
121 int cxy_nalloc; /* Allocation size for cxy_na and cxy_ind */
123 int *nsubc; /* The number of sub cells for each super cell */
124 float *bbcz; /* Bounding boxes in z for the super cells */
125 nbnxn_bb_t *bb; /* 3D bounding boxes for the sub cells */
126 nbnxn_bb_t *bbj; /* 3D j-bounding boxes for the case where *
127 * the i- and j-cluster sizes are different */
128 float *pbb; /* 3D b. boxes in xxxx format per super cell */
129 int *flags; /* Flag for the super cells */
130 int nc_nalloc; /* Allocation size for the pointers above */
132 float *bbcz_simple; /* bbcz for simple grid converted from super */
133 nbnxn_bb_t *bb_simple; /* bb for simple grid converted from super */
134 int *flags_simple; /* flags for simple grid converted from super */
135 int nc_nalloc_simple; /* Allocation size for the pointers above */
137 int nsubc_tot; /* Total number of subcell, used for printing */
140 #ifdef GMX_NBNXN_SIMD
142 typedef struct nbnxn_x_ci_simd_4xn {
143 /* The i-cluster coordinates for simple search */
144 gmx_simd_real_t ix_S0, iy_S0, iz_S0;
145 gmx_simd_real_t ix_S1, iy_S1, iz_S1;
146 gmx_simd_real_t ix_S2, iy_S2, iz_S2;
147 gmx_simd_real_t ix_S3, iy_S3, iz_S3;
148 } nbnxn_x_ci_simd_4xn_t;
150 typedef struct nbnxn_x_ci_simd_2xnn {
151 /* The i-cluster coordinates for simple search */
152 gmx_simd_real_t ix_S0, iy_S0, iz_S0;
153 gmx_simd_real_t ix_S2, iy_S2, iz_S2;
154 } nbnxn_x_ci_simd_2xnn_t;
158 /* Working data for the actual i-supercell during pair search */
159 typedef struct nbnxn_list_work {
160 gmx_cache_protect_t cp0; /* Protect cache between threads */
162 nbnxn_bb_t *bb_ci; /* The bounding boxes, pbc shifted, for each cluster */
163 float *pbb_ci; /* As bb_ci, but in xxxx packed format */
164 real *x_ci; /* The coordinates, pbc shifted, for each atom */
165 #ifdef GMX_NBNXN_SIMD
166 nbnxn_x_ci_simd_4xn_t *x_ci_simd_4xn;
167 nbnxn_x_ci_simd_2xnn_t *x_ci_simd_2xnn;
169 int cj_ind; /* The current cj_ind index for the current list */
170 int cj4_init; /* The first unitialized cj4 block */
172 float *d2; /* Bounding box distance work array */
174 nbnxn_cj_t *cj; /* The j-cell list */
175 int cj_nalloc; /* Allocation size of cj */
177 int ncj_noq; /* Nr. of cluster pairs without Coul for flop count */
178 int ncj_hlj; /* Nr. of cluster pairs with 1/2 LJ for flop count */
180 int *sort; /* Sort index */
181 int sort_nalloc; /* Allocation size of sort */
183 nbnxn_sci_t *sci_sort; /* Second sci array, for sorting */
184 int sci_sort_nalloc; /* Allocation size of sci_sort */
186 gmx_cache_protect_t cp1; /* Protect cache between threads */
189 /* Function type for setting the i-atom coordinate working data */
191 gmx_icell_set_x_t (int ci,
192 real shx, real shy, real shz,
194 int stride, const real *x,
195 nbnxn_list_work_t *work);
197 static gmx_icell_set_x_t icell_set_x_simple;
198 #ifdef GMX_NBNXN_SIMD
199 static gmx_icell_set_x_t icell_set_x_simple_simd_4xn;
200 static gmx_icell_set_x_t icell_set_x_simple_simd_2xnn;
202 static gmx_icell_set_x_t icell_set_x_supersub;
203 #ifdef NBNXN_SEARCH_SSE
204 static gmx_icell_set_x_t icell_set_x_supersub_sse8;
207 /* Local cycle count struct for profiling */
214 /* Local cycle count enum for profiling */
216 enbsCCgrid, enbsCCsearch, enbsCCcombine, enbsCCreducef, enbsCCnr
219 /* Thread-local work struct, contains part of nbnxn_grid_t */
221 gmx_cache_protect_t cp0;
227 int sort_work_nalloc;
229 nbnxn_buffer_flags_t buffer_flags; /* Flags for force buffer access */
231 int ndistc; /* Number of distance checks for flop counting */
233 nbnxn_cycle_t cc[enbsCCnr];
235 gmx_cache_protect_t cp1;
236 } nbnxn_search_work_t;
238 /* Main pair-search struct, contains the grid(s), not the pair-list(s) */
239 typedef struct nbnxn_search {
240 int ePBC; /* PBC type enum */
241 matrix box; /* The periodic unit-cell */
243 gmx_bool DomDec; /* Are we doing domain decomposition? */
244 ivec dd_dim; /* Are we doing DD in x,y,z? */
245 gmx_domdec_zones_t *zones; /* The domain decomposition zones */
247 int ngrid; /* The number of grids, equal to #DD-zones */
248 nbnxn_grid_t *grid; /* Array of grids, size ngrid */
249 int *cell; /* Actual allocated cell array for all grids */
250 int cell_nalloc; /* Allocation size of cell */
251 int *a; /* Atom index for grid, the inverse of cell */
252 int a_nalloc; /* Allocation size of a */
254 int natoms_local; /* The local atoms run from 0 to natoms_local */
255 int natoms_nonlocal; /* The non-local atoms run from natoms_local
256 * to natoms_nonlocal */
258 gmx_bool print_cycles;
260 nbnxn_cycle_t cc[enbsCCnr];
262 gmx_icell_set_x_t *icell_set_x; /* Function for setting i-coords */
264 int nthread_max; /* Maximum number of threads for pair-search */
265 nbnxn_search_work_t *work; /* Work array, size nthread_max */
269 static void nbs_cycle_start(nbnxn_cycle_t *cc)
271 cc->start = gmx_cycles_read();
274 static void nbs_cycle_stop(nbnxn_cycle_t *cc)
276 cc->c += gmx_cycles_read() - cc->start;