From f9efa33b8d372a8baf035c0a233caacb940bf303 Mon Sep 17 00:00:00 2001 From: Berk Hess Date: Tue, 3 Sep 2019 09:40:10 +0200 Subject: [PATCH] Extact UnitCellInfo from gmx_domdec_t This required adding an explicit constructor for gmx_domdec_t, which is currently incomplete. Change-Id: Iba39fec36945465bffaf97d499c56501500ecb3b --- src/gromacs/domdec/box.cpp | 9 ++---- src/gromacs/domdec/box.h | 5 +--- src/gromacs/domdec/distribute.cpp | 8 +++--- src/gromacs/domdec/domdec.cpp | 28 +++++++++++------- src/gromacs/domdec/domdec_specatomcomm.cpp | 16 +++++------ src/gromacs/domdec/domdec_struct.h | 33 ++++++++++++++-------- src/gromacs/domdec/dump.cpp | 4 +-- src/gromacs/domdec/partition.cpp | 8 +++--- src/gromacs/domdec/redistribute.cpp | 12 ++++---- 9 files changed, 66 insertions(+), 57 deletions(-) diff --git a/src/gromacs/domdec/box.cpp b/src/gromacs/domdec/box.cpp index 050ebdccb6..42bcd2bc3c 100644 --- a/src/gromacs/domdec/box.cpp +++ b/src/gromacs/domdec/box.cpp @@ -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 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); -} diff --git a/src/gromacs/domdec/box.h b/src/gromacs/domdec/box.h index f4b37daf16..8e8b396da3 100644 --- a/src/gromacs/domdec/box.h +++ b/src/gromacs/domdec/box.h @@ -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 x, gmx_ddbox_t *ddbox); -//! Returns whether the DD box can change size. -bool dynamic_dd_box(const gmx_domdec_t &dd); - #endif diff --git a/src/gromacs/domdec/distribute.cpp b/src/gromacs/domdec/distribute.cpp index 57540a1e14..25efe43f9d 100644 --- a/src/gromacs/domdec/distribute.cpp +++ b/src/gromacs/domdec/distribute.cpp @@ -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); } diff --git a/src/gromacs/domdec/domdec.cpp b/src/gromacs/domdec/domdec.cpp index 3dc77780ef..3578ba693a 100644 --- a/src/gromacs/domdec/domdec.cpp +++ b/src/gromacs/domdec/domdec.cpp @@ -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; } diff --git a/src/gromacs/domdec/domdec_specatomcomm.cpp b/src/gromacs/domdec/domdec_specatomcomm.cpp index 59762d4d87..91e50f7240 100644 --- a/src/gromacs/domdec/domdec_specatomcomm.cpp +++ b/src/gromacs/domdec/domdec_specatomcomm.cpp @@ -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; } diff --git a/src/gromacs/domdec/domdec_struct.h b/src/gromacs/domdec/domdec_struct.h index 4121a84eb5..07715b1d46 100644 --- a/src/gromacs/domdec/domdec_struct.h +++ b/src/gromacs/domdec/domdec_struct.h @@ -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]; diff --git a/src/gromacs/domdec/dump.cpp b/src/gromacs/domdec/dump.cpp index 5e88a3dc29..0a37a06269 100644 --- a/src/gromacs/domdec/dump.cpp +++ b/src/gromacs/domdec/dump.cpp @@ -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++) { diff --git a/src/gromacs/domdec/partition.cpp b/src/gromacs/domdec/partition.cpp index a837d6b825..23e5b93941 100644 --- a/src/gromacs/domdec/partition.cpp +++ b/src/gromacs/domdec/partition.cpp @@ -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(), diff --git a/src/gromacs/domdec/redistribute.cpp b/src/gromacs/domdec/redistribute.cpp index d766f3f591..d947b034b9 100644 --- a/src/gromacs/domdec/redistribute.cpp +++ b/src/gromacs/domdec/redistribute.cpp @@ -328,7 +328,7 @@ static void calc_cg_move(FILE *fplog, int64_t step, int cg_start, int cg_end, gmx::ArrayRef 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 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 moveBuffer(comm->intBuffer, dd->ncg_home); gmx::ArrayRef move = moveBuffer.buffer; - const int npbcdim = dd->npbcdim; + const int npbcdim = dd->unitCellInfo.npbcdim; rvec cell_x0, cell_x1; MoveLimits moveLimits; -- 2.22.0