Extact UnitCellInfo from gmx_domdec_t
authorBerk Hess <hess@kth.se>
Tue, 3 Sep 2019 07:40:10 +0000 (09:40 +0200)
committerSzilárd Páll <pall.szilard@gmail.com>
Tue, 3 Sep 2019 14:08:49 +0000 (16:08 +0200)
This required adding an explicit constructor for gmx_domdec_t,
which is currently incomplete.

Change-Id: Iba39fec36945465bffaf97d499c56501500ecb3b

src/gromacs/domdec/box.cpp
src/gromacs/domdec/box.h
src/gromacs/domdec/distribute.cpp
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/domdec_specatomcomm.cpp
src/gromacs/domdec/domdec_struct.h
src/gromacs/domdec/dump.cpp
src/gromacs/domdec/partition.cpp
src/gromacs/domdec/redistribute.cpp

index 050ebdccb655237183151cf5b16352dd7492f404..42bcd2bc3c29a6d5f45507bea6600768981f6de1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2014,2015,2017,2018,2019, 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.
@@ -293,7 +293,7 @@ void set_ddbox(const gmx_domdec_t             &dd,
         gmx::ArrayRef<const gmx::RVec> xRef =
             constArrayRefFromArray(x.data(), masterRankHasTheSystemState ? x.size() : dd.comm->atomRanges.numHomeAtoms());
 
-        low_set_ddbox(dd.npbcdim, dd.numBoundedDimensions,
+        low_set_ddbox(dd.unitCellInfo.npbcdim, dd.unitCellInfo.numBoundedDimensions,
                       &dd.nc, box, calculateUnboundedSize, xRef,
                       needToReduceCoordinateData ? &dd.mpi_comm_all : nullptr,
                       ddbox);
@@ -320,8 +320,3 @@ void set_ddbox_cr(const t_commrec                &cr,
 
     gmx_bcast(sizeof(gmx_ddbox_t), ddbox, &cr);
 }
-
-bool dynamic_dd_box(const gmx_domdec_t &dd)
-{
-    return (dd.numBoundedDimensions < DIM || dd.haveDynamicBox);
-}
index f4b37daf16e31c0d232efe468b39cc643d5d7166..8e8b396da374e16a2fb9b99b8807a5e5404a3d1e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
@@ -70,7 +70,4 @@ void set_ddbox_cr(const t_commrec                &cr,
                   gmx::ArrayRef<const gmx::RVec>  x,
                   gmx_ddbox_t                    *ddbox);
 
-//! Returns whether the DD box can change size.
-bool dynamic_dd_box(const gmx_domdec_t &dd);
-
 #endif
index 57540a1e14d5aec8251c9917f541600708dd91c8..25efe43f9defa737a35290c0c2ef5dc445d56208 100644 (file)
@@ -319,9 +319,9 @@ computeAtomGroupDomainIndex(const gmx_domdec_t                         &dd,
     for (int d = DIM - 1; d >= 0; d--)
     {
         real pos_d = cog[d];
-        if (d < dd.npbcdim)
+        if (d < dd.unitCellInfo.npbcdim)
         {
-            bool bScrew = (dd.bScrewPBC && d == XX);
+            bool bScrew = (dd.unitCellInfo.haveScrewPBC && d == XX);
             if (ddbox.tric_dir[d] && dd.nc[d] > 1)
             {
                 /* Use triclinic coordinates for this dimension */
@@ -397,7 +397,7 @@ getAtomGroupDistribution(const gmx::MDLogger &mdlog,
     }
 
     matrix triclinicCorrectionMatrix;
-    make_tric_corr_matrix(dd->npbcdim, box, triclinicCorrectionMatrix);
+    make_tric_corr_matrix(dd->unitCellInfo.npbcdim, box, triclinicCorrectionMatrix);
 
     ivec       npulse;
     const auto cellBoundaries =
@@ -506,7 +506,7 @@ static void distributeAtomGroups(const gmx::MDLogger &mdlog,
     {
         GMX_ASSERT(box && pos, "box or pos not set on master");
 
-        if (dd->bScrewPBC)
+        if (dd->unitCellInfo.haveScrewPBC)
         {
             check_screw_box(box);
         }
index 3dc77780ef10e7dc92ce7a82b0189ef51fa0948d..3578ba693ac37bf278600be3d7932366e1cfb86f 100644 (file)
@@ -326,7 +326,7 @@ void dd_move_x(gmx_domdec_t             *dd,
     for (int d = 0; d < dd->ndim; d++)
     {
         bPBC   = (dd->ci[dd->dim[d]] == 0);
-        bScrew = (bPBC && dd->bScrewPBC && dd->dim[d] == XX);
+        bScrew = (bPBC && dd->unitCellInfo.haveScrewPBC && dd->dim[d] == XX);
         if (bPBC)
         {
             copy_rvec(box[dd->dim[d]], shift);
@@ -424,7 +424,7 @@ void dd_move_f(gmx_domdec_t              *dd,
         /* Only forces in domains near the PBC boundaries need to
            consider PBC in the treatment of fshift */
         const bool shiftForcesNeedPbc = (forceWithShiftForces->computeVirial() && dd->ci[dd->dim[d]] == 0);
-        const bool applyScrewPbc      = (shiftForcesNeedPbc && dd->bScrewPBC && dd->dim[d] == XX);
+        const bool applyScrewPbc      = (shiftForcesNeedPbc && dd->unitCellInfo.haveScrewPBC && dd->dim[d] == XX);
         /* Determine which shift vector we need */
         ivec       vis   = { 0, 0, 0 };
         vis[dd->dim[d]]  = 1;
@@ -2104,6 +2104,14 @@ static void setupUpdateGroups(const gmx::MDLogger &mdlog,
     }
 }
 
+UnitCellInfo::UnitCellInfo(const t_inputrec &ir) :
+    npbcdim(ePBC2npbcdim(ir.ePBC)),
+    numBoundedDimensions(inputrec2nboundeddim(&ir)),
+    ddBoxIsDynamic(numBoundedDimensions < DIM || inputrecDynamicBox(&ir)),
+    haveScrewPBC(ir.ePBC == epbcSCREW)
+{
+}
+
 /*! \brief Set the cell size and interaction limits, as well as the DD grid */
 static void set_dd_limits_and_grid(const gmx::MDLogger &mdlog,
                                    t_commrec *cr, gmx_domdec_t *dd,
@@ -2120,11 +2128,6 @@ static void set_dd_limits_and_grid(const gmx::MDLogger &mdlog,
     const real         tenPercentMargin = 1.1;
     gmx_domdec_comm_t *comm             = dd->comm;
 
-    dd->npbcdim              = ePBC2npbcdim(ir->ePBC);
-    dd->numBoundedDimensions = inputrec2nboundeddim(ir);
-    dd->haveDynamicBox       = inputrecDynamicBox(ir);
-    dd->bScrewPBC            = (ir->ePBC == epbcSCREW);
-
     dd->pme_recv_f_alloc = 0;
     dd->pme_recv_f_buf   = nullptr;
 
@@ -2643,7 +2646,7 @@ static void writeSettings(gmx::TextWriter       *log,
         }
         else
         {
-            if (dynamic_dd_box(*dd))
+            if (dd->unitCellInfo.ddBoxIsDynamic)
             {
                 log->writeLine("(the following are initial values, they could change due to box deformation)");
             }
@@ -2910,6 +2913,11 @@ static void set_dd_envvar_options(const gmx::MDLogger &mdlog,
     }
 }
 
+gmx_domdec_t::gmx_domdec_t(const t_inputrec &ir) :
+    unitCellInfo(ir)
+{
+}
+
 gmx_domdec_t *init_domain_decomposition(const gmx::MDLogger           &mdlog,
                                         t_commrec                     *cr,
                                         const DomdecOptions           &options,
@@ -2925,7 +2933,7 @@ gmx_domdec_t *init_domain_decomposition(const gmx::MDLogger           &mdlog,
     GMX_LOG(mdlog.info).appendTextFormatted(
             "\nInitializing Domain Decomposition on %d ranks", cr->nnodes);
 
-    dd = new gmx_domdec_t;
+    dd = new gmx_domdec_t(*ir);
 
     dd->comm = init_dd_comm();
 
@@ -2981,7 +2989,7 @@ static gmx_bool test_dd_cutoff(t_commrec     *cr,
         dim = dd->dim[d];
 
         inv_cell_size = DD_CELL_MARGIN*dd->nc[dim]/ddbox.box_size[dim];
-        if (dynamic_dd_box(*dd))
+        if (dd->unitCellInfo.ddBoxIsDynamic)
         {
             inv_cell_size *= DD_PRES_SCALE_MARGIN;
         }
index 59762d4d879b43632dd3e0f40983e7ae0b56ea98..91e50f72407369c76c29e7d716b771de9d521fd5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2006,2007,2008,2009,2010,2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2006,2007,2008,2009,2010,2012,2013,2014,2015,2017,2018,2019, 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.
@@ -94,7 +94,7 @@ void dd_move_f_specat(gmx_domdec_t *dd, gmx_domdec_specat_comm_t *spac,
             {
                 bPBC   = ((dir == 0 && dd->ci[dim] == 0) ||
                           (dir == 1 && dd->ci[dim] == dd->nc[dim]-1));
-                bScrew = (bPBC && dd->bScrewPBC && dim == XX);
+                bScrew = (bPBC && dd->unitCellInfo.haveScrewPBC && dim == XX);
 
                 spas = &spac->spas[d][dir];
                 /* Sum the buffer into the required forces */
@@ -149,7 +149,7 @@ void dd_move_f_specat(gmx_domdec_t *dd, gmx_domdec_specat_comm_t *spac,
                        f + n, spas->nrecv,
                        as_rvec_array(spac->vbuf.data()), spas->a.size());
             /* Sum the buffer into the required forces */
-            if (dd->bScrewPBC && dim == XX &&
+            if (dd->unitCellInfo.haveScrewPBC && dim == XX &&
                 (dd->ci[dim] == 0 ||
                  dd->ci[dim] == dd->nc[dim]-1))
             {
@@ -205,13 +205,13 @@ void dd_move_x_specat(gmx_domdec_t *dd, gmx_domdec_specat_comm_t *spac,
                 if (dir == 0 && dd->ci[dim] == 0)
                 {
                     bPBC   = TRUE;
-                    bScrew = (dd->bScrewPBC && dim == XX);
+                    bScrew = (dd->unitCellInfo.haveScrewPBC && dim == XX);
                     copy_rvec(box[dim], shift);
                 }
                 else if (dir == 1 && dd->ci[dim] == dd->nc[dim]-1)
                 {
                     bPBC   = TRUE;
-                    bScrew = (dd->bScrewPBC && dim == XX);
+                    bScrew = (dd->unitCellInfo.haveScrewPBC && dim == XX);
                     for (i = 0; i < DIM; i++)
                     {
                         shift[i] = -box[dim][i];
@@ -306,7 +306,7 @@ void dd_move_x_specat(gmx_domdec_t *dd, gmx_domdec_specat_comm_t *spac,
             for (v = 0; v < nvec; v++)
             {
                 rvec *x = (v == 0 ? x0 : x1);
-                if (dd->bScrewPBC && dim == XX &&
+                if (dd->unitCellInfo.haveScrewPBC && dim == XX &&
                     (dd->ci[XX] == 0 || dd->ci[XX] == dd->nc[XX]-1))
                 {
                     /* Here we only perform the rotation, the rest of the pbc
@@ -392,7 +392,7 @@ int setup_specat_communication(gmx_domdec_t               *dd,
     {
         /* Pulse the grid forward and backward */
         dim  = dd->dim[d];
-        bPBC = (dim < dd->npbcdim);
+        bPBC = (dim < dd->unitCellInfo.npbcdim);
         if (dd->nc[dim] == 2)
         {
             /* Only 2 cells, so we only need to communicate once */
@@ -439,7 +439,7 @@ int setup_specat_communication(gmx_domdec_t               *dd,
     for (int d = 0; d < dd->ndim; d++)
     {
         /* Pulse the grid forward and backward */
-        if (dd->dim[d] >= dd->npbcdim || dd->nc[dd->dim[d]] > 2)
+        if (dd->dim[d] >= dd->unitCellInfo.npbcdim || dd->nc[dd->dim[d]] > 2)
         {
             ndir = 2;
         }
index 4121a84eb5abf767a2bf185d85d54672cbdee2c3..07715b1d468ba7f4b2ec9ce58a312b5cd65c7c3d 100644 (file)
@@ -68,6 +68,7 @@ struct gmx_domdec_specat_comm_t;
 class gmx_ga2la_t;
 struct gmx_pme_comm_n_box_t;
 struct gmx_reverse_top_t;
+struct t_inputrec;
 
 namespace gmx
 {
@@ -134,8 +135,26 @@ struct gmx_ddbox_t {
     rvec normal[DIM];
 };
 
+/*! \internal \brief Provides information about properties of the unit cell */
+struct UnitCellInfo
+{
+    //! Constructor
+    UnitCellInfo(const t_inputrec &ir);
+
+    //! We have PBC from dim 0 (X) up to npbcdim
+    int  npbcdim;
+    //! The system is bounded from 0 (X) to numBoundedDimensions
+    int  numBoundedDimensions;
+    //! Tells whether the box bounding the atoms is dynamic
+    bool ddBoxIsDynamic;
+    //! Screw PBC?
+    bool haveScrewPBC;
+};
 
 struct gmx_domdec_t { //NOLINT(clang-analyzer-optin.performance.Padding)
+    //! Constructor, only partial for now
+    gmx_domdec_t(const t_inputrec &ir);
+
     /* The DD particle-particle nodes only */
     /* The communication setup within the communicator all
      * defined in dd->comm in domdec.c
@@ -156,24 +175,14 @@ struct gmx_domdec_t { //NOLINT(clang-analyzer-optin.performance.Padding)
     int                    nreq_pme = 0;
     MPI_Request            req_pme[8];
 
+    /* Properties of the unit cell */
+    UnitCellInfo unitCellInfo;
 
     /* The communication setup, identical for each cell, cartesian index */
     ivec     nc;
     int      ndim;
     ivec     dim; /* indexed by 0 to ndim */
 
-    /* TODO: Move the next 4, and more from domdec_internal.h, to a simulation system */
-
-    /* PBC from dim 0 (X) to npbcdim */
-    int  npbcdim;
-    /* The system is bounded from 0 (X) to numBoundedDimensions */
-    int  numBoundedDimensions;
-    /* Does the box size change during the simulaton? */
-    bool haveDynamicBox;
-
-    /* Screw PBC? */
-    gmx_bool bScrewPBC;
-
     /* Forward and backward neighboring cells, indexed by 0 to ndim */
     int  neighbor[DIM][2];
 
index 5e88a3dc29ddb3b869cd1f80278d6a8a72d4ab35..0a37a062692136ee9dddc9d10ec985e6632a7536 100644 (file)
@@ -101,7 +101,7 @@ void write_dd_grid_pdb(const char *fn, int64_t step,
         }
         sprintf(fname, "%s_%s.pdb", fn, gmx_step_str(step, buf));
         out = gmx_fio_fopen(fname, "w");
-        gmx_write_pdb_box(out, dd->bScrewPBC ? epbcSCREW : epbcXYZ, box);
+        gmx_write_pdb_box(out, dd->unitCellInfo.haveScrewPBC ? epbcSCREW : epbcXYZ, box);
         a = 1;
         for (i = 0; i < dd->nnodes; i++)
         {
@@ -165,7 +165,7 @@ void write_dd_pdb(const char *fn, int64_t step, const char *title,
     out = gmx_fio_fopen(fname, "w");
 
     fprintf(out, "TITLE     %s\n", title);
-    gmx_write_pdb_box(out, dd->bScrewPBC ? epbcSCREW : epbcXYZ, box);
+    gmx_write_pdb_box(out, dd->unitCellInfo.haveScrewPBC ? epbcSCREW : epbcXYZ, box);
     int molb = 0;
     for (int i = 0; i < natoms; i++)
     {
index a837d6b825f6a950174f899a87f6beb4bf7c47c3..23e5b939411f254b1c8f6d4ff51ff4f993521e46 100644 (file)
@@ -1645,7 +1645,7 @@ get_zone_pulse_cgs(gmx_domdec_t *dd,
 
     comm = dd->comm;
 
-    bScrew = (dd->bScrewPBC && dim == XX);
+    bScrew = (dd->unitCellInfo.haveScrewPBC && dim == XX);
 
     bDistMB_pulse = (bDistMB && bDistBonded);
 
@@ -2447,7 +2447,7 @@ static void set_zones_size(gmx_domdec_t *dd,
             {
                 corner[ZZ] = zones->size[z].x1[ZZ];
             }
-            if (dd->ndim == 1 && dd->dim[0] < ZZ && ZZ < dd->npbcdim &&
+            if (dd->ndim == 1 && dd->dim[0] < ZZ && ZZ < dd->unitCellInfo.npbcdim &&
                 box[ZZ][1 - dd->dim[0]] != 0)
             {
                 /* With 1D domain decomposition the cg's are not in
@@ -3032,7 +3032,7 @@ void dd_partition_system(FILE                    *fplog,
     copy_rvec(ddbox.box0, comm->box0    );
     copy_rvec(ddbox.box_size, comm->box_size);
 
-    set_dd_cell_sizes(dd, &ddbox, dynamic_dd_box(*dd), bMasterState, bDoDLB,
+    set_dd_cell_sizes(dd, &ddbox, dd->unitCellInfo.ddBoxIsDynamic, bMasterState, bDoDLB,
                       step, wcycle);
 
     if (comm->nstDDDumpGrid > 0 && step % comm->nstDDDumpGrid == 0)
@@ -3186,7 +3186,7 @@ void dd_partition_system(FILE                    *fplog,
     {
         np[dd->dim[i]] = comm->cd[i].numPulses();
     }
-    dd_make_local_top(dd, &comm->zones, dd->npbcdim, state_local->box,
+    dd_make_local_top(dd, &comm->zones, dd->unitCellInfo.npbcdim, state_local->box,
                       comm->cellsize_min, np,
                       fr,
                       state_local->x.rvec_array(),
index d766f3f5910a4772d7632d67ce7b5c5126b09629..d947b034b9e68baaf0942d10a9702e22acbf6433 100644 (file)
@@ -328,7 +328,7 @@ static void calc_cg_move(FILE *fplog, int64_t step,
                          int cg_start, int cg_end,
                          gmx::ArrayRef<int> move)
 {
-    const int npbcdim = dd->npbcdim;
+    const int npbcdim = dd->unitCellInfo.npbcdim;
     auto      x       = makeArrayRef(state->x);
 
     for (int a = cg_start; a < cg_end; a++)
@@ -343,7 +343,7 @@ static void calc_cg_move(FILE *fplog, int64_t step,
         {
             if (dd->nc[d] > 1)
             {
-                bool bScrew = (dd->bScrewPBC && d == XX);
+                bool bScrew = (dd->unitCellInfo.haveScrewPBC && d == XX);
                 /* Determine the location of this cg in lattice coordinates */
                 real pos_d = cm_new[d];
                 if (tric_dir[d])
@@ -449,9 +449,9 @@ static void calcGroupMove(FILE *fplog, int64_t step,
                           int groupBegin, int groupEnd,
                           gmx::ArrayRef<PbcAndFlag> pbcAndFlags)
 {
-    GMX_RELEASE_ASSERT(!dd->bScrewPBC, "Screw PBC is not supported here");
+    GMX_RELEASE_ASSERT(!dd->unitCellInfo.haveScrewPBC, "Screw PBC is not supported here");
 
-    const int             npbcdim         = dd->npbcdim;
+    const int             npbcdim         = dd->unitCellInfo.npbcdim;
 
     gmx::UpdateGroupsCog *updateGroupsCog = dd->comm->updateGroupsCog.get();
 
@@ -555,7 +555,7 @@ void dd_redistribute_cg(FILE *fplog, int64_t step,
 {
     gmx_domdec_comm_t *comm = dd->comm;
 
-    if (dd->bScrewPBC)
+    if (dd->unitCellInfo.haveScrewPBC)
     {
         check_screw_box(state->box);
     }
@@ -567,7 +567,7 @@ void dd_redistribute_cg(FILE *fplog, int64_t step,
     DDBufferAccess<int> moveBuffer(comm->intBuffer, dd->ncg_home);
     gmx::ArrayRef<int>  move = moveBuffer.buffer;
 
-    const int           npbcdim = dd->npbcdim;
+    const int           npbcdim = dd->unitCellInfo.npbcdim;
 
     rvec                cell_x0, cell_x1;
     MoveLimits          moveLimits;