Fix clang-tidy-11 errors in NBNXM module, part 1
authorAndrey Alekseenko <al42and@gmail.com>
Wed, 10 Feb 2021 07:42:07 +0000 (07:42 +0000)
committerMark Abraham <mark.j.abraham@gmail.com>
Wed, 10 Feb 2021 07:42:07 +0000 (07:42 +0000)
In some cases, extracted problematic pieces into static functions to
simplify the logic.

13 files changed:
src/gromacs/nbnxm/atomdata.h
src/gromacs/nbnxm/gridset.cpp
src/gromacs/nbnxm/kernel_common.cpp
src/gromacs/nbnxm/kerneldispatch.cpp
src/gromacs/nbnxm/nbnxm.cpp
src/gromacs/nbnxm/nbnxm.h
src/gromacs/nbnxm/nbnxm_geometry.h
src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp
src/gromacs/nbnxm/nbnxm_setup.cpp
src/gromacs/nbnxm/pairlist.cpp
src/gromacs/nbnxm/pairlistwork.h
src/gromacs/nbnxm/pairsearch.h
src/gromacs/nbnxm/prunekerneldispatch.cpp

index 9839381ac734060d937d9101fb13dbc4802ec02d..30bcec06a810a17ef5e9dad81ba38a3d5e61cc4b 100644 (file)
@@ -232,7 +232,7 @@ struct nbnxn_atomdata_t
 
     /*! \brief Constructor
      *
-     * \param[in] pinningPolicy  Sets the pinning policy for all data that might be transfered to a GPU
+     * \param[in] pinningPolicy  Sets the pinning policy for all data that might be transferred to a GPU
      */
     nbnxn_atomdata_t(gmx::PinningPolicy pinningPolicy);
 
index 95078bcc6247e9720b19c97eac63ea806096fb7a..6b6b84ef97f26b3ed28512635b1d143c22538732 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -57,14 +57,15 @@ namespace Nbnxm
 //! Returns the number of search grids
 static int numGrids(const GridSet::DomainSetup& domainSetup)
 {
-    int numGrids;
+    // One grid for the test particle, one for the rest
+    static constexpr int sc_numGridsForTestParticleInsertion = 2;
     if (domainSetup.doTestParticleInsertion)
     {
-        numGrids = 2;
+        return sc_numGridsForTestParticleInsertion;
     }
     else
     {
-        numGrids = 1;
+        int numGrids = 1;
         for (auto haveDD : domainSetup.haveMultipleDomainsPerDim)
         {
             if (haveDD)
@@ -72,9 +73,8 @@ static int numGrids(const GridSet::DomainSetup& domainSetup)
                 numGrids *= 2;
             }
         }
+        return numGrids;
     }
-
-    return numGrids;
 }
 
 GridSet::DomainSetup::DomainSetup(const PbcType             pbcType,
@@ -132,6 +132,19 @@ void GridSet::setLocalAtomOrder()
     }
 }
 
+static int getGridOffset(gmx::ArrayRef<const Grid> grids, int gridIndex)
+{
+    if (gridIndex == 0)
+    {
+        return 0;
+    }
+    else
+    {
+        const Nbnxm::Grid& previousGrid = grids[gridIndex - 1];
+        return previousGrid.atomIndexEnd() / previousGrid.geometry().numAtomsPerCell;
+    }
+}
+
 void GridSet::putOnGrid(const matrix                   box,
                         const int                      gridIndex,
                         const rvec                     lowerCorner,
@@ -145,22 +158,11 @@ void GridSet::putOnGrid(const matrix                   box,
                         const int*                     move,
                         nbnxn_atomdata_t*              nbat)
 {
-    Nbnxm::Grid& grid = grids_[gridIndex];
-
-    int cellOffset;
-    if (gridIndex == 0)
-    {
-        cellOffset = 0;
-    }
-    else
-    {
-        const Nbnxm::Grid& previousGrid = grids_[gridIndex - 1];
-        cellOffset = previousGrid.atomIndexEnd() / previousGrid.geometry().numAtomsPerCell;
-    }
-
-    const int n = atomRange.size();
+    Nbnxm::Grid& grid               = grids_[gridIndex];
+    const int    cellOffset         = getGridOffset(grids_, gridIndex);
+    const int    n                  = atomRange.size();
+    real         maxAtomGroupRadius = NAN;
 
-    real maxAtomGroupRadius;
     if (gridIndex == 0)
     {
         copy_mat(box, box_);
index ac176fa6cd4407fa0b98f613bed0daf0a4f4d0a5..b28b9a0168394a8e0e0469c05693567dec682f1a 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) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -68,7 +68,7 @@ template<int numComponentsPerElement>
 static void clearBufferFlagged(const nbnxn_atomdata_t& nbat, int outputIndex, gmx::ArrayRef<real> buffer)
 {
     gmx::ArrayRef<const gmx_bitmask_t> flags = nbat.buffer_flags;
-    gmx_bitmask_t                      our_flag;
+    gmx_bitmask_t                      our_flag; // NOLINT(cppcoreguidelines-init-variables)
     bitmask_init_bit(&our_flag, outputIndex);
 
     constexpr size_t numComponentsPerBlock = NBNXN_BUFFERFLAG_SIZE * numComponentsPerElement;
@@ -98,9 +98,7 @@ void clearForceBuffer(nbnxn_atomdata_t* nbat, int outputIndex)
 
 void clear_fshift(real* fshift)
 {
-    int i;
-
-    for (i = 0; i < SHIFTS * DIM; i++)
+    for (int i = 0; i < SHIFTS * DIM; i++)
     {
         fshift[i] = 0;
     }
index c840addd4cacbec79a37ef2aa84eb5eb7699474e..1952bf3d0c249a4cb1468d9eb426d0512d99ba2d 100644 (file)
@@ -56,6 +56,7 @@
 #include "gromacs/nbnxm/nbnxm.h"
 #include "gromacs/simd/simd.h"
 #include "gromacs/timing/wallcycle.h"
+#include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/real.h"
 
@@ -134,39 +135,12 @@ static void reduceGroupEnergySimdBuffers(int numGroups, int numGroups_2log, nbnx
     }
 }
 
-/*! \brief Dispatches the non-bonded N versus M atom cluster CPU kernels.
- *
- * OpenMP parallelization is performed within this function.
- * Energy reduction, but not force and shift force reduction, is performed
- * within this function.
- *
- * \param[in]     pairlistSet   Pairlists with local or non-local interactions to compute
- * \param[in]     kernelSetup   The non-bonded kernel setup
- * \param[in,out] nbat          The atomdata for the interactions
- * \param[in]     ic            Non-bonded interaction constants
- * \param[in]     shiftVectors  The PBC shift vectors
- * \param[in]     stepWork      Flags that tell what to compute
- * \param[in]     clearF        Enum that tells if to clear the force output buffer
- * \param[out]    vCoulomb      Output buffer for Coulomb energies
- * \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 int getCoulombKernelType(const Nbnxm::KernelSetup& kernelSetup, const interaction_const_t& ic)
 {
 
-    int coulkt;
     if (EEL_RF(ic.eeltype) || ic.eeltype == eelCUT)
     {
-        coulkt = coulktRF;
+        return coulktRF;
     }
     else
     {
@@ -174,29 +148,31 @@ static void nbnxn_kernel_cpu(const PairlistSet&         pairlistSet,
         {
             if (ic.rcoulomb == ic.rvdw)
             {
-                coulkt = coulktTAB;
+                return coulktTAB;
             }
             else
             {
-                coulkt = coulktTAB_TWIN;
+                return coulktTAB_TWIN;
             }
         }
         else
         {
             if (ic.rcoulomb == ic.rvdw)
             {
-                coulkt = coulktEWALD;
+                return coulktEWALD;
             }
             else
             {
-                coulkt = coulktEWALD_TWIN;
+                return coulktEWALD_TWIN;
             }
         }
     }
+}
 
-    const nbnxn_atomdata_t::Params& nbatParams = nbat->params();
-
-    int vdwkt = 0;
+static int getVdwKernelType(const Nbnxm::KernelSetup&       kernelSetup,
+                            const nbnxn_atomdata_t::Params& nbatParams,
+                            const interaction_const_t&      ic)
+{
     if (ic.vdwtype == evdwCUT)
     {
         switch (ic.vdw_modifier)
@@ -205,36 +181,77 @@ static void nbnxn_kernel_cpu(const PairlistSet&         pairlistSet,
             case eintmodPOTSHIFT:
                 switch (nbatParams.ljCombinationRule)
                 {
-                    case LJCombinationRule::Geometric: vdwkt = vdwktLJCUT_COMBGEOM; break;
-                    case LJCombinationRule::LorentzBerthelot: vdwkt = vdwktLJCUT_COMBLB; break;
-                    case LJCombinationRule::None: vdwkt = vdwktLJCUT_COMBNONE; break;
-                    default: GMX_RELEASE_ASSERT(false, "Unknown combination rule");
+                    case LJCombinationRule::Geometric: return vdwktLJCUT_COMBGEOM;
+                    case LJCombinationRule::LorentzBerthelot: return vdwktLJCUT_COMBLB;
+                    case LJCombinationRule::None: return vdwktLJCUT_COMBNONE;
+                    default: gmx_incons("Unknown combination rule");
                 }
-                break;
-            case eintmodFORCESWITCH: vdwkt = vdwktLJFORCESWITCH; break;
-            case eintmodPOTSWITCH: vdwkt = vdwktLJPOTSWITCH; break;
-            default: GMX_RELEASE_ASSERT(false, "Unsupported VdW interaction modifier");
+            case eintmodFORCESWITCH: return vdwktLJFORCESWITCH;
+            case eintmodPOTSWITCH: return vdwktLJPOTSWITCH;
+            default:
+                std::string errorMsg =
+                        gmx::formatString("Unsupported VdW interaction modifier %s (%d)",
+                                          INTMODIFIER(ic.vdw_modifier),
+                                          ic.vdw_modifier);
+                gmx_incons(errorMsg);
         }
     }
     else if (ic.vdwtype == evdwPME)
     {
         if (ic.ljpme_comb_rule == eljpmeGEOM)
         {
-            vdwkt = vdwktLJEWALDCOMBGEOM;
+            return vdwktLJEWALDCOMBGEOM;
         }
         else
         {
-            vdwkt = vdwktLJEWALDCOMBLB;
             /* At setup we (should have) selected the C reference kernel */
             GMX_RELEASE_ASSERT(kernelSetup.kernelType == Nbnxm::KernelType::Cpu4x4_PlainC,
                                "Only the C reference nbnxn SIMD kernel supports LJ-PME with LB "
                                "combination rules");
+            return vdwktLJEWALDCOMBLB;
         }
     }
     else
     {
-        GMX_RELEASE_ASSERT(false, "Unsupported VdW interaction type");
+        std::string errorMsg = gmx::formatString(
+                "Unsupported VdW interaction type %s (%d)", EVDWTYPE(ic.vdwtype), ic.vdwtype);
+        gmx_incons(errorMsg);
     }
+}
+
+/*! \brief Dispatches the non-bonded N versus M atom cluster CPU kernels.
+ *
+ * OpenMP parallelization is performed within this function.
+ * Energy reduction, but not force and shift force reduction, is performed
+ * within this function.
+ *
+ * \param[in]     pairlistSet   Pairlists with local or non-local interactions to compute
+ * \param[in]     kernelSetup   The non-bonded kernel setup
+ * \param[in,out] nbat          The atomdata for the interactions
+ * \param[in]     ic            Non-bonded interaction constants
+ * \param[in]     shiftVectors  The PBC shift vectors
+ * \param[in]     stepWork      Flags that tell what to compute
+ * \param[in]     clearF        Enum that tells if to clear the force output buffer
+ * \param[out]    vCoulomb      Output buffer for Coulomb energies
+ * \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)
+{
+
+    const nbnxn_atomdata_t::Params& nbatParams = nbat->params();
+
+    const int coulkt = getCoulombKernelType(kernelSetup, ic);
+    const int vdwkt  = getVdwKernelType(kernelSetup, nbatParams, ic);
 
     gmx::ArrayRef<const NbnxnPairlistCpu> pairlists = pairlistSet.cpuLists();
 
@@ -370,7 +387,7 @@ static void accountFlops(t_nrnb*                    nrnb,
 {
     const bool usingGpuKernels = nbv.useGpu();
 
-    int enr_nbnxn_kernel_ljc;
+    int enr_nbnxn_kernel_ljc = eNRNB;
     if (EEL_RF(ic.eeltype) || ic.eeltype == eelCUT)
     {
         enr_nbnxn_kernel_ljc = eNR_NBNXN_LJ_RF;
index 33d50502c7dab9279f5b8f6987f0956c2985072a..97827a636781777822689264de2a92e6fa71c419 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -132,14 +132,14 @@ gmx::ArrayRef<const int> nonbonded_verlet_t::getLocalAtomOrder() const
     return gmx::constArrayRefFromArray(pairSearch_->gridSet().atomIndices().data(), numIndices);
 }
 
-void nonbonded_verlet_t::setLocalAtomOrder()
+void nonbonded_verlet_t::setLocalAtomOrder() const
 {
     pairSearch_->setLocalAtomOrder();
 }
 
 void nonbonded_verlet_t::setAtomProperties(gmx::ArrayRef<const int>  atomTypes,
                                            gmx::ArrayRef<const real> atomCharges,
-                                           gmx::ArrayRef<const int>  atomInfo)
+                                           gmx::ArrayRef<const int>  atomInfo) const
 {
     nbnxn_atomdata_set(nbat.get(), pairSearch_->gridSet(), atomTypes, atomCharges, atomInfo);
 }
@@ -197,7 +197,7 @@ void nonbonded_verlet_t::atomdata_add_nbat_f_to_f(const gmx::AtomLocality  local
     wallcycle_stop(wcycle_, ewcNB_XF_BUF_OPS);
 }
 
-int nonbonded_verlet_t::getNumAtoms(const gmx::AtomLocality locality)
+int nonbonded_verlet_t::getNumAtoms(const gmx::AtomLocality locality) const
 {
     int numAtoms = 0;
     switch (locality)
@@ -215,7 +215,7 @@ int nonbonded_verlet_t::getNumAtoms(const gmx::AtomLocality locality)
     return numAtoms;
 }
 
-void* nonbonded_verlet_t::getGpuForces()
+void* nonbonded_verlet_t::getGpuForces() const
 {
     return Nbnxm::getGpuForces(gpu_nbv);
 }
@@ -230,13 +230,13 @@ real nonbonded_verlet_t::pairlistOuterRadius() const
     return pairlistSets_->params().rlistOuter;
 }
 
-void nonbonded_verlet_t::changePairlistRadii(real rlistOuter, real rlistInner)
+void nonbonded_verlet_t::changePairlistRadii(real rlistOuter, real rlistInner) const
 {
     pairlistSets_->changePairlistRadii(rlistOuter, rlistInner);
 }
 
 void nonbonded_verlet_t::setupGpuShortRangeWork(const gmx::GpuBonded*          gpuBonded,
-                                                const gmx::InteractionLocality iLocality)
+                                                const gmx::InteractionLocality iLocality) const
 {
     if (useGpu() && !emulateGpu())
     {
@@ -244,12 +244,12 @@ void nonbonded_verlet_t::setupGpuShortRangeWork(const gmx::GpuBonded*          g
     }
 }
 
-void nonbonded_verlet_t::atomdata_init_copy_x_to_nbat_x_gpu()
+void nonbonded_verlet_t::atomdata_init_copy_x_to_nbat_x_gpu() const
 {
     Nbnxm::nbnxn_gpu_init_x_to_nbat_x(pairSearch_->gridSet(), gpu_nbv);
 }
 
-void nonbonded_verlet_t::insertNonlocalGpuDependency(const gmx::InteractionLocality interactionLocality)
+void nonbonded_verlet_t::insertNonlocalGpuDependency(const gmx::InteractionLocality interactionLocality) const
 {
     Nbnxm::nbnxnInsertNonlocalGpuDependency(gpu_nbv, interactionLocality);
 }
index 9a212ce929dab162502e20ca77b3cf931a4693be..b7c3101799d1e555ef80900b0d50131e2c1f157e 100644 (file)
@@ -291,7 +291,7 @@ public:
     gmx::ArrayRef<const int> getLocalAtomOrder() const;
 
     //! Sets the order of the local atoms to the order grid atom ordering
-    void setLocalAtomOrder();
+    void setLocalAtomOrder() const;
 
     //! Returns the index position of the atoms on the search grid
     gmx::ArrayRef<const int> getGridIndices() const;
@@ -311,12 +311,12 @@ public:
     void constructPairlist(gmx::InteractionLocality     iLocality,
                            const gmx::ListOfLists<int>& exclusions,
                            int64_t                      step,
-                           t_nrnb*                      nrnb);
+                           t_nrnb*                      nrnb) const;
 
     //! Updates all the atom properties in Nbnxm
     void setAtomProperties(gmx::ArrayRef<const int>  atomTypes,
                            gmx::ArrayRef<const real> atomCharges,
-                           gmx::ArrayRef<const int>  atomInfo);
+                           gmx::ArrayRef<const int>  atomInfo) const;
 
     /*!\brief Convert the coordinates to NBNXM format for the given locality.
      *
@@ -343,10 +343,10 @@ public:
                                GpuEventSynchronizer*   xReadyOnDevice);
 
     //! Init for GPU version of setup coordinates in Nbnxm
-    void atomdata_init_copy_x_to_nbat_x_gpu();
+    void atomdata_init_copy_x_to_nbat_x_gpu() const;
 
     //! Sync the nonlocal GPU stream with dependent tasks in the local queue.
-    void insertNonlocalGpuDependency(gmx::InteractionLocality interactionLocality);
+    void insertNonlocalGpuDependency(gmx::InteractionLocality interactionLocality) const;
 
     //! Returns a reference to the pairlist sets
     const PairlistSets& pairlistSets() const { return *pairlistSets_; }
@@ -358,7 +358,7 @@ 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);
+    void dispatchPruneKernelCpu(gmx::InteractionLocality iLocality, const rvec* shift_vec) const;
 
     //! Dispatches the dynamic pruning kernel for GPU lists
     void dispatchPruneKernelGpu(int64_t step);
@@ -395,13 +395,13 @@ public:
      * \param [in] locality   Local or non-local
      * \returns               The number of atoms for given locality
      */
-    int getNumAtoms(gmx::AtomLocality locality);
+    int getNumAtoms(gmx::AtomLocality locality) const;
 
     /*! \brief Get the pointer to the GPU nonbonded force buffer
      *
      * \returns A pointer to the force buffer in GPU memory
      */
-    void* getGpuForces();
+    void* getGpuForces() const;
 
     //! Return the kernel setup
     const Nbnxm::KernelSetup& kernelSetup() const { return kernelSetup_; }
@@ -413,13 +413,12 @@ public:
     real pairlistOuterRadius() const;
 
     //! Changes the pair-list outer and inner radius
-    void changePairlistRadii(real rlistOuter, real rlistInner);
+    void changePairlistRadii(real rlistOuter, real rlistInner) const;
 
     //! Set up internal flags that indicate what type of short-range work there is.
-    void setupGpuShortRangeWork(const gmx::GpuBonded* gpuBonded, gmx::InteractionLocality iLocality);
+    void setupGpuShortRangeWork(const gmx::GpuBonded* gpuBonded, gmx::InteractionLocality iLocality) const;
 
     // TODO: Make all data members private
-public:
     //! All data related to the pair lists
     std::unique_ptr<PairlistSets> pairlistSets_;
     //! Working data for constructing the pairlists
index 033590999686cb626f9b8dde480b891acc005199..66238857881427db03fd644c3149591c4a0aef43 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+ * 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.
@@ -58,9 +58,8 @@
  */
 static inline int get_2log(int n)
 {
-    int log2;
-
-    log2 = 0;
+    // TODO: Replace with gmx::Log2I?
+    int log2 = 0;
     while ((1 << log2) < n)
     {
         log2++;
index 87ec7b5b2112889a6c4d12c7de8a24e3fd56117c..2a2a394cae417fba976f71d7637425057d8dee48 100644 (file)
@@ -205,16 +205,14 @@ void init_plist(gpu_plist* pl)
 
 void init_timings(gmx_wallclock_gpu_nbnxn_t* t)
 {
-    int i, j;
-
     t->nb_h2d_t = 0.0;
     t->nb_d2h_t = 0.0;
     t->nb_c     = 0;
     t->pl_h2d_t = 0.0;
     t->pl_h2d_c = 0;
-    for (i = 0; i < 2; i++)
+    for (int i = 0; i < 2; i++)
     {
-        for (j = 0; j < 2; j++)
+        for (int j = 0; j < 2; j++)
         {
             t->ktime[i][j].t = 0.0;
             t->ktime[i][j].c = 0;
index 03eab394b68e5752dae9b6c78db703d288e7eafd..89a4187719bb5d6e94236d409ae3c581f062cc0d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -212,25 +212,22 @@ static KernelSetup pick_nbnxn_kernel_cpu(const t_inputrec gmx_unused* ir,
 
 const char* lookup_kernel_name(const KernelType kernelType)
 {
-    const char* returnvalue = nullptr;
     switch (kernelType)
     {
-        case KernelType::NotSet: returnvalue = "not set"; break;
-        case KernelType::Cpu4x4_PlainC: returnvalue = "plain C"; break;
+        case KernelType::NotSet: return "not set";
+        case KernelType::Cpu4x4_PlainC: return "plain C";
         case KernelType::Cpu4xN_Simd_4xN:
         case KernelType::Cpu4xN_Simd_2xNN:
 #if GMX_SIMD
-            returnvalue = "SIMD";
+            return "SIMD";
 #else  // GMX_SIMD
-            returnvalue = "not available";
+            return "not available";
 #endif // GMX_SIMD
-            break;
-        case KernelType::Gpu8x8x8: returnvalue = "GPU"; break;
-        case KernelType::Cpu8x8x8_PlainC: returnvalue = "plain C"; break;
+        case KernelType::Gpu8x8x8: return "GPU";
+        case KernelType::Cpu8x8x8_PlainC: return "plain C";
 
         default: gmx_fatal(FARGS, "Illegal kernel type selected");
     }
-    return returnvalue;
 };
 
 /*! \brief Returns the most suitable kernel type and Ewald handling */
@@ -314,13 +311,11 @@ namespace Nbnxm
 /*! \brief Gets and returns the minimum i-list count for balacing based on the GPU used or env.var. when set */
 static int getMinimumIlistCountForGpuBalancing(NbnxmGpu* nbnxmGpu)
 {
-    int minimumIlistCount;
-
     if (const char* env = getenv("GMX_NB_MIN_CI"))
     {
-        char* end;
+        char* end = nullptr;
 
-        minimumIlistCount = strtol(env, &end, 10);
+        int minimumIlistCount = strtol(env, &end, 10);
         if (!end || (*end != 0) || minimumIlistCount < 0)
         {
             gmx_fatal(
@@ -331,10 +326,11 @@ static int getMinimumIlistCountForGpuBalancing(NbnxmGpu* nbnxmGpu)
         {
             fprintf(debug, "Neighbor-list balancing parameter: %d (passed as env. var.)\n", minimumIlistCount);
         }
+        return minimumIlistCount;
     }
     else
     {
-        minimumIlistCount = gpu_min_ci_balanced(nbnxmGpu);
+        int minimumIlistCount = gpu_min_ci_balanced(nbnxmGpu);
         if (debug)
         {
             fprintf(debug,
@@ -342,9 +338,36 @@ static int getMinimumIlistCountForGpuBalancing(NbnxmGpu* nbnxmGpu)
                     "multi-processors)\n",
                     minimumIlistCount);
         }
+        return minimumIlistCount;
     }
+}
 
-    return minimumIlistCount;
+static int getENbnxnInitCombRule(const t_forcerec* fr)
+{
+    if (fr->ic->vdwtype == evdwCUT
+        && (fr->ic->vdw_modifier == eintmodNONE || fr->ic->vdw_modifier == eintmodPOTSHIFT)
+        && getenv("GMX_NO_LJ_COMB_RULE") == nullptr)
+    {
+        /* Plain LJ cut-off: we can optimize with combination rules */
+        return enbnxninitcombruleDETECT;
+    }
+    else if (fr->ic->vdwtype == evdwPME)
+    {
+        /* LJ-PME: we need to use a combination rule for the grid */
+        if (fr->ljpme_combination_rule == eljpmeGEOM)
+        {
+            return enbnxninitcombruleGEOM;
+        }
+        else
+        {
+            return enbnxninitcombruleLB;
+        }
+    }
+    else
+    {
+        /* We use a full combination matrix: no rule required */
+        return enbnxninitcombruleNONE;
+    }
 }
 
 std::unique_ptr<nonbonded_verlet_t> init_nb_verlet(const gmx::MDLogger& mdlog,
@@ -387,31 +410,7 @@ std::unique_ptr<nonbonded_verlet_t> init_nb_verlet(const gmx::MDLogger& mdlog,
 
     setupDynamicPairlistPruning(mdlog, ir, mtop, box, fr->ic, &pairlistParams);
 
-    int enbnxninitcombrule;
-    if (fr->ic->vdwtype == evdwCUT
-        && (fr->ic->vdw_modifier == eintmodNONE || fr->ic->vdw_modifier == eintmodPOTSHIFT)
-        && getenv("GMX_NO_LJ_COMB_RULE") == nullptr)
-    {
-        /* Plain LJ cut-off: we can optimize with combination rules */
-        enbnxninitcombrule = enbnxninitcombruleDETECT;
-    }
-    else if (fr->ic->vdwtype == evdwPME)
-    {
-        /* LJ-PME: we need to use a combination rule for the grid */
-        if (fr->ljpme_combination_rule == eljpmeGEOM)
-        {
-            enbnxninitcombrule = enbnxninitcombruleGEOM;
-        }
-        else
-        {
-            enbnxninitcombrule = enbnxninitcombruleLB;
-        }
-    }
-    else
-    {
-        /* We use a full combination matrix: no rule required */
-        enbnxninitcombrule = enbnxninitcombruleNONE;
-    }
+    const int enbnxninitcombrule = getENbnxnInitCombRule(fr);
 
     auto pinPolicy = (useGpuForNonbonded ? gmx::PinningPolicy::PinnedIfSupported
                                          : gmx::PinningPolicy::CannotBePinned);
index a53233c2e1e8b84d89befe69d6da5ce2b9e4334b..7c963691f642964f7385ccc0d49f6f2bc52d8f7d 100644 (file)
@@ -4340,7 +4340,7 @@ void PairlistSets::construct(const InteractionLocality iLocality,
 void nonbonded_verlet_t::constructPairlist(const InteractionLocality iLocality,
                                            const ListOfLists<int>&   exclusions,
                                            int64_t                   step,
-                                           t_nrnb*                   nrnb)
+                                           t_nrnb*                   nrnb) const
 {
     pairlistSets_->construct(iLocality, pairSearch_.get(), nbat.get(), exclusions, step, nrnb);
 
index 3fce22eab74e0aa0eb30dbc65c8f39056f42f804..b30f37a50b320b6ba533fcd13102654d92f72f4e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -57,7 +57,7 @@
 //! Working data for the actual i-supercell during pair search \internal
 struct NbnxnPairlistCpuWork
 {
-    //! Struct for storing coordinats and bounding box for an i-entry during search \internal
+    //! Struct for storing coordinates and bounding box for an i-entry during search \internal
     struct IClusterData
     {
         IClusterData() :
index c4c92969a1c2fd3a79d88a42e865c906d251b754..70ae875162b6bc65cdf26b553210ab072ab2773c 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+ * 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.
@@ -40,7 +40,7 @@
  *
  * The PairSearch class holds the domain setup, the search grids
  * and helper object for the pair search. It manages the search work.
- * The actual gridding and pairlist generation is performeed by the
+ * The actual gridding and pairlist generation is performed by the
  * GridSet/Grid and PairlistSet/Pairlist classes, respectively.
  *
  * \author Berk Hess <hess@kth.se>
@@ -151,7 +151,7 @@ struct PairsearchWork
 
     ~PairsearchWork();
 
-    //! Buffer to avoid cache polution
+    //! Buffer to avoid cache pollution
     gmx_cache_protect_t cp0;
 
     //! Temporary buffer for sorting atoms within a grid column
index 9b98e5f92ff62b4f68999b818213df4b5e0ee898..4a09d6d94d4ac0e9452c3ad23859d31b21b159c8 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019,2020 by the GROMACS development team.
+ * Copyright (c) 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.
@@ -91,7 +92,8 @@ void PairlistSet::dispatchPruneKernel(const nbnxn_atomdata_t* nbat, const rvec*
     }
 }
 
-void nonbonded_verlet_t::dispatchPruneKernelCpu(const gmx::InteractionLocality iLocality, const rvec* shift_vec)
+void nonbonded_verlet_t::dispatchPruneKernelCpu(const gmx::InteractionLocality iLocality,
+                                                const rvec*                    shift_vec) const
 {
     pairlistSets_->dispatchPruneKernel(iLocality, nbat.get(), shift_vec);
 }