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.
39 #include "gromacs/legacyheaders/typedefs.h"
40 #include "gromacs/mdlib/nb_verlet.h"
41 #include "gromacs/mdlib/nbnxn_simd.h"
45 {1}#include "gromacs/simd/vector_operations.h"
48 #define GMX_SIMD_J_UNROLL_SIZE {3}
51 #include "gromacs/legacyheaders/gmx_omp_nthreads.h"
52 #include "gromacs/legacyheaders/types/force_flags.h"
53 #include "gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_common.h"
54 #include "gromacs/utility/fatalerror.h"
56 /*! \brief Kinds of electrostatic treatments in SIMD Verlet kernels
59 coulktRF, coulktTAB, coulktTAB_TWIN, coulktEWALD, coulktEWALD_TWIN, coulktNR
62 /*! \brief Kinds of Van der Waals treatments in SIMD Verlet kernels
65 vdwktLJCUT_COMBGEOM, vdwktLJCUT_COMBLB, vdwktLJCUT_COMBNONE, vdwktLJFORCESWITCH, vdwktLJPOTSWITCH, vdwktLJEWALDCOMBGEOM, vdwktNR
68 /* Declare and define the kernel function pointer lookup tables.
69 * The minor index of the array goes over both the LJ combination rules,
70 * which is only supported by plain cut-off, and the LJ switch/PME functions.
72 static p_nbk_func_noener p_nbk_noener[coulktNR][vdwktNR] =
74 static p_nbk_func_ener p_nbk_ener[coulktNR][vdwktNR] =
76 static p_nbk_func_ener p_nbk_energrp[coulktNR][vdwktNR] =
80 reduce_group_energies(int ng, int ng_2log,
81 const real *VSvdw, const real *VSc,
84 const int unrollj = GMX_SIMD_REAL_WIDTH/GMX_SIMD_J_UNROLL_SIZE;
85 const int unrollj_half = unrollj/2;
86 int ng_p2, i, j, j0, j1, c, s;
90 /* The size of the x86 SIMD energy group buffer array is:
91 * ng*ng*ng_p2*unrollj_half*simd_width
93 for (i = 0; i < ng; i++)
95 for (j = 0; j < ng; j++)
101 for (j1 = 0; j1 < ng; j1++)
103 for (j0 = 0; j0 < ng; j0++)
105 c = ((i*ng + j1)*ng_p2 + j0)*unrollj_half*unrollj;
106 for (s = 0; s < unrollj_half; s++)
108 Vvdw[i*ng+j0] += VSvdw[c+0];
109 Vvdw[i*ng+j1] += VSvdw[c+1];
110 Vc [i*ng+j0] += VSc [c+0];
111 Vc [i*ng+j1] += VSc [c+1];
121 #include "gromacs/utility/fatalerror.h"
126 {5}(nbnxn_pairlist_set_t gmx_unused *nbl_list,
127 {6}const nbnxn_atomdata_t gmx_unused *nbat,
128 {6}const interaction_const_t gmx_unused *ic,
129 {6}int gmx_unused ewald_excl,
130 {6}rvec gmx_unused *shift_vec,
131 {6}int gmx_unused force_flags,
132 {6}int gmx_unused clearF,
133 {6}real gmx_unused *fshift,
134 {6}real gmx_unused *Vc,
135 {6}real gmx_unused *Vvdw)
139 nbnxn_pairlist_t **nbl;
140 int coulkt, vdwkt = 0;
142 int nthreads gmx_unused;
144 nnbl = nbl_list->nnbl;
147 if (EEL_RF(ic->eeltype) || ic->eeltype == eelCUT)
153 if (ewald_excl == ewaldexclTable)
155 if (ic->rcoulomb == ic->rvdw)
161 coulkt = coulktTAB_TWIN;
166 if (ic->rcoulomb == ic->rvdw)
168 coulkt = coulktEWALD;
172 coulkt = coulktEWALD_TWIN;
177 if (ic->vdwtype == evdwCUT)
179 switch (ic->vdw_modifier)
182 case eintmodPOTSHIFT:
183 switch (nbat->comb_rule)
185 case ljcrGEOM: vdwkt = vdwktLJCUT_COMBGEOM; break;
186 case ljcrLB: vdwkt = vdwktLJCUT_COMBLB; break;
187 case ljcrNONE: vdwkt = vdwktLJCUT_COMBNONE; break;
188 default: gmx_incons("Unknown combination rule");
191 case eintmodFORCESWITCH:
192 vdwkt = vdwktLJFORCESWITCH;
194 case eintmodPOTSWITCH:
195 vdwkt = vdwktLJPOTSWITCH;
198 gmx_incons("Unsupported VdW interaction modifier");
201 else if (ic->vdwtype == evdwPME)
203 if (ic->ljpme_comb_rule == eljpmeLB)
205 gmx_incons("The nbnxn SIMD kernels don't suport LJ-PME with LB");
207 vdwkt = vdwktLJEWALDCOMBGEOM;
211 gmx_incons("Unsupported VdW interaction type");
214 nthreads = gmx_omp_nthreads_get(emntNonbonded);
215 #pragma omp parallel for schedule(static) num_threads(nthreads)
216 for (nb = 0; nb < nnbl; nb++)
218 nbnxn_atomdata_output_t *out;
221 out = &nbat->out[nb];
223 if (clearF == enbvClearFYes)
225 clear_f(nbat, nb, out->f);
228 if ((force_flags & GMX_FORCE_VIRIAL) && nnbl == 1)
234 fshift_p = out->fshift;
236 if (clearF == enbvClearFYes)
238 clear_fshift(fshift_p);
242 if (!(force_flags & GMX_FORCE_ENERGY))
244 /* Don't calculate energies */
245 p_nbk_noener[coulkt][vdwkt](nbl[nb], nbat,
251 else if (out->nV == 1)
253 /* No energy groups */
257 p_nbk_ener[coulkt][vdwkt](nbl[nb], nbat,
267 /* Calculate energy group contributions */
270 for (i = 0; i < out->nVS; i++)
274 for (i = 0; i < out->nVS; i++)
279 p_nbk_energrp[coulkt][vdwkt](nbl[nb], nbat,
287 reduce_group_energies(nbat->nenergrp, nbat->neg_2log,
288 out->VSvdw, out->VSc,
293 if (force_flags & GMX_FORCE_ENERGY)
295 reduce_energies_over_lists(nbat, nnbl, Vvdw, Vc);
300 gmx_incons("{5} called when such kernels "
301 " are not enabled.");
304 #undef GMX_SIMD_J_UNROLL_SIZE