From f4078e67f505a029a759e67e7a2483f93b0e7464 Mon Sep 17 00:00:00 2001 From: Joe Jordan Date: Sat, 20 Feb 2021 08:52:44 +0000 Subject: [PATCH] Remove unsed structs from nblist and use vector in t_nblist Several unused structs are removed from nblist.h. Some unused members of t_nblist are removed, and pointers are changed to vectors. --- .../gmxlib/nonbonded/nb_free_energy.cpp | 14 +- src/gromacs/mdtypes/md_enums.cpp | 9 -- src/gromacs/mdtypes/md_enums.h | 28 ---- src/gromacs/mdtypes/nblist.h | 121 ++---------------- src/gromacs/nbnxm/pairlist.cpp | 58 ++------- src/gromacs/nbnxm/pairlist.h | 5 +- src/gromacs/nbnxm/pairsearch.cpp | 26 +--- 7 files changed, 38 insertions(+), 223 deletions(-) diff --git a/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp b/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp index fffb72a14c..d036d8510a 100644 --- a/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp +++ b/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp @@ -227,12 +227,12 @@ static void nb_free_energy_kernel(const t_nblist* gmx_restrict nlist, const interaction_const_t* ic = fr->ic; // Extract pair list data - const int nri = nlist->nri; - const int* iinr = nlist->iinr; - const int* jindex = nlist->jindex; - const int* jjnr = nlist->jjnr; - const int* shift = nlist->shift; - const int* gid = nlist->gid; + const int nri = nlist->nri; + gmx::ArrayRef iinr = nlist->iinr; + gmx::ArrayRef jindex = nlist->jindex; + gmx::ArrayRef jjnr = nlist->jjnr; + gmx::ArrayRef shift = nlist->shift; + gmx::ArrayRef gid = nlist->gid; const real* shiftvec = fr->shift_vec[0]; const real* chargeA = mdatoms->chargeA; @@ -420,7 +420,7 @@ static void nb_free_energy_kernel(const t_nblist* gmx_restrict nlist, const RealType rSq = dX * dX + dY * dY + dZ * dZ; RealType fScalC[NSTATES], fScalV[NSTATES]; /* Check if this pair on the exlusions list.*/ - const bool bPairIncluded = nlist->excl_fep == nullptr || nlist->excl_fep[k]; + const bool bPairIncluded = nlist->excl_fep.empty() || nlist->excl_fep[k]; if (rSq >= rcutoff_max2 && bPairIncluded) { diff --git a/src/gromacs/mdtypes/md_enums.cpp b/src/gromacs/mdtypes/md_enums.cpp index c3313017cb..53a24a3a11 100644 --- a/src/gromacs/mdtypes/md_enums.cpp +++ b/src/gromacs/mdtypes/md_enums.cpp @@ -189,15 +189,6 @@ const char* eSwapTypes_names[eSwapTypesNR + 1] = { "no", "X", "Y", "Z", nullptr const char* eSwapFixedGrp_names[eSwapFixedGrpNR + 1] = { "Split0", "Split1", "Solvent", nullptr }; -const char* gmx_nblist_geometry_names[GMX_NBLIST_GEOMETRY_NR + 1] = { - "Particle-Particle", "Water3-Particle", "Water3-Water3", "Water4-Particle", - "Water4-Water4", "CG-CG", nullptr -}; - -const char* gmx_nblist_interaction_names[GMX_NBLIST_INTERACTION_NR + 1] = { "Standard", - "Free_Energy", - nullptr }; - const char* gmx_nbkernel_elec_names[GMX_NBKERNEL_ELEC_NR + 1] = { "None", "Coulomb", "Reaction-Field", "Cubic-Spline-Table", "Ewald", nullptr }; diff --git a/src/gromacs/mdtypes/md_enums.h b/src/gromacs/mdtypes/md_enums.h index 2f358ca418..3728713a30 100644 --- a/src/gromacs/mdtypes/md_enums.h +++ b/src/gromacs/mdtypes/md_enums.h @@ -779,24 +779,6 @@ enum //! String for swap group splitting extern const char* eSwapFixedGrp_names[eSwapFixedGrpNR + 1]; -/*! \brief Neighborlist geometry type. - * - * Kernels will compute interactions between two particles, - * 3-center water, 4-center water or coarse-grained beads. - */ -enum gmx_nblist_kernel_geometry -{ - GMX_NBLIST_GEOMETRY_PARTICLE_PARTICLE, - GMX_NBLIST_GEOMETRY_WATER3_PARTICLE, - GMX_NBLIST_GEOMETRY_WATER3_WATER3, - GMX_NBLIST_GEOMETRY_WATER4_PARTICLE, - GMX_NBLIST_GEOMETRY_WATER4_WATER4, - GMX_NBLIST_GEOMETRY_CG_CG, - GMX_NBLIST_GEOMETRY_NR -}; -//! String corresponding to nblist geometry names -extern const char* gmx_nblist_geometry_names[GMX_NBLIST_GEOMETRY_NR + 1]; - /*! \brief Types of electrostatics calculations * * Types of electrostatics calculations available inside nonbonded kernels. @@ -833,14 +815,4 @@ enum gmx_nbkernel_vdw //! String corresponding to VdW kernels extern const char* gmx_nbkernel_vdw_names[GMX_NBKERNEL_VDW_NR + 1]; -//! \brief Types of interactions inside the neighborlist -enum gmx_nblist_interaction_type -{ - GMX_NBLIST_INTERACTION_STANDARD, - GMX_NBLIST_INTERACTION_FREE_ENERGY, - GMX_NBLIST_INTERACTION_NR -}; -//! String corresponding to interactions in neighborlist code -extern const char* gmx_nblist_interaction_names[GMX_NBLIST_INTERACTION_NR + 1]; - #endif /* GMX_MDTYPES_MD_ENUMS_H */ diff --git a/src/gromacs/mdtypes/nblist.h b/src/gromacs/mdtypes/nblist.h index 6427c9d26c..3b6e5b145f 100644 --- a/src/gromacs/mdtypes/nblist.h +++ b/src/gromacs/mdtypes/nblist.h @@ -40,11 +40,8 @@ #include #include "gromacs/utility/alignedallocator.h" -#include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/real.h" -typedef unsigned long t_excl; - /* The interactions contained in a (possibly merged) table * for computing electrostatic, VDW repulsion and/or VDW dispersion * contributions. @@ -79,95 +76,20 @@ enum gmx_table_format GMX_TABLE_FORMAT_NR }; -enum +struct t_nblist { - eNL_VDWQQ, - eNL_VDW, - eNL_QQ, - eNL_VDWQQ_FREE, - eNL_VDW_FREE, - eNL_QQ_FREE, - eNL_VDWQQ_WATER, - eNL_QQ_WATER, - eNL_VDWQQ_WATERWATER, - eNL_QQ_WATERWATER, - eNL_NR + int nri = 0; /* Current number of i particles */ + int maxnri = 0; /* Max number of i particles */ + int nrj = 0; /* Current number of j particles */ + int maxnrj = 0; /* ;Max number of j particles */ + std::vector iinr; /* The i-elements */ + std::vector gid; /* Index in energy arrays */ + std::vector shift; /* Shift vector index */ + std::vector jindex; /* Index in jjnr */ + std::vector jjnr; /* The j-atom list */ + std::vector excl_fep; /* Exclusions for FEP with Verlet scheme */ }; -#define MAX_CG 1024 - -typedef struct -{ - int ncg; - int nj; - int jcg[MAX_CG]; -} t_ns_buf; - - -/* The maximum charge group size because of minimum size of t_excl - * could be 32 bits. - */ -#define MAX_CHARGEGROUP_SIZE 32 - -/* The maximum charge group size for CG-CG nblists. - * The excl entry in t_nblist uses blocks of this size. - */ -#define MAX_CGCGSIZE 32 - -typedef struct t_nblist -{ - int igeometry; /* The type of list (atom, water, etc.) */ - int ielec; /* Coulomb loop type index for kernels */ - int ielecmod; /* Coulomb modifier (e.g. switch/shift) */ - int ivdw; /* VdW loop type index for kernels */ - int ivdwmod; /* VdW modifier (e.g. switch/shift) */ - int type; /* Type of interaction, listed in - gmx_nblist_interaction_type */ - - int nri, maxnri; /* Current/max number of i particles */ - int nrj, maxnrj; /* Current/max number of j particles */ - int* iinr; /* The i-elements */ - int* iinr_end; /* The end atom, only with enlistCG */ - int* gid; /* Index in energy arrays */ - int* shift; /* Shift vector index */ - int* jindex; /* Index in jjnr */ - int* jjnr; /* The j-atom list */ - int* jjnr_end; /* The end atom, only with enltypeCG */ - char* excl_fep; /* Exclusions for FEP with Verlet scheme */ - t_excl* excl; /* Exclusions, only with enltypeCG */ - - /* We use separate pointers for kernels that compute both potential - * and force (vf suffix), only potential (v) or only force (f) - */ - void* kernelptr_vf; - void* kernelptr_v; - void* kernelptr_f; - - /* Pad the list of neighbors for each i atom with "-1" entries up to the - * simd_padding_width, if it is larger than 0. This is necessary for many - * accelerated kernels using single-instruction multiple-data operations - * internally. - */ - int simd_padding_width; - -} t_nblist; - -/* For atom I = nblist->iinr[N] (0 <= N < nblist->nri) there can be - * several neighborlists (N's), for different energy groups (gid) and - * different shifts (shift). - * For corresponding J atoms for each list start at: - * nblist->jjnr[JI] - * with nblist->jindex[N] <= JI < nblist->jindex[N+1] - * - * enlist is of the form enlistUNIT1_UNIT2: - * UNIT ATOM: there is one atom: iinr[N] or jjnr[JI] - * UNIT SPC: there are 3 atoms: iinr[N],iinr[N]+1,iinr[N]+2, jjnr analog. - * UNIT TIP4P: there are 4 atoms: iinr[N],...,iinr[N]+3, jjnr analog. - * UNIT CG: there are N atoms: iinr[N],...,iinr_end[N]-1, jjnr analog. - * - * Clear? - */ - /* Structure describing the data in a single table */ struct t_forcetable { @@ -193,25 +115,4 @@ struct t_forcetable int stride; /* Distance to next table point (number of fp variables per table point in total) */ }; -struct gmx_ns_t -{ - gmx_bool bCGlist; - int* simple_aaj; - t_excl* bexcl; - gmx_bool* bHaveVdW; - t_ns_buf** ns_buf; - gmx_bool* bExcludeAlleg; - int nra_alloc; - int cg_alloc; - int** nl_sr; - int* nsr; - int** nl_lr_ljc; - int** nl_lr_one; - int* nlr_ljc; - int* nlr_one; - /* the nblists should probably go in here */ - gmx_bool nblist_initialized; /* has the nblist been initialized? */ - int dump_nl; /* neighbour list dump level (from env. var. GMX_DUMP_NL)*/ -}; - #endif /* GMX_MDTYPES_NBLIST_H */ diff --git a/src/gromacs/nbnxm/pairlist.cpp b/src/gromacs/nbnxm/pairlist.cpp index 4040db0a9b..8d8186beb1 100644 --- a/src/gromacs/nbnxm/pairlist.cpp +++ b/src/gromacs/nbnxm/pairlist.cpp @@ -217,29 +217,6 @@ static inline int xIndexFromCj(int cj) } #endif // defined(GMX_NBNXN_SIMD_4XN) || defined(GMX_NBNXN_SIMD_2XNN) - -void nbnxn_init_pairlist_fep(t_nblist* nl) -{ - nl->type = GMX_NBLIST_INTERACTION_FREE_ENERGY; - nl->igeometry = GMX_NBLIST_GEOMETRY_PARTICLE_PARTICLE; - /* The interaction functions are set in the free energy kernel function */ - nl->ivdw = -1; - nl->ivdwmod = -1; - nl->ielec = -1; - nl->ielecmod = -1; - - nl->maxnri = 0; - nl->maxnrj = 0; - nl->nri = 0; - nl->nrj = 0; - nl->iinr = nullptr; - nl->gid = nullptr; - nl->shift = nullptr; - nl->jindex = nullptr; - nl->jjnr = nullptr; - nl->excl_fep = nullptr; -} - static constexpr int sizeNeededForBufferFlags(const int numAtoms) { return (numAtoms + NBNXN_BUFFERFLAG_SIZE - 1) / NBNXN_BUFFERFLAG_SIZE; @@ -733,7 +710,6 @@ PairlistSet::PairlistSet(const InteractionLocality locality, const PairlistParam * impacts performance. */ fepLists_[i] = std::make_unique(); - nbnxn_init_pairlist_fep(fepLists_[i].get()); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR } @@ -1462,20 +1438,10 @@ static inline void fep_list_new_nri_copy(t_nblist* nlist) /* Rellocate FEP list for size nl->maxnri, TODO: replace by C++ */ static void reallocate_nblist(t_nblist* nl) { - if (gmx_debug_at) - { - fprintf(debug, - "reallocating neigborlist (ielec=%d, ivdw=%d, igeometry=%d, type=%d), maxnri=%d\n", - nl->ielec, - nl->ivdw, - nl->igeometry, - nl->type, - nl->maxnri); - } - srenew(nl->iinr, nl->maxnri); - srenew(nl->gid, nl->maxnri); - srenew(nl->shift, nl->maxnri); - srenew(nl->jindex, nl->maxnri + 1); + nl->iinr.resize(nl->maxnri); + nl->gid.resize(nl->maxnri); + nl->shift.resize(nl->maxnri); + nl->jindex.resize(nl->maxnri + 1); } /* For load balancing of the free-energy lists over threads, we set @@ -1573,8 +1539,8 @@ static void make_fep_list(gmx::ArrayRef atomIndices, if (nlist->nrj + (cj_ind_end - cj_ind_start) * nbl->na_cj > nlist->maxnrj) { nlist->maxnrj = over_alloc_small(nlist->nrj + (cj_ind_end - cj_ind_start) * nbl->na_cj); - srenew(nlist->jjnr, nlist->maxnrj); - srenew(nlist->excl_fep, nlist->maxnrj); + nlist->jjnr.resize(nlist->maxnrj); + nlist->excl_fep.resize(nlist->maxnrj); } if (ngid > 1) @@ -1775,8 +1741,8 @@ static void make_fep_list(gmx::ArrayRef atomIndices, if (nrjMax > nlist->maxnrj) { nlist->maxnrj = over_alloc_small(nrjMax); - srenew(nlist->jjnr, nlist->maxnrj); - srenew(nlist->excl_fep, nlist->maxnrj); + nlist->jjnr.resize(nlist->maxnrj); + nlist->excl_fep.resize(nlist->maxnrj); } for (int cj4_ind = cj4_ind_start; cj4_ind < cj4_ind_end; cj4_ind++) @@ -2227,9 +2193,9 @@ static void clear_pairlist_fep(t_nblist* nl) { nl->nri = 0; nl->nrj = 0; - if (nl->jindex == nullptr) + if (nl->jindex.empty()) { - snew(nl->jindex, 1); + nl->jindex.resize(1); } nl->jindex[0] = 0; } @@ -2728,8 +2694,8 @@ static void balance_fep_lists(gmx::ArrayRef> fepLists, if (nri_tot > nbl->maxnri || nrj_tot > nbl->maxnrj) { nbl->maxnrj = over_alloc_small(nrj_tot); - srenew(nbl->jjnr, nbl->maxnrj); - srenew(nbl->excl_fep, nbl->maxnrj); + nbl->jjnr.resize(nbl->maxnrj); + nbl->excl_fep.resize(nbl->maxnrj); } clear_pairlist_fep(nbl); diff --git a/src/gromacs/nbnxm/pairlist.h b/src/gromacs/nbnxm/pairlist.h index 5bdfba33a8..bb9db400ba 100644 --- a/src/gromacs/nbnxm/pairlist.h +++ b/src/gromacs/nbnxm/pairlist.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. @@ -299,7 +299,4 @@ struct NbnxnPairlistGpu gmx_cache_protect_t cp1; }; -//! Initializes a free-energy pair-list -void nbnxn_init_pairlist_fep(t_nblist* nl); - #endif diff --git a/src/gromacs/nbnxm/pairsearch.cpp b/src/gromacs/nbnxm/pairsearch.cpp index d606779b8c..546b95ff65 100644 --- a/src/gromacs/nbnxm/pairsearch.cpp +++ b/src/gromacs/nbnxm/pairsearch.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. @@ -46,7 +46,6 @@ #include "pairsearch.h" #include "gromacs/mdtypes/nblist.h" -#include "gromacs/utility/smalloc.h" #include "pairlist.h" @@ -75,30 +74,19 @@ void SearchCycleCounting::printCycles(FILE* fp, gmx::ArrayRefiinr); - sfree(nl->gid); - sfree(nl->shift); - sfree(nl->jindex); - sfree(nl->jjnr); - sfree(nl->excl_fep); -} - #ifndef DOXYGEN -PairsearchWork::PairsearchWork() : cp0({ { 0 } }), ndistc(0), nbl_fep(new t_nblist), cp1({ { 0 } }) +PairsearchWork::PairsearchWork() : + cp0({ { 0 } }), + ndistc(0), + nbl_fep(std::make_unique()), + cp1({ { 0 } }) { - nbnxn_init_pairlist_fep(nbl_fep.get()); } #endif // !DOXYGEN -PairsearchWork::~PairsearchWork() -{ - free_nblist(nbl_fep.get()); -} +PairsearchWork::~PairsearchWork() = default; PairSearch::PairSearch(const PbcType pbcType, const bool doTestParticleInsertion, -- 2.22.0