Remove unsed structs from nblist and use vector in t_nblist
authorJoe Jordan <ejjordan12@gmail.com>
Sat, 20 Feb 2021 08:52:44 +0000 (08:52 +0000)
committerArtem Zhmurov <zhmurov@gmail.com>
Sat, 20 Feb 2021 08:52:44 +0000 (08:52 +0000)
Several unused structs are removed from nblist.h. Some unused members of
t_nblist are removed, and pointers are changed to vectors.

src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp
src/gromacs/mdtypes/md_enums.cpp
src/gromacs/mdtypes/md_enums.h
src/gromacs/mdtypes/nblist.h
src/gromacs/nbnxm/pairlist.cpp
src/gromacs/nbnxm/pairlist.h
src/gromacs/nbnxm/pairsearch.cpp

index fffb72a14cac2e310a23036623b7a48c2bf98c15..d036d8510a4317526382c44330da3defee190d9f 100644 (file)
@@ -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<const int> iinr   = nlist->iinr;
+    gmx::ArrayRef<const int> jindex = nlist->jindex;
+    gmx::ArrayRef<const int> jjnr   = nlist->jjnr;
+    gmx::ArrayRef<const int> shift  = nlist->shift;
+    gmx::ArrayRef<const int> 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)
             {
index c3313017cb7a0878a1e181c278500ba444c20829..53a24a3a11afd1c311a02bf98b3c0e7b8f9048f9 100644 (file)
@@ -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
 };
index 2f358ca418aaab7f5e8f645a0350e3070eb56e61..3728713a308f5c40ff0a520b3285401909f1a453 100644 (file)
@@ -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 */
index 6427c9d26c64bc83b45bf707d34aae55706c9721..3b6e5b145f7a585e60932cd000345d090ffa8d33 100644 (file)
 #include <vector>
 
 #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<int> iinr;       /* The i-elements                        */
+    std::vector<int> gid;        /* Index in energy arrays                */
+    std::vector<int> shift;      /* Shift vector index                    */
+    std::vector<int> jindex;     /* Index in jjnr                         */
+    std::vector<int> jjnr;       /* The j-atom list                       */
+    std::vector<int> 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 */
index 4040db0a9bd49b7972ac5907ed30b0d14510ba76..8d8186beb1b7b2624b0c588ddf504196ff1539fe 100644 (file)
@@ -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<t_nblist>();
-                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<const int> 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<const int> 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<std::unique_ptr<t_nblist>> 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);
index 5bdfba33a83a672f98b6ef8dff6db958ab1b5683..bb9db400baac0a5bbed00a3e7782378ac48c6c99 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.
@@ -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
index d606779b8c192833d6b5ce08e42e3e42599cdc83..546b95ff65baf7283103f925d228774d596d1380 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.
@@ -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::ArrayRef<const PairsearchWo
     fprintf(fp, "\n");
 }
 
-/*! \brief Frees the contents of a legacy t_nblist struct */
-static void free_nblist(t_nblist* nl)
-{
-    sfree(nl->iinr);
-    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<t_nblist>()),
+    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,