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.
48 #include "gmx_omp_nthreads.h"
49 #include "../nbnxn_consts.h"
50 #include "nbnxn_kernel_common.h"
52 #ifdef GMX_NBNXN_SIMD_4XN
54 #include "nbnxn_kernel_simd_4xn.h"
56 /* Include all flavors of the SSE or AVX 4xN kernel loops */
58 #if GMX_NBNXN_SIMD_BITWIDTH == 128
59 #define GMX_MM128_HERE
61 #if GMX_NBNXN_SIMD_BITWIDTH == 256
62 #define GMX_MM256_HERE
64 #error "unsupported GMX_NBNXN_SIMD_BITWIDTH"
68 /* Analytical reaction-field kernels */
71 #include "nbnxn_kernel_simd_4xn_includes.h"
75 /* Tabulated exclusion interaction electrostatics kernels */
78 /* Single cut-off: rcoulomb = rvdw */
79 #include "nbnxn_kernel_simd_4xn_includes.h"
81 /* Twin cut-off: rcoulomb >= rvdw */
82 #define VDW_CUTOFF_CHECK
83 #include "nbnxn_kernel_simd_4xn_includes.h"
84 #undef VDW_CUTOFF_CHECK
88 /* Analytical Ewald exclusion interaction electrostatics kernels */
89 #define CALC_COUL_EWALD
91 /* Single cut-off: rcoulomb = rvdw */
92 #include "nbnxn_kernel_simd_4xn_includes.h"
94 /* Twin cut-off: rcoulomb >= rvdw */
95 #define VDW_CUTOFF_CHECK
96 #include "nbnxn_kernel_simd_4xn_includes.h"
97 #undef VDW_CUTOFF_CHECK
99 #undef CALC_COUL_EWALD
102 typedef void (*p_nbk_func_ener)(const nbnxn_pairlist_t *nbl,
103 const nbnxn_atomdata_t *nbat,
104 const interaction_const_t *ic,
111 typedef void (*p_nbk_func_noener)(const nbnxn_pairlist_t *nbl,
112 const nbnxn_atomdata_t *nbat,
113 const interaction_const_t *ic,
119 coultRF, coultTAB, coultTAB_TWIN, coultEWALD, coultEWALD_TWIN, coultNR
122 #define NBK_FN(elec, ljcomb) nbnxn_kernel_simd_4xn_ ## elec ## _comb_ ## ljcomb ## _ener
123 static p_nbk_func_ener p_nbk_ener[coultNR][ljcrNR] =
124 { { NBK_FN(rf, geom), NBK_FN(rf, lb), NBK_FN(rf, none) },
125 { NBK_FN(tab, geom), NBK_FN(tab, lb), NBK_FN(tab, none) },
126 { NBK_FN(tab_twin, geom), NBK_FN(tab_twin, lb), NBK_FN(tab_twin, none) },
127 { NBK_FN(ewald, geom), NBK_FN(ewald, lb), NBK_FN(ewald, none) },
128 { NBK_FN(ewald_twin, geom), NBK_FN(ewald_twin, lb), NBK_FN(ewald_twin, none) } };
131 #define NBK_FN(elec, ljcomb) nbnxn_kernel_simd_4xn_ ## elec ## _comb_ ## ljcomb ## _energrp
132 static p_nbk_func_ener p_nbk_energrp[coultNR][ljcrNR] =
133 { { NBK_FN(rf, geom), NBK_FN(rf, lb), NBK_FN(rf, none) },
134 { NBK_FN(tab, geom), NBK_FN(tab, lb), NBK_FN(tab, none) },
135 { NBK_FN(tab_twin, geom), NBK_FN(tab_twin, lb), NBK_FN(tab_twin, none) },
136 { NBK_FN(ewald, geom), NBK_FN(ewald, lb), NBK_FN(ewald, none) },
137 { NBK_FN(ewald_twin, geom), NBK_FN(ewald_twin, lb), NBK_FN(ewald_twin, none) } };
140 #define NBK_FN(elec, ljcomb) nbnxn_kernel_simd_4xn_ ## elec ## _comb_ ## ljcomb ## _noener
141 static p_nbk_func_noener p_nbk_noener[coultNR][ljcrNR] =
142 { { NBK_FN(rf, geom), NBK_FN(rf, lb), NBK_FN(rf, none) },
143 { NBK_FN(tab, geom), NBK_FN(tab, lb), NBK_FN(tab, none) },
144 { NBK_FN(tab_twin, geom), NBK_FN(tab_twin, lb), NBK_FN(tab_twin, none) },
145 { NBK_FN(ewald, geom), NBK_FN(ewald, lb), NBK_FN(ewald, none) },
146 { NBK_FN(ewald_twin, geom), NBK_FN(ewald_twin, lb), NBK_FN(ewald_twin, none) } };
150 static void reduce_group_energies(int ng, int ng_2log,
151 const real *VSvdw, const real *VSc,
152 real *Vvdw, real *Vc)
154 const int simd_width = GMX_SIMD_WIDTH_HERE;
155 const int unrollj_half = GMX_SIMD_WIDTH_HERE/2;
156 int ng_p2, i, j, j0, j1, c, s;
158 ng_p2 = (1<<ng_2log);
160 /* The size of the x86 SIMD energy group buffer array is:
161 * ng*ng*ng_p2*unrollj_half*simd_width
163 for (i = 0; i < ng; i++)
165 for (j = 0; j < ng; j++)
171 for (j1 = 0; j1 < ng; j1++)
173 for (j0 = 0; j0 < ng; j0++)
175 c = ((i*ng + j1)*ng_p2 + j0)*unrollj_half*simd_width;
176 for (s = 0; s < unrollj_half; s++)
178 Vvdw[i*ng+j0] += VSvdw[c+0];
179 Vvdw[i*ng+j1] += VSvdw[c+1];
180 Vc [i*ng+j0] += VSc [c+0];
181 Vc [i*ng+j1] += VSc [c+1];
189 #endif /* GMX_NBNXN_SIMD_4XN */
192 nbnxn_kernel_simd_4xn(nbnxn_pairlist_set_t *nbl_list,
193 const nbnxn_atomdata_t *nbat,
194 const interaction_const_t *ic,
202 #ifdef GMX_NBNXN_SIMD_4XN
205 nbnxn_pairlist_t **nbl;
209 nnbl = nbl_list->nnbl;
212 if (EEL_RF(ic->eeltype) || ic->eeltype == eelCUT)
218 if (ewald_excl == ewaldexclTable)
220 if (ic->rcoulomb == ic->rvdw)
226 coult = coultTAB_TWIN;
231 if (ic->rcoulomb == ic->rvdw)
237 coult = coultEWALD_TWIN;
242 #pragma omp parallel for schedule(static) num_threads(gmx_omp_nthreads_get(emntNonbonded))
243 for (nb = 0; nb < nnbl; nb++)
245 nbnxn_atomdata_output_t *out;
248 out = &nbat->out[nb];
250 if (clearF == enbvClearFYes)
252 clear_f(nbat, nb, out->f);
255 if ((force_flags & GMX_FORCE_VIRIAL) && nnbl == 1)
261 fshift_p = out->fshift;
263 if (clearF == enbvClearFYes)
265 clear_fshift(fshift_p);
269 /* With Ewald type electrostatics we the forces for excluded atom pairs
270 * should not contribute to the virial sum. The exclusion forces
271 * are not calculate in the energy kernels, but are in _noener.
273 if (!((force_flags & GMX_FORCE_ENERGY) ||
274 (EEL_FULL(ic->eeltype) && (force_flags & GMX_FORCE_VIRIAL))))
276 /* Don't calculate energies */
277 p_nbk_noener[coult][nbat->comb_rule](nbl[nb], nbat,
283 else if (out->nV == 1 || !(force_flags & GMX_FORCE_ENERGY))
285 /* No energy groups */
289 p_nbk_ener[coult][nbat->comb_rule](nbl[nb], nbat,
299 /* Calculate energy group contributions */
302 for (i = 0; i < out->nVS; i++)
306 for (i = 0; i < out->nVS; i++)
311 p_nbk_energrp[coult][nbat->comb_rule](nbl[nb], nbat,
319 reduce_group_energies(nbat->nenergrp, nbat->neg_2log,
320 out->VSvdw, out->VSc,
325 if (force_flags & GMX_FORCE_ENERGY)
327 reduce_energies_over_lists(nbat, nnbl, Vvdw, Vc);
332 gmx_incons("nbnxn_kernel_simd_4xn called while GROMACS was configured without 4xN SIMD kernels enabled");