2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2012, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
39 #ifndef _nbnxn_internal_h
40 #define _nbnxn_internal_h
44 #include "gmx_cyclecounter.h"
47 /* The include below sets the SIMD instruction type (precision+width)
48 * for all nbnxn SIMD search and non-bonded kernel code.
50 #ifdef GMX_NBNXN_HALF_WIDTH_SIMD
51 #define GMX_USE_HALF_WIDTH_SIMD_HERE
53 #include "gmx_simd_macros.h"
62 /* Use 4-way SIMD for, always, single precision bounding box calculations */
63 #define NBNXN_SEARCH_BB_SSE
68 /* Memory alignment in bytes as required by SIMD aligned loads/stores */
69 #define NBNXN_MEM_ALIGN (GMX_SIMD_WIDTH_HERE*sizeof(real))
71 /* No alignment required, but set it so we can call the same routines */
72 #define NBNXN_MEM_ALIGN 32
76 /* Pair search box lower and upper corner in x,y,z.
77 * Store this in 4 iso 3 reals, which is useful with SSE.
78 * To avoid complicating the code we also use 4 without SSE.
81 /* Pair search box lower and upper bound in z only. */
83 /* Pair search box lower and upper corner x,y,z indices, entry 3 is unused */
88 /* Bounding box for a nbnxn atom cluster */
90 float lower[NNBSBB_C];
91 float upper[NNBSBB_C];
95 /* A pair-search grid struct for one domain decomposition zone */
97 rvec c0; /* The lower corner of the (local) grid */
98 rvec c1; /* The upper corner of the (local) grid */
99 real atom_density; /* The atom number density for the local grid */
101 gmx_bool bSimple; /* Is this grid simple or super/sub */
102 int na_c; /* Number of atoms per cluster */
103 int na_cj; /* Number of atoms for list j-clusters */
104 int na_sc; /* Number of atoms per super-cluster */
105 int na_c_2log; /* 2log of na_c */
107 int ncx; /* Number of (super-)cells along x */
108 int ncy; /* Number of (super-)cells along y */
109 int nc; /* Total number of (super-)cells */
111 real sx; /* x-size of a (super-)cell */
112 real sy; /* y-size of a (super-)cell */
113 real inv_sx; /* 1/sx */
114 real inv_sy; /* 1/sy */
116 int cell0; /* Index in nbs->cell corresponding to cell 0 */
118 int *cxy_na; /* The number of atoms for each column in x,y */
119 int *cxy_ind; /* Grid (super)cell index, offset from cell0 */
120 int cxy_nalloc; /* Allocation size for cxy_na and cxy_ind */
122 int *nsubc; /* The number of sub cells for each super cell */
123 float *bbcz; /* Bounding boxes in z for the super cells */
124 nbnxn_bb_t *bb; /* 3D bounding boxes for the sub cells */
125 nbnxn_bb_t *bbj; /* 3D j-b.boxes for SSE-double or AVX-single */
126 float *pbb; /* 3D b. boxes in xxxx format per super cell */
127 int *flags; /* Flag for the super cells */
128 int nc_nalloc; /* Allocation size for the pointers above */
130 float *bbcz_simple; /* bbcz for simple grid converted from super */
131 nbnxn_bb_t *bb_simple; /* bb for simple grid converted from super */
132 int *flags_simple; /* flags for simple grid converted from super */
133 int nc_nalloc_simple; /* Allocation size for the pointers above */
135 int nsubc_tot; /* Total number of subcell, used for printing */
138 #ifdef GMX_NBNXN_SIMD
140 typedef struct nbnxn_x_ci_simd_4xn {
141 /* The i-cluster coordinates for simple search */
142 gmx_mm_pr ix_SSE0, iy_SSE0, iz_SSE0;
143 gmx_mm_pr ix_SSE1, iy_SSE1, iz_SSE1;
144 gmx_mm_pr ix_SSE2, iy_SSE2, iz_SSE2;
145 gmx_mm_pr ix_SSE3, iy_SSE3, iz_SSE3;
146 } nbnxn_x_ci_simd_4xn_t;
148 typedef struct nbnxn_x_ci_simd_2xnn {
149 /* The i-cluster coordinates for simple search */
150 gmx_mm_pr ix_SSE0, iy_SSE0, iz_SSE0;
151 gmx_mm_pr ix_SSE2, iy_SSE2, iz_SSE2;
152 } nbnxn_x_ci_simd_2xnn_t;
156 /* Working data for the actual i-supercell during pair search */
157 typedef struct nbnxn_list_work {
158 gmx_cache_protect_t cp0; /* Protect cache between threads */
160 nbnxn_bb_t *bb_ci; /* The bounding boxes, pbc shifted, for each cluster */
161 float *pbb_ci; /* As bb_ci, but in xxxx packed format */
162 real *x_ci; /* The coordinates, pbc shifted, for each atom */
163 #ifdef GMX_NBNXN_SIMD
164 nbnxn_x_ci_simd_4xn_t *x_ci_simd_4xn;
165 nbnxn_x_ci_simd_2xnn_t *x_ci_simd_2xnn;
167 int cj_ind; /* The current cj_ind index for the current list */
168 int cj4_init; /* The first unitialized cj4 block */
170 float *d2; /* Bounding box distance work array */
172 nbnxn_cj_t *cj; /* The j-cell list */
173 int cj_nalloc; /* Allocation size of cj */
175 int ncj_noq; /* Nr. of cluster pairs without Coul for flop count */
176 int ncj_hlj; /* Nr. of cluster pairs with 1/2 LJ for flop count */
178 int *sort; /* Sort index */
179 int sort_nalloc; /* Allocation size of sort */
181 nbnxn_sci_t *sci_sort; /* Second sci array, for sorting */
182 int sci_sort_nalloc; /* Allocation size of sci_sort */
184 gmx_cache_protect_t cp1; /* Protect cache between threads */
187 /* Function type for setting the i-atom coordinate working data */
189 gmx_icell_set_x_t (int ci,
190 real shx, real shy, real shz,
192 int stride, const real *x,
193 nbnxn_list_work_t *work);
195 static gmx_icell_set_x_t icell_set_x_simple;
196 #ifdef GMX_NBNXN_SIMD
197 static gmx_icell_set_x_t icell_set_x_simple_simd_4xn;
198 static gmx_icell_set_x_t icell_set_x_simple_simd_2xnn;
200 static gmx_icell_set_x_t icell_set_x_supersub;
201 #ifdef NBNXN_SEARCH_SSE
202 static gmx_icell_set_x_t icell_set_x_supersub_sse8;
205 /* Local cycle count struct for profiling */
212 /* Local cycle count enum for profiling */
214 enbsCCgrid, enbsCCsearch, enbsCCcombine, enbsCCreducef, enbsCCnr
217 /* Thread-local work struct, contains part of nbnxn_grid_t */
219 gmx_cache_protect_t cp0;
225 int sort_work_nalloc;
227 nbnxn_buffer_flags_t buffer_flags; /* Flags for force buffer access */
229 int ndistc; /* Number of distance checks for flop counting */
231 nbnxn_cycle_t cc[enbsCCnr];
233 gmx_cache_protect_t cp1;
234 } nbnxn_search_work_t;
236 /* Main pair-search struct, contains the grid(s), not the pair-list(s) */
237 typedef struct nbnxn_search {
238 int ePBC; /* PBC type enum */
239 matrix box; /* The periodic unit-cell */
241 gmx_bool DomDec; /* Are we doing domain decomposition? */
242 ivec dd_dim; /* Are we doing DD in x,y,z? */
243 gmx_domdec_zones_t *zones; /* The domain decomposition zones */
245 int ngrid; /* The number of grids, equal to #DD-zones */
246 nbnxn_grid_t *grid; /* Array of grids, size ngrid */
247 int *cell; /* Actual allocated cell array for all grids */
248 int cell_nalloc; /* Allocation size of cell */
249 int *a; /* Atom index for grid, the inverse of cell */
250 int a_nalloc; /* Allocation size of a */
252 int natoms_local; /* The local atoms run from 0 to natoms_local */
253 int natoms_nonlocal; /* The non-local atoms run from natoms_local
254 * to natoms_nonlocal */
256 gmx_bool print_cycles;
258 nbnxn_cycle_t cc[enbsCCnr];
260 gmx_icell_set_x_t *icell_set_x; /* Function for setting i-coords */
262 int nthread_max; /* Maximum number of threads for pair-search */
263 nbnxn_search_work_t *work; /* Work array, size nthread_max */
267 static void nbs_cycle_start(nbnxn_cycle_t *cc)
269 cc->start = gmx_cycles_read();
272 static void nbs_cycle_stop(nbnxn_cycle_t *cc)
274 cc->c += gmx_cycles_read() - cc->start;