Extract DomainSetup from nbnxn_search
authorBerk Hess <hess@kth.se>
Wed, 13 Mar 2019 12:55:33 +0000 (13:55 +0100)
committerBerk Hess <hess@kth.se>
Fri, 15 Mar 2019 07:24:00 +0000 (08:24 +0100)
Change-Id: I1a46c543e063b250e27b3759ddc050a46fc6692d

src/gromacs/nbnxm/gridset.cpp
src/gromacs/nbnxm/gridset.h
src/gromacs/nbnxm/internal.h
src/gromacs/nbnxm/pairlist.cpp

index 6b604d00848118d26202a3906cfc7911d7397e53..75dc905fd5f14e4a6ee13b400b0e385158f6e135 100644 (file)
 namespace Nbnxm
 {
 
-//! Returns the number of DD zones or 1 when \p numDDCells = nullptr
-static int numDDZones(const ivec *numDDCells)
+//! Returns the number of DD zones
+static int numDDZones(const std::array<bool, DIM> &haveDomDecPerDim)
 {
     int  numDDZones = 1;
-    bool haveDomDec = (numDDCells != nullptr);
-    if (haveDomDec)
+    for (auto haveDD : haveDomDecPerDim)
     {
-        for (int d = 0; d < DIM; d++)
+        if (haveDD)
         {
-            if ((*numDDCells)[d] > 1)
-            {
-                numDDZones *= 2;
-            }
+            numDDZones *= 2;
         }
     }
 
     return numDDZones;
 }
 
-GridSet::GridSet(const ivec         *numDDCells,
-                 const PairlistType  pairlistType,
-                 const bool          haveFep,
-                 const int           numThreads) :
-    grids_(numDDZones(numDDCells), pairlistType),
+GridSet::GridSet(const std::array<bool, DIM> &haveDomDecPerDim,
+                 const PairlistType           pairlistType,
+                 const bool                   haveFep,
+                 const int                    numThreads) :
+    grids_(numDDZones(haveDomDecPerDim), pairlistType),
     haveFep_(haveFep),
     numRealAtomsLocal_(0),
     numRealAtomsTotal_(0),
index bfd43206533b86b0ad74943e1113b4b0efcbce7b..a9abb38c455181a02aafd301e54853af86291b8c 100644 (file)
@@ -77,10 +77,10 @@ class GridSet
 {
     public:
         //! Constructs a grid set for 1 or multiple DD zones, when numDDCells!=nullptr
-        GridSet(const ivec   *numDDCells,
-                PairlistType  pairlistType,
-                bool          haveFep,
-                int           numThreads);
+        GridSet(const std::array<bool, DIM> &haveDomDecPerDim,
+                PairlistType                 pairlistType,
+                bool                         haveFep,
+                int                          numThreads);
 
         //! Puts the atoms in \p ddZone on the grid and copies the coordinates to \p nbat
         void putOnGrid(const matrix                    box,
index b41a42fd0f4e1e97db7ab70b95fda7333dd8b587..033e2e87377d71241dbfe4d92211dc16dc164be5 100644 (file)
@@ -105,30 +105,53 @@ struct nbnxn_search_work_t
 /* Main pair-search struct, contains the grid(s), not the pair-list(s) */
 struct nbnxn_search
 {
+    /*! \internal
+     * \brief Description of the domain setup: PBC and the connections between domains
+     */
+    struct DomainSetup
+    {
+        //! Constructor, without DD \p numDDCells and \p ddZones should be nullptr
+        DomainSetup(int                       ePBC,
+                    const ivec               *numDDCells,
+                    const gmx_domdec_zones_t *ddZones);
+
+        //! The type of PBC
+        int                       ePBC;
+        //! Tells whether we are using domain decomposition
+        bool                      haveDomDec;
+        //! Tells whether we are using domain decomposition per dimension
+        std::array<bool, DIM>     haveDomDecPerDim;
+        //! The domain decomposition zone setup
+        const gmx_domdec_zones_t *zones;
+    };
+
     /* \brief Constructor
      *
      * \param[in] ePBC            The periodic boundary conditions
-     * \param[in] n_dd_cells      The number of domain decomposition cells per dimension, without DD nullptr should be passed
+     * \param[in] numDDCells      The number of domain decomposition cells per dimension, without DD nullptr should be passed
      * \param[in] zones           The domain decomposition zone setup, without DD nullptr should be passed
      * \param[in] haveFep         Tells whether non-bonded interactions are perturbed
      * \param[in] maxNumThreads   The maximum number of threads used in the search
      */
     nbnxn_search(int                       ePBC,
-                 const ivec               *n_dd_cells,
+                 const ivec               *numDDCells,
                  const gmx_domdec_zones_t *zones,
                  PairlistType              pairlistType,
                  bool                      haveFep,
                  int                       maxNumthreads);
 
+    const DomainSetup &domainSetup() const
+    {
+        return domainSetup_;
+    }
+
     const Nbnxm::GridSet &gridSet() const
     {
         return gridSet_;
     }
 
-    int                        ePBC;            /* PBC type enum                              */
-    gmx_bool                   DomDec;          /* Are we doing domain decomposition?         */
-    ivec                       dd_dim;          /* Are we doing DD in x,y,z?                  */
-    const gmx_domdec_zones_t  *zones;           /* The domain decomposition zones        */
+    //! The domain setup
+    DomainSetup          domainSetup_;
 
     //! The local and non-local grids
     Nbnxm::GridSet       gridSet_;
index 17cb35706a4d461e6fcf9014acb060ee96f537af..1a4ec994c0c15d42f624b4f9bd8513f56d80be58 100644 (file)
@@ -299,32 +299,30 @@ nbnxn_search_work_t::~nbnxn_search_work_t()
     free_nblist(nbl_fep.get());
 }
 
+nbnxn_search::DomainSetup::DomainSetup(const int                 ePBC,
+                                       const ivec               *numDDCells,
+                                       const gmx_domdec_zones_t *ddZones) :
+    ePBC(ePBC),
+    haveDomDec(numDDCells != nullptr),
+    zones(ddZones)
+{
+    for (int d = 0; d < DIM; d++)
+    {
+        haveDomDecPerDim[d] = (numDDCells != nullptr && (*numDDCells)[d] > 1);
+    }
+}
+
 nbnxn_search::nbnxn_search(const int                 ePBC,
-                           const ivec               *n_dd_cells,
-                           const gmx_domdec_zones_t *zones,
+                           const ivec               *numDDCells,
+                           const gmx_domdec_zones_t *ddZones,
                            const PairlistType        pairlistType,
                            const bool                haveFep,
                            const int                 maxNumThreads) :
-    ePBC(ePBC),
-    zones(zones),
-    gridSet_(n_dd_cells, pairlistType, haveFep, maxNumThreads),
+    domainSetup_(ePBC, numDDCells, ddZones),
+    gridSet_(domainSetup_.haveDomDecPerDim, pairlistType, haveFep, maxNumThreads),
     search_count(0),
     work(maxNumThreads)
 {
-    clear_ivec(dd_dim);
-    DomDec = n_dd_cells != nullptr;
-    if (DomDec)
-    {
-        for (int d = 0; d < DIM; d++)
-        {
-            if ((*n_dd_cells)[d] > 1)
-            {
-                dd_dim[d] = 1;
-            }
-        }
-    }
-
-    /* Initialize detailed nbsearch cycle counting */
     print_cycles = (getenv("GMX_NBNXN_CYCLE") != nullptr);
     nbs_cycle_clear(cc);
 }
@@ -2633,7 +2631,7 @@ static void get_nsubpair_target(const nbnxn_search        *nbs,
     /* The formulas below are a heuristic estimate of the average nsj per si*/
     r_eff_sup = rlist + nbnxn_get_rlist_effective_inc(numAtomsCluster, ls);
 
-    if (!nbs->DomDec || nbs->zones->n == 1)
+    if (!nbs->domainSetup().haveDomDec || nbs->domainSetup().zones->n == 1)
     {
         nsp_est_nl = 0;
     }
@@ -2641,7 +2639,7 @@ static void get_nsubpair_target(const nbnxn_search        *nbs,
     {
         nsp_est_nl =
             gmx::square(dims.atomDensity/numAtomsCluster)*
-            nonlocal_vol2(nbs->zones, ls, r_eff_sup);
+            nonlocal_vol2(nbs->domainSetup().zones, ls, r_eff_sup);
     }
 
     if (iloc == InteractionLocality::Local)
@@ -3331,7 +3329,8 @@ static void nbnxn_make_pairlist_part(const nbnxn_search *nbs,
         /* Check if we need periodicity shifts.
          * Without PBC or with domain decomposition we don't need them.
          */
-        if (d >= ePBC2npbcdim(nbs->ePBC) || nbs->dd_dim[d])
+        if (d >= ePBC2npbcdim(nbs->domainSetup().ePBC) ||
+            nbs->domainSetup().haveDomDecPerDim[d])
         {
             shp[d] = 0;
         }
@@ -4075,7 +4074,7 @@ nonbonded_verlet_t::PairlistSets::construct(const InteractionLocality  iLocality
     }
     else
     {
-        nzi = nbs->zones->nizone;
+        nzi = nbs->domainSetup().zones->nizone;
     }
 
     if (!nbl_list->bSimple && minimumIlistCountForGpuBalancing_ > 0)
@@ -4107,6 +4106,8 @@ nonbonded_verlet_t::PairlistSets::construct(const InteractionLocality  iLocality
         }
     }
 
+    const gmx_domdec_zones_t *ddZones = nbs->domainSetup().zones;
+
     for (int zi = 0; zi < nzi; zi++)
     {
         const Grid &iGrid = nbs->gridSet().grids()[zi];
@@ -4120,8 +4121,8 @@ nonbonded_verlet_t::PairlistSets::construct(const InteractionLocality  iLocality
         }
         else
         {
-            zj0 = nbs->zones->izone[zi].j0;
-            zj1 = nbs->zones->izone[zi].j1;
+            zj0 = ddZones->izone[zi].j0;
+            zj1 = ddZones->izone[zi].j1;
             if (zi == 0)
             {
                 zj0++;
@@ -4138,12 +4139,12 @@ nonbonded_verlet_t::PairlistSets::construct(const InteractionLocality  iLocality
 
             nbs_cycle_start(&nbs->cc[enbsCCsearch]);
 
-            ci_block = get_ci_block_size(iGrid, nbs->DomDec, nnbl);
+            ci_block = get_ci_block_size(iGrid, nbs->domainSetup().haveDomDec, nnbl);
 
             /* With GPU: generate progressively smaller lists for
              * load balancing for local only or non-local with 2 zones.
              */
-            progBal = (iLocality == InteractionLocality::Local || nbs->zones->n <= 2);
+            progBal = (iLocality == InteractionLocality::Local || ddZones->n <= 2);
 
 #pragma omp parallel for num_threads(nnbl) schedule(static)
             for (int th = 0; th < nnbl; th++)
@@ -4314,7 +4315,7 @@ nonbonded_verlet_t::PairlistSets::construct(const InteractionLocality  iLocality
         nbs->search_count++;
     }
     if (nbs->print_cycles &&
-        (!nbs->DomDec || iLocality == InteractionLocality::NonLocal) &&
+        (!nbs->domainSetup().haveDomDec || iLocality == InteractionLocality::NonLocal) &&
         nbs->search_count % 100 == 0)
     {
         nbs_cycle_print(stderr, nbs);