From: Andrey Alekseenko Date: Wed, 10 Feb 2021 07:42:07 +0000 (+0000) Subject: Fix clang-tidy-11 errors in NBNXM module, part 1 X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=1d6a151649900aaa9e75d90dc6ab4922bb8fef76;p=alexxy%2Fgromacs.git Fix clang-tidy-11 errors in NBNXM module, part 1 In some cases, extracted problematic pieces into static functions to simplify the logic. --- diff --git a/src/gromacs/nbnxm/atomdata.h b/src/gromacs/nbnxm/atomdata.h index 9839381ac7..30bcec06a8 100644 --- a/src/gromacs/nbnxm/atomdata.h +++ b/src/gromacs/nbnxm/atomdata.h @@ -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); diff --git a/src/gromacs/nbnxm/gridset.cpp b/src/gromacs/nbnxm/gridset.cpp index 95078bcc62..6b6b84ef97 100644 --- a/src/gromacs/nbnxm/gridset.cpp +++ b/src/gromacs/nbnxm/gridset.cpp @@ -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 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_); diff --git a/src/gromacs/nbnxm/kernel_common.cpp b/src/gromacs/nbnxm/kernel_common.cpp index ac176fa6cd..b28b9a0168 100644 --- a/src/gromacs/nbnxm/kernel_common.cpp +++ b/src/gromacs/nbnxm/kernel_common.cpp @@ -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 static void clearBufferFlagged(const nbnxn_atomdata_t& nbat, int outputIndex, gmx::ArrayRef buffer) { gmx::ArrayRef 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; } diff --git a/src/gromacs/nbnxm/kerneldispatch.cpp b/src/gromacs/nbnxm/kerneldispatch.cpp index c840addd4c..1952bf3d0c 100644 --- a/src/gromacs/nbnxm/kerneldispatch.cpp +++ b/src/gromacs/nbnxm/kerneldispatch.cpp @@ -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 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; diff --git a/src/gromacs/nbnxm/nbnxm.cpp b/src/gromacs/nbnxm/nbnxm.cpp index 33d50502c7..97827a6367 100644 --- a/src/gromacs/nbnxm/nbnxm.cpp +++ b/src/gromacs/nbnxm/nbnxm.cpp @@ -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 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 atomTypes, gmx::ArrayRef atomCharges, - gmx::ArrayRef atomInfo) + gmx::ArrayRef 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); } diff --git a/src/gromacs/nbnxm/nbnxm.h b/src/gromacs/nbnxm/nbnxm.h index 9a212ce929..b7c3101799 100644 --- a/src/gromacs/nbnxm/nbnxm.h +++ b/src/gromacs/nbnxm/nbnxm.h @@ -291,7 +291,7 @@ public: gmx::ArrayRef 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 getGridIndices() const; @@ -311,12 +311,12 @@ public: void constructPairlist(gmx::InteractionLocality iLocality, const gmx::ListOfLists& exclusions, int64_t step, - t_nrnb* nrnb); + t_nrnb* nrnb) const; //! Updates all the atom properties in Nbnxm void setAtomProperties(gmx::ArrayRef atomTypes, gmx::ArrayRef atomCharges, - gmx::ArrayRef atomInfo); + gmx::ArrayRef 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_; //! Working data for constructing the pairlists diff --git a/src/gromacs/nbnxm/nbnxm_geometry.h b/src/gromacs/nbnxm/nbnxm_geometry.h index 0335909996..6623885788 100644 --- a/src/gromacs/nbnxm/nbnxm_geometry.h +++ b/src/gromacs/nbnxm/nbnxm_geometry.h @@ -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++; diff --git a/src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp b/src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp index 87ec7b5b21..2a2a394cae 100644 --- a/src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp +++ b/src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp @@ -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; diff --git a/src/gromacs/nbnxm/nbnxm_setup.cpp b/src/gromacs/nbnxm/nbnxm_setup.cpp index 03eab394b6..89a4187719 100644 --- a/src/gromacs/nbnxm/nbnxm_setup.cpp +++ b/src/gromacs/nbnxm/nbnxm_setup.cpp @@ -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 init_nb_verlet(const gmx::MDLogger& mdlog, @@ -387,31 +410,7 @@ std::unique_ptr 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); diff --git a/src/gromacs/nbnxm/pairlist.cpp b/src/gromacs/nbnxm/pairlist.cpp index a53233c2e1..7c963691f6 100644 --- a/src/gromacs/nbnxm/pairlist.cpp +++ b/src/gromacs/nbnxm/pairlist.cpp @@ -4340,7 +4340,7 @@ void PairlistSets::construct(const InteractionLocality iLocality, void nonbonded_verlet_t::constructPairlist(const InteractionLocality iLocality, const ListOfLists& exclusions, int64_t step, - t_nrnb* nrnb) + t_nrnb* nrnb) const { pairlistSets_->construct(iLocality, pairSearch_.get(), nbat.get(), exclusions, step, nrnb); diff --git a/src/gromacs/nbnxm/pairlistwork.h b/src/gromacs/nbnxm/pairlistwork.h index 3fce22eab7..b30f37a50b 100644 --- a/src/gromacs/nbnxm/pairlistwork.h +++ b/src/gromacs/nbnxm/pairlistwork.h @@ -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() : diff --git a/src/gromacs/nbnxm/pairsearch.h b/src/gromacs/nbnxm/pairsearch.h index c4c92969a1..70ae875162 100644 --- a/src/gromacs/nbnxm/pairsearch.h +++ b/src/gromacs/nbnxm/pairsearch.h @@ -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 @@ -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 diff --git a/src/gromacs/nbnxm/prunekerneldispatch.cpp b/src/gromacs/nbnxm/prunekerneldispatch.cpp index 9b98e5f92f..4a09d6d94d 100644 --- a/src/gromacs/nbnxm/prunekerneldispatch.cpp +++ b/src/gromacs/nbnxm/prunekerneldispatch.cpp @@ -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); }