Turn t_forcerec.shift_vec into an std::vector of gmx::RVec
authorkanduri <kanduri@cscs.ch>
Tue, 30 Mar 2021 11:53:51 +0000 (11:53 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Tue, 30 Mar 2021 11:53:51 +0000 (11:53 +0000)
Change function signatures so that call sites have minimal changes

24 files changed:
api/nblib/gmxsetup.cpp
src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp
src/gromacs/mdlib/forcerec.cpp
src/gromacs/mdlib/sim_util.cpp
src/gromacs/mdtypes/forcerec.h
src/gromacs/nbnxm/atomdata.cpp
src/gromacs/nbnxm/atomdata.h
src/gromacs/nbnxm/benchmark/bench_system.cpp
src/gromacs/nbnxm/kerneldispatch.cpp
src/gromacs/nbnxm/kernels_reference/kernel_gpu_ref.cpp
src/gromacs/nbnxm/kernels_reference/kernel_gpu_ref.h
src/gromacs/nbnxm/kernels_reference/kernel_ref_prune.cpp
src/gromacs/nbnxm/kernels_reference/kernel_ref_prune.h
src/gromacs/nbnxm/kernels_simd_2xmm/kernel_prune.cpp
src/gromacs/nbnxm/kernels_simd_2xmm/kernel_prune.h
src/gromacs/nbnxm/kernels_simd_4xm/kernel_prune.cpp
src/gromacs/nbnxm/kernels_simd_4xm/kernel_prune.h
src/gromacs/nbnxm/nbnxm.h
src/gromacs/nbnxm/pairlistset.h
src/gromacs/nbnxm/pairlistsets.h
src/gromacs/nbnxm/prunekerneldispatch.cpp
src/gromacs/pbcutil/pbc.cpp
src/gromacs/pbcutil/pbc.h
src/gromacs/pbcutil/tests/pbc.cpp

index b19744755b501a126f8c656b08f023b783ce7d8c..fd3cfd2a878eda8f0bf826062f882b9ddb83ba92 100644 (file)
@@ -298,7 +298,7 @@ void NbvSetupUtil::setupForceRec(const matrix& box)
 {
     assert((gmxForceCalculator_->forcerec_ && "Forcerec not initialized"));
     gmxForceCalculator_->forcerec_->nbfp = nonbondedParameters_;
-    snew(gmxForceCalculator_->forcerec_->shift_vec, numShiftVectors);
+    gmxForceCalculator_->forcerec_->shift_vec.resize(numShiftVectors);
     calc_shifts(box, gmxForceCalculator_->forcerec_->shift_vec);
 }
 
index 86c17b74792cbb5b0686e3121b1b3e493a0a0ff8..8fde84db9fd86cf40bee0c5703183df2834e5f7e 100644 (file)
@@ -241,7 +241,7 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
     gmx::ArrayRef<const int> shift  = nlist.shift;
     gmx::ArrayRef<const int> gid    = nlist.gid;
 
-    const real*               shiftvec  = fr.shift_vec[0];
+    const auto                shiftvec  = fr.shift_vec;
     const int                 ntype     = fr.ntype;
     gmx::ArrayRef<const real> nbfp      = fr.nbfp;
     gmx::ArrayRef<const real> nbfp_grid = fr.ljpme_c6grid;
@@ -385,10 +385,11 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
     {
         int npair_within_cutoff = 0;
 
-        const int  is3   = 3 * shift[n];
-        const real shX   = shiftvec[is3];
-        const real shY   = shiftvec[is3 + 1];
-        const real shZ   = shiftvec[is3 + 2];
+        const int  is    = shift[n];
+        const int  is3   = DIM * is;
+        const real shX   = shiftvec[is][XX];
+        const real shY   = shiftvec[is][YY];
+        const real shZ   = shiftvec[is][ZZ];
         const int  nj0   = jindex[n];
         const int  nj1   = jindex[n + 1];
         const int  ii    = iinr[n];
index cda7d5743e33f9605c349d9bba22fff10102a478..c2004aa45e39be603fa23b4ce85f92b3aac45da3 100644 (file)
@@ -1218,9 +1218,9 @@ void init_forcerec(FILE*                            fplog,
         forcerec->forceHelperBuffers.emplace_back(haveDirectVirialContributions);
     }
 
-    if (forcerec->shift_vec == nullptr)
+    if (forcerec->shift_vec.empty())
     {
-        snew(forcerec->shift_vec, SHIFTS);
+        forcerec->shift_vec.resize(SHIFTS);
     }
 
     if (forcerec->nbfp.empty())
@@ -1418,6 +1418,5 @@ t_forcerec::t_forcerec() = default;
 t_forcerec::~t_forcerec()
 {
     /* Note: This code will disappear when types are converted to C++ */
-    sfree(shift_vec);
     sfree(ewc_t);
 }
index f02d9fa9c7a42307016db383acf2ece51ef888a3..0d27bedbdac23fe42a81e28a11a4a4b4ad79851e 100644 (file)
@@ -165,8 +165,9 @@ static void calc_virial(int                              start,
                         PbcType                          pbcType)
 {
     /* The short-range virial from surrounding boxes */
-    const rvec* fshift = as_rvec_array(forceWithShiftForces.shiftForces().data());
-    calc_vir(SHIFTS, fr->shift_vec, fshift, vir_part, pbcType == PbcType::Screw, box);
+    const rvec* fshift          = as_rvec_array(forceWithShiftForces.shiftForces().data());
+    const rvec* shiftVecPointer = as_rvec_array(fr->shift_vec.data());
+    calc_vir(SHIFTS, shiftVecPointer, fshift, vir_part, pbcType == PbcType::Screw, box);
     inc_nrnb(nrnb, eNR_VIRIAL, SHIFTS);
 
     /* Calculate partial virial, for local atoms only, based on short range.
index f6404b48481645ea10aff18de59eb4cb27ec991b..ee8425551fd6f739db58f0e51466b4a9a19a64fe 100644 (file)
@@ -44,6 +44,7 @@
 
 #include "gromacs/math/vectypes.h"
 #include "gromacs/mdtypes/md_enums.h"
+#include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/real.h"
@@ -240,7 +241,7 @@ struct t_forcerec
     /* Information about atom properties for local and non-local atoms */
     std::vector<int> cginfo;
 
-    rvec* shift_vec = nullptr;
+    std::vector<gmx::RVec> shift_vec;
 
     std::unique_ptr<gmx::WholeMoleculeTransform> wholeMoleculeTransform;
 
index d9639e9b5be8627cb8bd7a6b30f0367a1412a4f9..1fa91c6f039f97f859a4f5e423bff9a7c61d47df 100644 (file)
@@ -946,13 +946,10 @@ void nbnxn_atomdata_set(nbnxn_atomdata_t*     nbat,
 }
 
 /* Copies the shift vector array to nbnxn_atomdata_t */
-void nbnxn_atomdata_copy_shiftvec(gmx_bool bDynamicBox, rvec* shift_vec, nbnxn_atomdata_t* nbat)
+void nbnxn_atomdata_copy_shiftvec(gmx_bool bDynamicBox, gmx::ArrayRef<gmx::RVec> shift_vec, nbnxn_atomdata_t* nbat)
 {
     nbat->bDynamicBox = bDynamicBox;
-    for (int i = 0; i < SHIFTS; i++)
-    {
-        copy_rvec(shift_vec[i], nbat->shift_vec[i]);
-    }
+    std::copy(shift_vec.begin(), shift_vec.end(), nbat->shift_vec.begin());
 }
 
 // This is slightly different from nbnxn_get_atom_range(...) at the end of the file
index 39a46794fa7cb5b15db1ec3b8d3282efc0676381..d676ae1f4cce287077b7f58918d1febe06963317 100644 (file)
@@ -337,7 +337,9 @@ void nbnxn_atomdata_set(nbnxn_atomdata_t*         nbat,
                         gmx::ArrayRef<const int>  atomInfo);
 
 //! Copy the shift vectors to nbat
-void nbnxn_atomdata_copy_shiftvec(gmx_bool dynamic_box, rvec* shift_vec, nbnxn_atomdata_t* nbat);
+void nbnxn_atomdata_copy_shiftvec(gmx_bool                 dynamic_box,
+                                  gmx::ArrayRef<gmx::RVec> shift_vec,
+                                  nbnxn_atomdata_t*        nbat);
 
 /*! \brief Transform coordinates to xbat layout
  *
index 999457ae62a39de37d50f946dbce571fe481c346..3076939ce5c80a576f4f8d10d8ab3e2ddd18dcc2 100644 (file)
@@ -200,7 +200,7 @@ BenchmarkSystem::BenchmarkSystem(const int multiplicationFactor, const std::stri
 
     forceRec.ntype = numAtomTypes;
     forceRec.nbfp  = nonbondedParameters;
-    snew(forceRec.shift_vec, SHIFTS);
+    forceRec.shift_vec.resize(SHIFTS);
     calc_shifts(box, forceRec.shift_vec);
     if (!outputFile.empty())
     {
index 0bfa57b9926e060dc2917df15e8244d1c62a6f72..24608cf4567dfbf504de9109924326931c61b30c 100644 (file)
@@ -238,16 +238,16 @@ static int getVdwKernelType(const Nbnxm::KernelSetup&       kernelSetup,
  * \param[out]    vVdw          Output buffer for Van der Waals energies
  * \param[in]     wcycle        Pointer to cycle counting data structure.
  */
-static void nbnxn_kernel_cpu(const PairlistSet&         pairlistSet,
-                             const Nbnxm::KernelSetup&  kernelSetup,
-                             nbnxn_atomdata_t*          nbat,
-                             const interaction_const_t& ic,
-                             rvec*                      shiftVectors,
-                             const gmx::StepWorkload&   stepWork,
-                             int                        clearF,
-                             real*                      vCoulomb,
-                             real*                      vVdw,
-                             gmx_wallcycle*             wcycle)
+static void nbnxn_kernel_cpu(const PairlistSet&             pairlistSet,
+                             const Nbnxm::KernelSetup&      kernelSetup,
+                             nbnxn_atomdata_t*              nbat,
+                             const interaction_const_t&     ic,
+                             gmx::ArrayRef<const gmx::RVec> shiftVectors,
+                             const gmx::StepWorkload&       stepWork,
+                             int                            clearF,
+                             real*                          vCoulomb,
+                             real*                          vVdw,
+                             gmx_wallcycle*                 wcycle)
 {
 
     const nbnxn_atomdata_t::Params& nbatParams = nbat->params();
@@ -257,6 +257,8 @@ static void nbnxn_kernel_cpu(const PairlistSet&         pairlistSet,
 
     gmx::ArrayRef<const NbnxnPairlistCpu> pairlists = pairlistSet.cpuLists();
 
+    auto shiftVecPointer = as_rvec_array(shiftVectors.data());
+
     int gmx_unused nthreads = gmx_omp_nthreads_get(emntNonbonded);
     wallcycle_sub_start(wcycle, ewcsNONBONDED_CLEAR);
 #pragma omp parallel for schedule(static) num_threads(nthreads)
@@ -288,16 +290,16 @@ static void nbnxn_kernel_cpu(const PairlistSet&         pairlistSet,
             switch (kernelSetup.kernelType)
             {
                 case Nbnxm::KernelType::Cpu4x4_PlainC:
-                    nbnxn_kernel_noener_ref[coulkt][vdwkt](pairlist, nbat, &ic, shiftVectors, out);
+                    nbnxn_kernel_noener_ref[coulkt][vdwkt](pairlist, nbat, &ic, shiftVecPointer, out);
                     break;
 #ifdef GMX_NBNXN_SIMD_2XNN
                 case Nbnxm::KernelType::Cpu4xN_Simd_2xNN:
-                    nbnxm_kernel_noener_simd_2xmm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVectors, out);
+                    nbnxm_kernel_noener_simd_2xmm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVecPointer, out);
                     break;
 #endif
 #ifdef GMX_NBNXN_SIMD_4XN
                 case Nbnxm::KernelType::Cpu4xN_Simd_4xN:
-                    nbnxm_kernel_noener_simd_4xm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVectors, out);
+                    nbnxm_kernel_noener_simd_4xm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVecPointer, out);
                     break;
 #endif
                 default: GMX_RELEASE_ASSERT(false, "Unsupported kernel architecture");
@@ -312,16 +314,16 @@ static void nbnxn_kernel_cpu(const PairlistSet&         pairlistSet,
             switch (kernelSetup.kernelType)
             {
                 case Nbnxm::KernelType::Cpu4x4_PlainC:
-                    nbnxn_kernel_ener_ref[coulkt][vdwkt](pairlist, nbat, &ic, shiftVectors, out);
+                    nbnxn_kernel_ener_ref[coulkt][vdwkt](pairlist, nbat, &ic, shiftVecPointer, out);
                     break;
 #ifdef GMX_NBNXN_SIMD_2XNN
                 case Nbnxm::KernelType::Cpu4xN_Simd_2xNN:
-                    nbnxm_kernel_ener_simd_2xmm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVectors, out);
+                    nbnxm_kernel_ener_simd_2xmm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVecPointer, out);
                     break;
 #endif
 #ifdef GMX_NBNXN_SIMD_4XN
                 case Nbnxm::KernelType::Cpu4xN_Simd_4xN:
-                    nbnxm_kernel_ener_simd_4xm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVectors, out);
+                    nbnxm_kernel_ener_simd_4xm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVecPointer, out);
                     break;
 #endif
                 default: GMX_RELEASE_ASSERT(false, "Unsupported kernel architecture");
@@ -338,18 +340,19 @@ static void nbnxn_kernel_cpu(const PairlistSet&         pairlistSet,
             {
                 case Nbnxm::KernelType::Cpu4x4_PlainC:
                     unrollj = c_nbnxnCpuIClusterSize;
-                    nbnxn_kernel_energrp_ref[coulkt][vdwkt](pairlist, nbat, &ic, shiftVectors, out);
+                    nbnxn_kernel_energrp_ref[coulkt][vdwkt](pairlist, nbat, &ic, shiftVecPointer, out);
                     break;
 #ifdef GMX_NBNXN_SIMD_2XNN
                 case Nbnxm::KernelType::Cpu4xN_Simd_2xNN:
                     unrollj = GMX_SIMD_REAL_WIDTH / 2;
-                    nbnxm_kernel_energrp_simd_2xmm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVectors, out);
+                    nbnxm_kernel_energrp_simd_2xmm[coulkt][vdwkt](
+                            pairlist, nbat, &ic, shiftVecPointer, out);
                     break;
 #endif
 #ifdef GMX_NBNXN_SIMD_4XN
                 case Nbnxm::KernelType::Cpu4xN_Simd_4xN:
                     unrollj = GMX_SIMD_REAL_WIDTH;
-                    nbnxm_kernel_energrp_simd_4xm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVectors, out);
+                    nbnxm_kernel_energrp_simd_4xm[coulkt][vdwkt](pairlist, nbat, &ic, shiftVecPointer, out);
                     break;
 #endif
                 default: GMX_RELEASE_ASSERT(false, "Unsupported kernel architecture");
index 8fa8d6797a9fdfd52d7f2395b807227e601ee223..6002eb5be7ebe912d50b28d0a90548ead7e88e03 100644 (file)
 
 static constexpr int c_clSize = c_nbnxnGpuClusterSize;
 
-void nbnxn_kernel_gpu_ref(const NbnxnPairlistGpu*    nbl,
-                          const nbnxn_atomdata_t*    nbat,
-                          const interaction_const_t* iconst,
-                          rvec*                      shift_vec,
-                          const gmx::StepWorkload&   stepWork,
-                          int                        clearF,
-                          gmx::ArrayRef<real>        f,
-                          real*                      fshift,
-                          real*                      Vc,
-                          real*                      Vvdw)
+void nbnxn_kernel_gpu_ref(const NbnxnPairlistGpu*        nbl,
+                          const nbnxn_atomdata_t*        nbat,
+                          const interaction_const_t*     iconst,
+                          gmx::ArrayRef<const gmx::RVec> shiftvec,
+                          const gmx::StepWorkload&       stepWork,
+                          int                            clearF,
+                          gmx::ArrayRef<real>            f,
+                          real*                          fshift,
+                          real*                          Vc,
+                          real*                          Vvdw)
 {
     real                fscal = NAN;
     real                vcoul = 0;
@@ -97,7 +97,6 @@ void nbnxn_kernel_gpu_ref(const NbnxnPairlistGpu*    nbl,
 
     const int*  type     = nbat->params().type.data();
     const real  facel    = iconst->epsfac;
-    const real* shiftvec = shift_vec[0];
     const real* vdwparam = nbat->params().nbfp.data();
     const int   ntype    = nbat->params().numTypes;
 
@@ -109,10 +108,11 @@ void nbnxn_kernel_gpu_ref(const NbnxnPairlistGpu*    nbl,
 
     for (const nbnxn_sci_t& nbln : nbl->sci)
     {
-        const int  ish3     = 3 * nbln.shift;
-        const real shX      = shiftvec[ish3];
-        const real shY      = shiftvec[ish3 + 1];
-        const real shZ      = shiftvec[ish3 + 2];
+        const int  ish      = nbln.shift;
+        const int  ish3     = DIM * ish;
+        const real shX      = shiftvec[ish][XX];
+        const real shY      = shiftvec[ish][YY];
+        const real shZ      = shiftvec[ish][ZZ];
         const int  cj4_ind0 = nbln.cj4_ind_start;
         const int  cj4_ind1 = nbln.cj4_ind_end;
         const int  sci      = nbln.sci;
index 57570a7efb6b5f05ec8b74b47b075a35299efebd..83c59b65f073fee429ba6202cb6cd9d5ec0a2cf7 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2015,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -60,15 +60,15 @@ class StepWorkload;
 }
 
 //! Reference (slow) kernel for nb n vs n GPU type pair lists
-void nbnxn_kernel_gpu_ref(const NbnxnPairlistGpu*    nbl,
-                          const nbnxn_atomdata_t*    nbat,
-                          const interaction_const_t* iconst,
-                          rvec*                      shift_vec,
-                          const gmx::StepWorkload&   stepWork,
-                          int                        clearF,
-                          gmx::ArrayRef<real>        f,
-                          real*                      fshift,
-                          real*                      Vc,
-                          real*                      Vvdw);
+void nbnxn_kernel_gpu_ref(const NbnxnPairlistGpu*        nbl,
+                          const nbnxn_atomdata_t*        nbat,
+                          const interaction_const_t*     iconst,
+                          gmx::ArrayRef<const gmx::RVec> shiftvec,
+                          const gmx::StepWorkload&       stepWork,
+                          int                            clearF,
+                          gmx::ArrayRef<real>            f,
+                          real*                          fshift,
+                          real*                          Vc,
+                          real*                          Vvdw);
 
 #endif
index 245529cd47bd02027afb1e1314f40f9298fc6f58..8d94eaed563a01f4f252ccdc3451fe72f359263e 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/utility/gmxassert.h"
 
 /* Prune a single NbnxnPairlistCpu entry with distance rlistInner */
-void nbnxn_kernel_prune_ref(NbnxnPairlistCpu*       nbl,
-                            const nbnxn_atomdata_t* nbat,
-                            const rvec* gmx_restrict shift_vec,
-                            real                     rlistInner)
+void nbnxn_kernel_prune_ref(NbnxnPairlistCpu*              nbl,
+                            const nbnxn_atomdata_t*        nbat,
+                            gmx::ArrayRef<const gmx::RVec> shiftvec,
+                            real                           rlistInner)
 {
     /* We avoid push_back() for efficiency reasons and resize after filling */
     nbl->ci.resize(nbl->ciOuter.size());
@@ -57,8 +58,7 @@ void nbnxn_kernel_prune_ref(NbnxnPairlistCpu*       nbl,
     const nbnxn_cj_t* gmx_restrict cjOuter = nbl->cjOuter.data();
     nbnxn_cj_t* gmx_restrict cjInner       = nbl->cj.data();
 
-    const real* gmx_restrict shiftvec = shift_vec[0];
-    const real* gmx_restrict x        = nbat->x().data();
+    const real* gmx_restrict x = nbat->x().data();
 
     const real rlist2 = rlistInner * rlistInner;
 
@@ -93,8 +93,7 @@ void nbnxn_kernel_prune_ref(NbnxnPairlistCpu*       nbl,
         {
             for (int d = 0; d < DIM; d++)
             {
-                xi[i * c_xiStride + d] =
-                        x[(ci * c_iUnroll + i) * c_xStride + d] + shiftvec[ish * DIM + d];
+                xi[i * c_xiStride + d] = x[(ci * c_iUnroll + i) * c_xStride + d] + shiftvec[ish][d];
             }
         }
 
index 1df5dc065dc40d02914648064ecffd0c7d3fd42a..d29cc4266cb0c8e567976d98786cfaca5c775efb 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 struct nbnxn_atomdata_t;
 struct NbnxnPairlistCpu;
 
+namespace gmx
+{
+template<typename>
+class ArrayRef;
+}
 /*! \brief Prune a single NbnxnPairlistCpu entry with distance \p rlistInner
  *
  * Reads a cluster pairlist \p nbl->ciOuter, \p nbl->cjOuter and writes
  * all cluster pairs within \p rlistInner to \p nbl->ci, \p nbl->cj.
  */
-void nbnxn_kernel_prune_ref(NbnxnPairlistCpu*       nbl,
-                            const nbnxn_atomdata_t* nbat,
-                            const rvec* gmx_restrict shift_vec,
-                            real                     rlistInner);
+void nbnxn_kernel_prune_ref(NbnxnPairlistCpu*              nbl,
+                            const nbnxn_atomdata_t*        nbat,
+                            gmx::ArrayRef<const gmx::RVec> shiftvec,
+                            real                           rlistInner);
index 3787909e12c21ea4ae4126700fef653ac4d2ff39..eab55185f00ca913e425502c662ecf2593dac4fb 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #endif
 
 /* Prune a single nbnxn_pairtlist_t entry with distance rlistInner */
-void nbnxn_kernel_prune_2xnn(NbnxnPairlistCpu*       nbl,
-                             const nbnxn_atomdata_t* nbat,
-                             const rvec* gmx_restrict shift_vec,
-                             real                     rlistInner)
+void nbnxn_kernel_prune_2xnn(NbnxnPairlistCpu*              nbl,
+                             const nbnxn_atomdata_t*        nbat,
+                             gmx::ArrayRef<const gmx::RVec> shiftvec,
+                             real                           rlistInner)
 {
 #ifdef GMX_NBNXN_SIMD_2XNN
     using namespace gmx;
@@ -66,8 +67,7 @@ void nbnxn_kernel_prune_2xnn(NbnxnPairlistCpu*       nbl,
     const nbnxn_cj_t* gmx_restrict cjOuter = nbl->cjOuter.data();
     nbnxn_cj_t* gmx_restrict cjInner       = nbl->cj.data();
 
-    const real* gmx_restrict shiftvec = shift_vec[0];
-    const real* gmx_restrict x        = nbat->x().data();
+    const real* gmx_restrict x = nbat->x().data();
 
     const SimdReal rlist2_S(rlistInner * rlistInner);
 
@@ -85,13 +85,12 @@ void nbnxn_kernel_prune_2xnn(NbnxnPairlistCpu*       nbl,
         ciInner[nciInner].cj_ind_start = ncjInner;
 
         /* Extract shift data */
-        int ish  = (ciEntry->shift & NBNXN_CI_SHIFT);
-        int ish3 = ish * 3;
-        int ci   = ciEntry->ci;
+        int ish = (ciEntry->shift & NBNXN_CI_SHIFT);
+        int ci  = ciEntry->ci;
 
-        SimdReal shX_S = SimdReal(shiftvec[ish3]);
-        SimdReal shY_S = SimdReal(shiftvec[ish3 + 1]);
-        SimdReal shZ_S = SimdReal(shiftvec[ish3 + 2]);
+        SimdReal shX_S = SimdReal(shiftvec[ish][XX]);
+        SimdReal shY_S = SimdReal(shiftvec[ish][YY]);
+        SimdReal shZ_S = SimdReal(shiftvec[ish][ZZ]);
 
 #    if UNROLLJ <= 4
         int scix = ci * STRIDE * DIM;
@@ -171,7 +170,7 @@ void nbnxn_kernel_prune_2xnn(NbnxnPairlistCpu*       nbl,
 
     GMX_UNUSED_VALUE(nbl);
     GMX_UNUSED_VALUE(nbat);
-    GMX_UNUSED_VALUE(shift_vec);
+    GMX_UNUSED_VALUE(shiftvec);
     GMX_UNUSED_VALUE(rlistInner);
 
 #endif /* GMX_NBNXN_SIMD_2XNN */
index ce2b8780301852a1b6bf08c7d57c40d6d294c9da..9abafd8b21dba8d1d15d8d6e0a5f6b5786b41104 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2019, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 struct nbnxn_atomdata_t;
 struct NbnxnPairlistCpu;
 
+namespace gmx
+{
+template<typename>
+class ArrayRef;
+}
+
 /*! \brief Prune a single NbnxnPairlistCpu entry with distance \p rlistInner
  *
  * Reads a cluster pairlist \p nbl->ciOuter, \p nbl->cjOuter and writes
  * all cluster pairs within \p rlistInner to \p nbl->ci, \p nbl->cj.
  */
-void nbnxn_kernel_prune_2xnn(NbnxnPairlistCpu*       nbl,
-                             const nbnxn_atomdata_t* nbat,
-                             const rvec* gmx_restrict shift_vec,
-                             real                     rlistInner);
+void nbnxn_kernel_prune_2xnn(NbnxnPairlistCpu*              nbl,
+                             const nbnxn_atomdata_t*        nbat,
+                             gmx::ArrayRef<const gmx::RVec> shift_vec,
+                             real                           rlistInner);
index d48a526f83f92043aed64f843a27e53185f021f4..cb2059a713230ad8ca8b28200fd6a5201ae7a77b 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #endif
 
 /* Prune a single nbnxn_pairtlist_t entry with distance rlistInner */
-void nbnxn_kernel_prune_4xn(NbnxnPairlistCpu*       nbl,
-                            const nbnxn_atomdata_t* nbat,
-                            const rvec* gmx_restrict shift_vec,
-                            real                     rlistInner)
+void nbnxn_kernel_prune_4xn(NbnxnPairlistCpu*              nbl,
+                            const nbnxn_atomdata_t*        nbat,
+                            gmx::ArrayRef<const gmx::RVec> shiftvec,
+                            real                           rlistInner)
 {
 #ifdef GMX_NBNXN_SIMD_4XN
     using namespace gmx;
@@ -66,8 +67,7 @@ void nbnxn_kernel_prune_4xn(NbnxnPairlistCpu*       nbl,
     const nbnxn_cj_t* gmx_restrict cjOuter = nbl->cjOuter.data();
     nbnxn_cj_t* gmx_restrict cjInner       = nbl->cj.data();
 
-    const real* gmx_restrict shiftvec = shift_vec[0];
-    const real* gmx_restrict x        = nbat->x().data();
+    const real* gmx_restrict x = nbat->x().data();
 
     const SimdReal rlist2_S(rlistInner * rlistInner);
 
@@ -85,13 +85,12 @@ void nbnxn_kernel_prune_4xn(NbnxnPairlistCpu*       nbl,
         ciInner[nciInner].cj_ind_start = ncjInner;
 
         /* Extract shift data */
-        int ish  = (ciEntry->shift & NBNXN_CI_SHIFT);
-        int ish3 = ish * 3;
-        int ci   = ciEntry->ci;
+        int ish = (ciEntry->shift & NBNXN_CI_SHIFT);
+        int ci  = ciEntry->ci;
 
-        SimdReal shX_S = SimdReal(shiftvec[ish3]);
-        SimdReal shY_S = SimdReal(shiftvec[ish3 + 1]);
-        SimdReal shZ_S = SimdReal(shiftvec[ish3 + 2]);
+        SimdReal shX_S = SimdReal(shiftvec[ish][XX]);
+        SimdReal shY_S = SimdReal(shiftvec[ish][YY]);
+        SimdReal shZ_S = SimdReal(shiftvec[ish][ZZ]);
 
 #    if UNROLLJ <= 4
         int scix = ci * STRIDE * DIM;
@@ -189,7 +188,7 @@ void nbnxn_kernel_prune_4xn(NbnxnPairlistCpu*       nbl,
 
     GMX_UNUSED_VALUE(nbl);
     GMX_UNUSED_VALUE(nbat);
-    GMX_UNUSED_VALUE(shift_vec);
+    GMX_UNUSED_VALUE(shiftvec);
     GMX_UNUSED_VALUE(rlistInner);
 
 #endif /* GMX_NBNXN_SIMD_4XN */
index ca6113dde9411e05f63bc1c69dd148098ce2f42e..025ba4a02e97a8a287738e9dfff389fac01fb718 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2019, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 struct nbnxn_atomdata_t;
 struct NbnxnPairlistCpu;
 
+namespace gmx
+{
+template<typename>
+class ArrayRef;
+}
+
 /*! \brief Prune a single NbnxnPairlistCpu entry with distance \p rlistInner
  *
  * Reads a cluster pairlist \p nbl->ciOuter, \p nbl->cjOuter and writes
  * all cluster pairs within \p rlistInner to \p nbl->ci, \p nbl->cj.
  */
-void nbnxn_kernel_prune_4xn(NbnxnPairlistCpu*       nbl,
-                            const nbnxn_atomdata_t* nbat,
-                            const rvec* gmx_restrict shift_vec,
-                            real                     rlistInner);
+void nbnxn_kernel_prune_4xn(NbnxnPairlistCpu*              nbl,
+                            const nbnxn_atomdata_t*        nbat,
+                            gmx::ArrayRef<const gmx::RVec> shiftvec,
+                            real                           rlistInner);
index bbfe22453d53b78f3986fdf4677eb4b7805fa414..b44fcaa8087b1b904f79104ebd0eaa0b38f8642f 100644 (file)
@@ -351,7 +351,8 @@ public:
     bool isDynamicPruningStepGpu(int64_t step) const;
 
     //! Dispatches the dynamic pruning kernel for the given locality, for CPU lists
-    void dispatchPruneKernelCpu(gmx::InteractionLocality iLocality, const rvec* shift_vec) const;
+    void dispatchPruneKernelCpu(gmx::InteractionLocality       iLocality,
+                                gmx::ArrayRef<const gmx::RVec> shift_vec) const;
 
     //! Dispatches the dynamic pruning kernel for GPU lists
     void dispatchPruneKernelGpu(int64_t step);
index c7f80e9f4859401e4c4a0ea5dcad06da78fc1997..c88a907f378ca5c8f7af06702aa9341ef75425fd 100644 (file)
@@ -98,7 +98,7 @@ public:
                             SearchCycleCounting*          searchCycleCounting);
 
     //! Dispatch the kernel for dynamic pairlist pruning
-    void dispatchPruneKernel(const nbnxn_atomdata_t* nbat, const rvec* shift_vec);
+    void dispatchPruneKernel(const nbnxn_atomdata_t* nbat, gmx::ArrayRef<const gmx::RVec> shift_vec);
 
     //! Returns the lists of CPU pairlists
     gmx::ArrayRef<const NbnxnPairlistCpu> cpuLists() const { return cpuLists_; }
index 0119680c72581d53faf78fc73523264b1a4b473c..8bbb92d9c4878b67ceae572a59ce272b0d4a4940 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 2012,2013,2014,2015,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -84,9 +84,9 @@ public:
                    t_nrnb*                      nrnb);
 
     //! Dispatches the dynamic pruning kernel for the given locality
-    void dispatchPruneKernel(gmx::InteractionLocality iLocality,
-                             const nbnxn_atomdata_t*  nbat,
-                             const rvec*              shift_vec);
+    void dispatchPruneKernel(gmx::InteractionLocality       iLocality,
+                             const nbnxn_atomdata_t*        nbat,
+                             gmx::ArrayRef<const gmx::RVec> shift_vec);
 
     //! Returns the pair list parameters
     const PairlistParams& params() const { return params_; }
index 4a09d6d94d4ac0e9452c3ad23859d31b21b159c8..f3e4dee503f8e732ac046feab005adf5fce5027f 100644 (file)
 
 void PairlistSets::dispatchPruneKernel(const gmx::InteractionLocality iLocality,
                                        const nbnxn_atomdata_t*        nbat,
-                                       const rvec*                    shift_vec)
+                                       gmx::ArrayRef<const gmx::RVec> shift_vec)
 {
     pairlistSet(iLocality).dispatchPruneKernel(nbat, shift_vec);
 }
 
-void PairlistSet::dispatchPruneKernel(const nbnxn_atomdata_t* nbat, const rvec* shift_vec)
+void PairlistSet::dispatchPruneKernel(const nbnxn_atomdata_t* nbat, gmx::ArrayRef<const gmx::RVec> shift_vec)
 {
     const real rlistInner = params_.rlistInner;
 
@@ -93,7 +93,7 @@ void PairlistSet::dispatchPruneKernel(const nbnxn_atomdata_t* nbat, const rvec*
 }
 
 void nonbonded_verlet_t::dispatchPruneKernelCpu(const gmx::InteractionLocality iLocality,
-                                                const rvec*                    shift_vec) const
+                                                gmx::ArrayRef<const gmx::RVec> shift_vec) const
 {
     pairlistSets_->dispatchPruneKernel(iLocality, nbat.get(), shift_vec);
 }
index 3e6fbb662330101a9d3797c968fb841eebf51e91..900663ad0cd65f7944c3b617444067839cd21b63 100644 (file)
@@ -1196,7 +1196,7 @@ void pbc_dx_d(const t_pbc* pbc, const dvec x1, const dvec x2, dvec dx)
     }
 }
 
-void calc_shifts(const matrix box, rvec shift_vec[])
+void calc_shifts(const matrix box, gmx::ArrayRef<gmx::RVec> shift_vec)
 {
     for (int n = 0, m = -D_BOX_Z; m <= D_BOX_Z; m++)
     {
index 17ccfbcf5a65d4eaf89deefd1cd79a3f70e1cfd4..fce60b814fc62be5e95d82119a215369b25f73ee 100644 (file)
@@ -283,7 +283,7 @@ void pbc_dx_d(const t_pbc* pbc, const dvec x1, const dvec x2, dvec dx);
  * \param[in]  box       The simulation box
  * \param[out] shift_vec The shifting vectors
  */
-void calc_shifts(const matrix box, rvec shift_vec[]);
+void calc_shifts(const matrix box, gmx::ArrayRef<gmx::RVec> shift_vec);
 
 /*! \brief Calculates the center of the box.
  *
index 47e3cf5bbc86b64f8f6ec27e9b1bc980c7245bd3..6ad87561fa4cf47403af571034bc9b51d7255f04 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -47,6 +47,7 @@
 
 #include "gromacs/math/vectypes.h"
 #include "gromacs/pbcutil/ishift.h"
+#include "gromacs/utility/arrayref.h"
 
 #include "testutils/refdata.h"
 
@@ -61,8 +62,8 @@ TEST(PbcTest, CalcShiftsWorks)
     // Choose box vector entries whose magnitudes will lead to unique
     // shift vector values when the largest box shift in any dimension
     // is two.
-    const matrix box = { { 0.01, 1, -100 }, { 300, -0.03, 3 }, { -6, -600, 0.06 } };
-    rvec         shiftVectors[SHIFTS];
+    const matrix           box = { { 0.01, 1, -100 }, { 300, -0.03, 3 }, { -6, -600, 0.06 } };
+    std::vector<gmx::RVec> shiftVectors(SHIFTS);
 
     calc_shifts(box, shiftVectors);