From 1b08190dff964b370dc2e378cf5efa63132d4afa Mon Sep 17 00:00:00 2001 From: Berk Hess Date: Sat, 25 Sep 2021 13:13:11 +0000 Subject: [PATCH] Replace DOMAINDECOMP macro by a renamed function --- src/gromacs/domdec/mdsetup.cpp | 2 +- src/gromacs/ewald/pme.cpp | 2 +- src/gromacs/ewald/pme_load_balancing.cpp | 22 +++++------ src/gromacs/ewald/pme_redistribute.cpp | 2 +- src/gromacs/imd/imd.cpp | 2 +- src/gromacs/listed_forces/disre.cpp | 4 +- src/gromacs/mdlib/constr.cpp | 7 ++-- src/gromacs/mdlib/coupling.cpp | 10 ++--- src/gromacs/mdlib/force.cpp | 4 +- src/gromacs/mdlib/forcerec.cpp | 14 ++++--- src/gromacs/mdlib/lincs.cpp | 10 ++--- src/gromacs/mdlib/mdoutf.cpp | 12 +++--- src/gromacs/mdlib/resethandler.cpp | 2 +- src/gromacs/mdlib/sim_util.cpp | 16 ++++---- src/gromacs/mdlib/simulationsignal.cpp | 2 +- src/gromacs/mdlib/update.cpp | 37 ++++++++++--------- src/gromacs/mdrun/md.cpp | 20 +++++----- src/gromacs/mdrun/mimic.cpp | 14 +++---- src/gromacs/mdrun/minimize.cpp | 32 ++++++++-------- src/gromacs/mdrun/replicaexchange.cpp | 8 ++-- src/gromacs/mdrun/rerun.cpp | 10 ++--- src/gromacs/mdrun/runner.cpp | 10 ++--- src/gromacs/mdrun/shellfc.cpp | 8 ++-- src/gromacs/mdtypes/commrec.h | 12 ++++-- .../andersentemperaturecoupling.cpp | 4 +- src/gromacs/modularsimulator/domdechelper.cpp | 3 +- .../expandedensembleelement.cpp | 2 +- .../firstorderpressurecoupling.cpp | 2 +- src/gromacs/modularsimulator/forceelement.cpp | 6 +-- .../freeenergyperturbationdata.cpp | 2 +- src/gromacs/modularsimulator/mttk.cpp | 4 +- .../modularsimulator/nosehooverchains.cpp | 2 +- .../parrinellorahmanbarostat.cpp | 2 +- .../modularsimulator/simulatoralgorithm.cpp | 4 +- .../modularsimulator/statepropagatordata.cpp | 12 +++--- .../modularsimulator/topologyholder.cpp | 2 +- .../velocityscalingtemperaturecoupling.cpp | 4 +- src/gromacs/nbnxm/nbnxm_setup.cpp | 20 +++++----- src/gromacs/nbnxm/pairlist_tuning.cpp | 6 +-- src/gromacs/pulling/pull.cpp | 4 +- src/gromacs/pulling/pull_rotation.cpp | 2 +- src/gromacs/pulling/pullutil.cpp | 2 +- src/gromacs/restraint/restraintmdmodule.cpp | 2 +- .../restraint/restraintmdmodule_impl.h | 2 +- src/gromacs/swap/swapcoords.cpp | 2 +- 45 files changed, 181 insertions(+), 170 deletions(-) diff --git a/src/gromacs/domdec/mdsetup.cpp b/src/gromacs/domdec/mdsetup.cpp index f6799a6c23..9aedfc1b83 100644 --- a/src/gromacs/domdec/mdsetup.cpp +++ b/src/gromacs/domdec/mdsetup.cpp @@ -77,7 +77,7 @@ void mdAlgorithmsSetupAtomData(const t_commrec* cr, VirtualSitesHandler* vsite, gmx_shellfc_t* shellfc) { - bool usingDomDec = DOMAINDECOMP(cr); + bool usingDomDec = haveDDAtomOrdering(*cr); int numAtomIndex; int numHomeAtoms; diff --git a/src/gromacs/ewald/pme.cpp b/src/gromacs/ewald/pme.cpp index 4260cac22c..7438077d0b 100644 --- a/src/gromacs/ewald/pme.cpp +++ b/src/gromacs/ewald/pme.cpp @@ -1581,7 +1581,7 @@ int gmx_pme_do(struct gmx_pme_t* pme, { forcesRef = pme->atc[d + 1].f; } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_pmeredist_f(pme, &pme->atc[d], forcesRef, d == pme->ndecompdim - 1 && pme->bPPnode); } diff --git a/src/gromacs/ewald/pme_load_balancing.cpp b/src/gromacs/ewald/pme_load_balancing.cpp index 52aaeb9862..3292d9b0b3 100644 --- a/src/gromacs/ewald/pme_load_balancing.cpp +++ b/src/gromacs/ewald/pme_load_balancing.cpp @@ -306,7 +306,7 @@ void pme_loadbal_init(pme_load_balancing_t** pme_lb_p, pme_lb->cycles_n = 0; pme_lb->cycles_c = 0; // only master ranks do timing - if (!PAR(cr) || (DOMAINDECOMP(cr) && DDMASTER(cr->dd))) + if (!PAR(cr) || (haveDDAtomOrdering(*cr) && DDMASTER(cr->dd))) { pme_lb->startTime = gmx_gettime(); } @@ -335,7 +335,7 @@ void pme_loadbal_init(pme_load_balancing_t** pme_lb_p, pme_lb->step_rel_stop = PMETunePeriod * ir.nstlist; /* Delay DD load balancing when GPUs are used */ - if (pme_lb->bActive && DOMAINDECOMP(cr) && cr->dd->nnodes > 1 && bUseGPU) + if (pme_lb->bActive && haveDDAtomOrdering(*cr) && cr->dd->nnodes > 1 && bUseGPU) { /* Lock DLB=auto to off (does nothing when DLB=yes/no. * With GPUs and separate PME nodes, we want to first @@ -651,7 +651,7 @@ static void pme_load_balance(pme_load_balancing_t* pme_lb, { pme_lb->fastest = pme_lb->cur; - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { /* We found a new fastest setting, ensure that with subsequent * shorter cut-off's the dynamic load balancing does not make @@ -726,7 +726,7 @@ static void pme_load_balance(pme_load_balancing_t* pme_lb, { pme_lb->cur++; - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { OK = change_dd_cutoff(cr, box, x, pme_lb->setup[pme_lb->cur].rlistOuter); if (!OK) @@ -793,7 +793,7 @@ static void pme_load_balance(pme_load_balancing_t* pme_lb, } } - if (DOMAINDECOMP(cr) && pme_lb->stage > 0) + if (haveDDAtomOrdering(*cr) && pme_lb->stage > 0) { OK = change_dd_cutoff(cr, box, x, pme_lb->setup[pme_lb->cur].rlistOuter); if (!OK) @@ -960,11 +960,11 @@ void pme_loadbal_do(pme_load_balancing_t* pme_lb, * We also want to skip a number of steps and seconds while * the CPU and GPU, when used, performance stabilizes. */ - if (!PAR(cr) || (DOMAINDECOMP(cr) && DDMASTER(cr->dd))) + if (!PAR(cr) || (haveDDAtomOrdering(*cr) && DDMASTER(cr->dd))) { pme_lb->startupTimeDelayElapsed = (gmx_gettime() - pme_lb->startTime < c_startupTimeDelay); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_bcast(cr->dd, sizeof(bool), &pme_lb->startupTimeDelayElapsed); } @@ -997,7 +997,7 @@ void pme_loadbal_do(pme_load_balancing_t* pme_lb, */ else if (step_rel >= c_numFirstTuningIntervalSkipWithSepPme * ir.nstlist) { - GMX_ASSERT(DOMAINDECOMP(cr), "Domain decomposition should be active here"); + GMX_ASSERT(haveDDAtomOrdering(*cr), "Domain decomposition should be active here"); if (DDMASTER(cr->dd)) { /* If PME rank load is too high, start tuning. If @@ -1027,7 +1027,7 @@ void pme_loadbal_do(pme_load_balancing_t* pme_lb, { pme_lb->bBalance = FALSE; - if (DOMAINDECOMP(cr) && dd_dlb_is_locked(cr->dd)) + if (haveDDAtomOrdering(*cr) && dd_dlb_is_locked(cr->dd)) { /* Unlock the DLB=auto, DLB is allowed to activate */ dd_dlb_unlock(cr->dd); @@ -1048,7 +1048,7 @@ void pme_loadbal_do(pme_load_balancing_t* pme_lb, pme_lb->bActive = FALSE; } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { /* Set the cut-off limit to the final selected cut-off, * so we don't have artificial DLB limits. @@ -1096,7 +1096,7 @@ void pme_loadbal_do(pme_load_balancing_t* pme_lb, pme_lb->bActive = FALSE; } - if (!(pme_lb->bActive) && DOMAINDECOMP(cr) && dd_dlb_is_locked(cr->dd)) + if (!(pme_lb->bActive) && haveDDAtomOrdering(*cr) && dd_dlb_is_locked(cr->dd)) { /* Make sure DLB is allowed when we deactivate PME tuning */ dd_dlb_unlock(cr->dd); diff --git a/src/gromacs/ewald/pme_redistribute.cpp b/src/gromacs/ewald/pme_redistribute.cpp index 9fdea71a55..96c994b578 100644 --- a/src/gromacs/ewald/pme_redistribute.cpp +++ b/src/gromacs/ewald/pme_redistribute.cpp @@ -497,7 +497,7 @@ void do_redist_pos_coeffs(struct gmx_pme_t* pme, atc.pd.resize(xRef.size()); pme_calc_pidx_wrapper(xRef, pme->recipbox, &atc); /* Redistribute x (only once) and qA/c6A or qB/c6B */ - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_pmeredist_pos_coeffs(pme, bFirst, xRef, param_d, &atc); } diff --git a/src/gromacs/imd/imd.cpp b/src/gromacs/imd/imd.cpp index 7d0cef345c..41a999c414 100644 --- a/src/gromacs/imd/imd.cpp +++ b/src/gromacs/imd/imd.cpp @@ -1268,7 +1268,7 @@ void ImdSession::Impl::prepareForPositionAssembly(const t_commrec* cr, gmx::Arra } } - if (!DOMAINDECOMP(cr)) + if (!haveDDAtomOrdering(*cr)) { nat_loc = nat; ind_loc = ind; diff --git a/src/gromacs/listed_forces/disre.cpp b/src/gromacs/listed_forces/disre.cpp index 34a2627bd0..5091d16f57 100644 --- a/src/gromacs/listed_forces/disre.cpp +++ b/src/gromacs/listed_forces/disre.cpp @@ -378,7 +378,7 @@ void calc_disres_R_6(const t_commrec* cr, } /* NOTE: Rt_6 and Rtav_6 are stored consecutively in memory */ - if (cr && DOMAINDECOMP(cr)) + if (cr && haveDDAtomOrdering(*cr)) { gmx_sum(2 * dd->nres, dd->Rt_6, cr); } @@ -397,7 +397,7 @@ void calc_disres_R_6(const t_commrec* cr, GMX_ASSERT(cr != nullptr && ms != nullptr, "We need multisim with nsystems>1"); gmx_sum_sim(2 * dd->nres, dd->Rt_6, ms); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { gmx_bcast(2 * dd->nres, dd->Rt_6, cr->mpi_comm_mygroup); } diff --git a/src/gromacs/mdlib/constr.cpp b/src/gromacs/mdlib/constr.cpp index 255dfb77a3..798f4f12f1 100644 --- a/src/gromacs/mdlib/constr.cpp +++ b/src/gromacs/mdlib/constr.cpp @@ -269,7 +269,7 @@ static void write_constr_pdb(const char* fn, const char * anm, *resnm; dd = nullptr; - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd = cr->dd; dd_get_constraint_range(*dd, &dd_ac0, &dd_ac1); @@ -479,7 +479,8 @@ bool Constraints::Impl::apply(bool bLog, * by the constraint coordinate communication routine, * so that here we can use normal pbc. */ - pbc_null = set_pbc_dd(&pbc, ir.pbcType, DOMAINDECOMP(cr) ? cr->dd->numCells : nullptr, FALSE, box); + pbc_null = set_pbc_dd( + &pbc, ir.pbcType, haveDDAtomOrdering(*cr) ? cr->dd->numCells : nullptr, FALSE, box); } else { @@ -1157,7 +1158,7 @@ Constraints::Impl::Impl(const gmx_mtop_t& mtop_p, // When there are multiple PP domains and update groups are // not in use, the constraints might be split across the // domains, needing particular handling. - const bool mayHaveSplitConstraints = DOMAINDECOMP(cr) && !useUpdateGroups; + const bool mayHaveSplitConstraints = haveDDAtomOrdering(*cr) && !useUpdateGroups; if (ir.eConstrAlg == ConstraintAlgorithm::Lincs) { diff --git a/src/gromacs/mdlib/coupling.cpp b/src/gromacs/mdlib/coupling.cpp index f280129898..a9ed66d6ac 100644 --- a/src/gromacs/mdlib/coupling.cpp +++ b/src/gromacs/mdlib/coupling.cpp @@ -1278,11 +1278,11 @@ void andersen_tcoupl(const t_inputrec* ir, const std::vector& randomize, gmx::ArrayRef boltzfac) { - const int* gatindex = (DOMAINDECOMP(cr) ? cr->dd->globalAtomIndices.data() : nullptr); - int i; - int gc = 0; - gmx::ThreeFry2x64<0> rng(ir->andersen_seed, gmx::RandomDomain::Thermostat); - gmx::UniformRealDistribution uniformDist; + const int* gatindex = (haveDDAtomOrdering(*cr) ? cr->dd->globalAtomIndices.data() : nullptr); + int i; + int gc = 0; + gmx::ThreeFry2x64<0> rng(ir->andersen_seed, gmx::RandomDomain::Thermostat); + gmx::UniformRealDistribution uniformDist; gmx::TabulatedNormalDistribution normalDist; /* randomize the velocities of the selected particles */ diff --git a/src/gromacs/mdlib/force.cpp b/src/gromacs/mdlib/force.cpp index 4507dbc7bc..325d96e7cc 100644 --- a/src/gromacs/mdlib/force.cpp +++ b/src/gromacs/mdlib/force.cpp @@ -275,8 +275,8 @@ void CpuPpLongRangeNonbondeds::calculate(gmx_pme_t* pmedata, sigmaB_, box, commrec, - DOMAINDECOMP(commrec) ? dd_pme_maxshift_x(*commrec->dd) : 0, - DOMAINDECOMP(commrec) ? dd_pme_maxshift_y(*commrec->dd) : 0, + haveDDAtomOrdering(*commrec) ? dd_pme_maxshift_x(*commrec->dd) : 0, + haveDDAtomOrdering(*commrec) ? dd_pme_maxshift_y(*commrec->dd) : 0, nrnb_, wcycle_, ewaldOutput.vir_q, diff --git a/src/gromacs/mdlib/forcerec.cpp b/src/gromacs/mdlib/forcerec.cpp index 166ff08603..4ed9daa5e1 100644 --- a/src/gromacs/mdlib/forcerec.cpp +++ b/src/gromacs/mdlib/forcerec.cpp @@ -739,14 +739,15 @@ void init_forcerec(FILE* fplog, } else { - forcerec->bMolPBC = (!DOMAINDECOMP(commrec) || dd_bonded_molpbc(*commrec->dd, forcerec->pbcType)); + forcerec->bMolPBC = + (!haveDDAtomOrdering(*commrec) || dd_bonded_molpbc(*commrec->dd, forcerec->pbcType)); // Check and set up PBC for Ewald surface corrections or orientation restraints const bool useEwaldSurfaceCorrection = (EEL_PME_EWALD(inputrec.coulombtype) && inputrec.epsilon_surface != 0); const bool haveOrientationRestraints = (gmx_mtop_ftype_count(mtop, F_ORIRES) > 0); const bool moleculesAreAlwaysWhole = - (DOMAINDECOMP(commrec) && dd_moleculesAreAlwaysWhole(*commrec->dd)); + (haveDDAtomOrdering(*commrec) && dd_moleculesAreAlwaysWhole(*commrec->dd)); // WholeMoleculeTransform is only supported with a single PP rank if (!moleculesAreAlwaysWhole && !havePPDomainDecomposition(commrec) && (useEwaldSurfaceCorrection || haveOrientationRestraints)) @@ -761,10 +762,11 @@ void init_forcerec(FILE* fplog, } forcerec->wholeMoleculeTransform = std::make_unique( - mtop, inputrec.pbcType, DOMAINDECOMP(commrec)); + mtop, inputrec.pbcType, haveDDAtomOrdering(*commrec)); } - forcerec->bMolPBC = !DOMAINDECOMP(commrec) || dd_bonded_molpbc(*commrec->dd, forcerec->pbcType); + forcerec->bMolPBC = + !haveDDAtomOrdering(*commrec) || dd_bonded_molpbc(*commrec->dd, forcerec->pbcType); if (useEwaldSurfaceCorrection) { @@ -1051,12 +1053,12 @@ void init_forcerec(FILE* fplog, /* Set all the static charge group info */ forcerec->atomInfoForEachMoleculeBlock = makeAtomInfoForEachMoleculeBlock(mtop, forcerec); - if (!DOMAINDECOMP(commrec)) + if (!haveDDAtomOrdering(*commrec)) { forcerec->atomInfo = expandAtomInfo(mtop.molblock.size(), forcerec->atomInfoForEachMoleculeBlock); } - if (!DOMAINDECOMP(commrec)) + if (!haveDDAtomOrdering(*commrec)) { forcerec_set_ranges(forcerec, mtop.natoms, mtop.natoms, mtop.natoms); } diff --git a/src/gromacs/mdlib/lincs.cpp b/src/gromacs/mdlib/lincs.cpp index a6ff2e0477..bc476f1d7d 100644 --- a/src/gromacs/mdlib/lincs.cpp +++ b/src/gromacs/mdlib/lincs.cpp @@ -1099,13 +1099,13 @@ static void do_lincs(ArrayRefWithPadding xPadded, for (int iter = 0; iter < lincsd->nIter; iter++) { - if ((lincsd->bCommIter && DOMAINDECOMP(cr) && cr->dd->constraints)) + if ((lincsd->bCommIter && haveDDAtomOrdering(*cr) && cr->dd->constraints)) { #pragma omp barrier #pragma omp master { /* Communicate the corrected non-local coordinates */ - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_move_x_constraints(cr->dd, box, xpPadded.unpaddedArrayRef(), ArrayRef(), FALSE); } @@ -1894,7 +1894,7 @@ void set_lincs(const InteractionDefinitions& idef, } int natoms; - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { if (cr->dd->constraints) { @@ -1928,7 +1928,7 @@ void set_lincs(const InteractionDefinitions& idef, li->blnr.resize(numEntries + 1); li->bllen.resize(numEntries); li->tmpv.resizeWithPadding(numEntries); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { li->nlocat.resize(numEntries); } @@ -2078,7 +2078,7 @@ void set_lincs(const InteractionDefinitions& idef, /* Without DD we order the blbnb matrix to optimize memory access. * With DD the overhead of sorting is more than the gain during access. */ - bSortMatrix = !DOMAINDECOMP(cr); + bSortMatrix = !haveDDAtomOrdering(*cr); li->blbnb.resize(li->ncc); diff --git a/src/gromacs/mdlib/mdoutf.cpp b/src/gromacs/mdlib/mdoutf.cpp index 3e0cc76354..ecf83d907e 100644 --- a/src/gromacs/mdlib/mdoutf.cpp +++ b/src/gromacs/mdlib/mdoutf.cpp @@ -235,7 +235,7 @@ gmx_mdoutf_t init_mdoutf(FILE* fplog, } } - if (ir->nstfout && DOMAINDECOMP(cr)) + if (ir->nstfout && haveDDAtomOrdering(*cr)) { snew(of->f_global, top_global.natoms); } @@ -306,7 +306,7 @@ static void write_checkpoint(const char* fn, char buf[1024], suffix[5 + STEPSTRSIZE], sbuf[STEPSTRSIZE]; t_fileio* ret; - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { npmenodes = cr->npmenodes; } @@ -387,7 +387,7 @@ static void write_checkpoint(const char* fn, std::strcpy(headerContents.version, gmx_version()); std::strcpy(headerContents.fprog, gmx::getProgramContext().fullBinaryPath()); std::strcpy(headerContents.ftime, timebuf.c_str()); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { copy_ivec(domdecCells, headerContents.dd_nc); } @@ -512,8 +512,8 @@ void mdoutf_write_checkpoint(gmx_mdoutf_t of, of->bKeepAndNumCPT, fplog, cr, - DOMAINDECOMP(cr) ? cr->dd->numCells : one_ivec, - DOMAINDECOMP(cr) ? cr->dd->nnodes : cr->nnodes, + haveDDAtomOrdering(*cr) ? cr->dd->numCells : one_ivec, + haveDDAtomOrdering(*cr) ? cr->dd->nnodes : cr->nnodes, of->eIntegrator, of->simulation_part, of->bExpanded, @@ -543,7 +543,7 @@ void mdoutf_write_to_trajectory_files(FILE* fplog, { const rvec* f_global; - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { if (mdof_flags & MDOF_CPT) { diff --git a/src/gromacs/mdlib/resethandler.cpp b/src/gromacs/mdlib/resethandler.cpp index be4d76eea5..0a21d89c85 100644 --- a/src/gromacs/mdlib/resethandler.cpp +++ b/src/gromacs/mdlib/resethandler.cpp @@ -193,7 +193,7 @@ bool ResetHandler::resetCountersImpl(int64_t step, wallcycle_stop(wcycle, WallCycleCounter::Run); wallcycle_reset_all(wcycle); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { reset_dd_statistics_counters(cr->dd); } diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index 429b91c6b1..3882768ada 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -1277,7 +1277,7 @@ void do_force(FILE* fplog, } const bool fillGrid = (stepWork.doNeighborSearch && stepWork.stateChanged); - const bool calcCGCM = (fillGrid && !DOMAINDECOMP(cr)); + const bool calcCGCM = (fillGrid && !haveDDAtomOrdering(*cr)); if (calcCGCM) { put_atoms_in_box_omp(fr->pbcType, @@ -1394,7 +1394,7 @@ void do_force(FILE* fplog, } wallcycle_start(wcycle, WallCycleCounter::NS); - if (!DOMAINDECOMP(cr)) + if (!haveDDAtomOrdering(*cr)) { const rvec vzero = { 0.0_real, 0.0_real, 0.0_real }; const rvec boxDiagonal = { box[XX][XX], box[YY][YY], box[ZZ][ZZ] }; @@ -1704,7 +1704,7 @@ void do_force(FILE* fplog, /* Reset energies */ reset_enerdata(enerd); - if (DOMAINDECOMP(cr) && simulationWork.haveSeparatePmeRank) + if (haveDDAtomOrdering(*cr) && simulationWork.haveSeparatePmeRank) { wallcycle_start(wcycle, WallCycleCounter::PpDuringPme); dd_force_flop_start(cr->dd, nrnb); @@ -1911,7 +1911,7 @@ void do_force(FILE* fplog, /* Since all atoms are in the rectangular or triclinic unit-cell, * only single box vector shifts (2 in x) are required. */ - set_pbc_dd(&pbc, fr->pbcType, DOMAINDECOMP(cr) ? cr->dd->numCells : nullptr, TRUE, box); + set_pbc_dd(&pbc, fr->pbcType, haveDDAtomOrdering(*cr) ? cr->dd->numCells : nullptr, TRUE, box); } for (int mtsIndex = 0; mtsIndex < (simulationWork.useMts && stepWork.computeSlowForces ? 2 : 1); @@ -1935,7 +1935,7 @@ void do_force(FILE* fplog, nrnb, lambda, mdatoms, - DOMAINDECOMP(cr) ? cr->dd->globalAtomIndices.data() : nullptr, + haveDDAtomOrdering(*cr) ? cr->dd->globalAtomIndices.data() : nullptr, stepWork); } } @@ -2197,7 +2197,7 @@ void do_force(FILE* fplog, enerd, stepWork, InteractionLocality::Local, - DOMAINDECOMP(cr) ? enbvClearFNo : enbvClearFYes, + haveDDAtomOrdering(*cr) ? enbvClearFNo : enbvClearFYes, step, nrnb, wcycle); @@ -2264,7 +2264,7 @@ void do_force(FILE* fplog, // NOTE: If there are virtual sites, the forces are modified on host after this D2H copy. Hence, // they should not be copied in do_md(...) for the output. if (!simulationWork.useGpuUpdate - || (simulationWork.useGpuUpdate && DOMAINDECOMP(cr) && simulationWork.useCpuPmePpCommunication) + || (simulationWork.useGpuUpdate && haveDDAtomOrdering(*cr) && simulationWork.useCpuPmePpCommunication) || vsite) { stateGpu->copyForcesFromGpu(forceWithShift, AtomLocality::Local); @@ -2281,7 +2281,7 @@ void do_force(FILE* fplog, launchGpuEndOfStepTasks( nbv, fr->listedForcesGpu.get(), fr->pmedata, enerd, *runScheduleWork, step, wcycle); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_force_flop_stop(cr->dd, nrnb); } diff --git a/src/gromacs/mdlib/simulationsignal.cpp b/src/gromacs/mdlib/simulationsignal.cpp index db0aec861c..fe0879e6d0 100644 --- a/src/gromacs/mdlib/simulationsignal.cpp +++ b/src/gromacs/mdlib/simulationsignal.cpp @@ -109,7 +109,7 @@ void SimulationSignaller::signalInterSim() // Communicate the signals between the simulations. gmx_sum_sim(eglsNR, mpiBuffer_.data(), ms_); } - if (DOMAINDECOMP(cr_)) + if (haveDDAtomOrdering(*cr_)) { // Communicate the signals from the master to the others. gmx_bcast(eglsNR * sizeof(mpiBuffer_[0]), mpiBuffer_.data(), cr_->mpi_comm_mygroup); diff --git a/src/gromacs/mdlib/update.cpp b/src/gromacs/mdlib/update.cpp index 7bcbc65687..800d68aa1d 100644 --- a/src/gromacs/mdlib/update.cpp +++ b/src/gromacs/mdlib/update.cpp @@ -1176,22 +1176,23 @@ static void do_update_sd(int start, } else { - doSDUpdateGeneral(sd, - start, - nrend, - dt, - nFreeze, - invmass, - ptype, - cFREEZE, - cTC, - x, - xprime, - v, - f, - step, - seed, - DOMAINDECOMP(cr) ? cr->dd->globalAtomIndices.data() : nullptr); + doSDUpdateGeneral( + sd, + start, + nrend, + dt, + nFreeze, + invmass, + ptype, + cFREEZE, + cTC, + x, + xprime, + v, + f, + step, + seed, + haveDDAtomOrdering(*cr) ? cr->dd->globalAtomIndices.data() : nullptr); } } @@ -1431,7 +1432,7 @@ void Update::Impl::update_sd_second_half(const t_inputrec& input nullptr, step, inputRecord.ld_seed, - DOMAINDECOMP(cr) ? cr->dd->globalAtomIndices.data() : nullptr); + haveDDAtomOrdering(*cr) ? cr->dd->globalAtomIndices.data() : nullptr); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR } @@ -1625,7 +1626,7 @@ void Update::Impl::update_coords(const t_inputrec& inputRecord, inputRecord.bd_fric, sd_.bd_rf.data(), inputRecord.ld_seed, - DOMAINDECOMP(cr) ? cr->dd->globalAtomIndices.data() : nullptr); + haveDDAtomOrdering(*cr) ? cr->dd->globalAtomIndices.data() : nullptr); break; case (IntegrationAlgorithm::VV): case (IntegrationAlgorithm::VVAK): diff --git a/src/gromacs/mdrun/md.cpp b/src/gromacs/mdrun/md.cpp index 3870f0fb92..7a649b7b4a 100644 --- a/src/gromacs/mdrun/md.cpp +++ b/src/gromacs/mdrun/md.cpp @@ -346,7 +346,7 @@ void gmx::LegacySimulator::do_md() top_global, constr ? constr->numFlexibleConstraints() : 0, ir->nstcalcenergy, - DOMAINDECOMP(cr), + haveDDAtomOrdering(*cr), useGpuForPme); { @@ -364,7 +364,7 @@ void gmx::LegacySimulator::do_md() ? PinningPolicy::PinnedIfSupported : PinningPolicy::CannotBePinned); const t_mdatoms* md = mdAtoms->mdatoms(); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { // Local state only becomes valid now. dd_init_local_state(*cr->dd, state_global, state); @@ -420,8 +420,8 @@ void gmx::LegacySimulator::do_md() // TODO: the assertions below should be handled by UpdateConstraintsBuilder. if (useGpuForUpdate) { - GMX_RELEASE_ASSERT(!DOMAINDECOMP(cr) || ddUsesUpdateGroups(*cr->dd) || constr == nullptr - || constr->numConstraintsTotal() == 0, + GMX_RELEASE_ASSERT(!haveDDAtomOrdering(*cr) || ddUsesUpdateGroups(*cr->dd) + || constr == nullptr || constr->numConstraintsTotal() == 0, "Constraints in domain decomposition are only supported with update " "groups if using GPU update.\n"); GMX_RELEASE_ASSERT(ir->eConstrAlg != ConstraintAlgorithm::Shake || constr == nullptr @@ -971,12 +971,12 @@ void gmx::LegacySimulator::do_md() } } } - if (DOMAINDECOMP(cr) && bMasterState) + if (haveDDAtomOrdering(*cr) && bMasterState) { dd_collect_state(cr->dd, state, state_global); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { /* Repartition the domain decomposition */ dd_partition_system(fplog, @@ -1492,7 +1492,7 @@ void gmx::LegacySimulator::do_md() { if (useGpuForUpdate) { - if (bNS && (bFirstStep || DOMAINDECOMP(cr))) + if (bNS && (bFirstStep || haveDDAtomOrdering(*cr))) { integrator->set(stateGpu->getCoordinates(), stateGpu->getVelocities(), @@ -1919,7 +1919,7 @@ void gmx::LegacySimulator::do_md() MASTER(cr) && mdrunOptions.verbose, bRerunMD); - if (bNeedRepartition && DOMAINDECOMP(cr)) + if (bNeedRepartition && haveDDAtomOrdering(*cr)) { dd_collect_state(cr->dd, state, state_global); } @@ -1932,7 +1932,7 @@ void gmx::LegacySimulator::do_md() bExchanged = replica_exchange(fplog, cr, ms, repl_ex, state_global, enerd, state, step, t); } - if ((bExchanged || bNeedRepartition) && DOMAINDECOMP(cr)) + if ((bExchanged || bNeedRepartition) && haveDDAtomOrdering(*cr)) { dd_partition_system(fplog, mdlog, @@ -1987,7 +1987,7 @@ void gmx::LegacySimulator::do_md() } cycles = wallcycle_stop(wcycle, WallCycleCounter::Step); - if (DOMAINDECOMP(cr) && wcycle) + if (haveDDAtomOrdering(*cr) && wcycle) { dd_cycles_add(cr->dd, cycles, ddCyclStep); } diff --git a/src/gromacs/mdrun/mimic.cpp b/src/gromacs/mdrun/mimic.cpp index 91b1d17940..82f4bf7465 100644 --- a/src/gromacs/mdrun/mimic.cpp +++ b/src/gromacs/mdrun/mimic.cpp @@ -218,7 +218,7 @@ void gmx::LegacySimulator::do_mimic() auto* nonConstInputrec = const_cast(inputrec); nonConstInputrec->nsteps = MimicCommunicator::getStepNumber(); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { // TODO: Avoid changing inputrec (#3854) auto* nonConstInputrec = const_cast(inputrec); @@ -273,7 +273,7 @@ void gmx::LegacySimulator::do_mimic() top_global, constr ? constr->numFlexibleConstraints() : 0, ir->nstcalcenergy, - DOMAINDECOMP(cr), + haveDDAtomOrdering(*cr), runScheduleWork->simulationWork.useGpuPme); { @@ -284,7 +284,7 @@ void gmx::LegacySimulator::do_mimic() } } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { // Local state only becomes valid now. dd_init_local_state(*cr->dd, state_global, state); @@ -447,7 +447,7 @@ void gmx::LegacySimulator::do_mimic() if (MASTER(cr)) { const bool constructVsites = ((vsite != nullptr) && mdrunOptions.rerunConstructVsites); - if (constructVsites && DOMAINDECOMP(cr)) + if (constructVsites && haveDDAtomOrdering(*cr)) { gmx_fatal(FARGS, "Vsite recalculation with -rerun is not implemented with domain " @@ -462,7 +462,7 @@ void gmx::LegacySimulator::do_mimic() } } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { /* Repartition the domain decomposition */ const bool bMasterState = true; @@ -653,7 +653,7 @@ void gmx::LegacySimulator::do_mimic() gmx::HostVector fglobal(top_global.natoms); gmx::ArrayRef ftemp; gmx::ArrayRef flocal = f.view().force(); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { ftemp = gmx::makeArrayRef(fglobal); dd_collect_vec(cr->dd, state->ddp_count, state->ddp_count_cg_gl, state->cg_gl, flocal, ftemp); @@ -744,7 +744,7 @@ void gmx::LegacySimulator::do_mimic() } cycles = wallcycle_stop(wcycle, WallCycleCounter::Step); - if (DOMAINDECOMP(cr) && wcycle) + if (haveDDAtomOrdering(*cr) && wcycle) { dd_cycles_add(cr->dd, cycles, ddCyclStep); } diff --git a/src/gromacs/mdrun/minimize.cpp b/src/gromacs/mdrun/minimize.cpp index 7513e11df3..e3ade12b7d 100644 --- a/src/gromacs/mdrun/minimize.cpp +++ b/src/gromacs/mdrun/minimize.cpp @@ -315,7 +315,7 @@ static void get_f_norm_max(const t_commrec* cr, } } - if (la_max >= 0 && DOMAINDECOMP(cr)) + if (la_max >= 0 && haveDDAtomOrdering(*cr)) { a_max = cr->dd->globalAtomIndices[la_max]; } @@ -414,7 +414,7 @@ static void init_em(FILE* fplog, top_global, constr ? constr->numFlexibleConstraints() : 0, ir->nstcalcenergy, - DOMAINDECOMP(cr), + haveDDAtomOrdering(*cr), thisRankHasDuty(cr, DUTY_PME)); } else @@ -432,7 +432,7 @@ static void init_em(FILE* fplog, } } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { // Local state only becomes valid now. dd_init_local_state(*cr->dd, state_global, &ems->s); @@ -596,7 +596,7 @@ static void write_em_traj(FILE* fplog, if (confout != nullptr) { - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { /* If bX=true, x was collected to state_global in the call above */ if (!bX) @@ -614,7 +614,7 @@ static void write_em_traj(FILE* fplog, if (MASTER(cr)) { - if (ir->pbcType != PbcType::No && !ir->bPeriodicMols && DOMAINDECOMP(cr)) + if (ir->pbcType != PbcType::No && !ir->bPeriodicMols && haveDDAtomOrdering(*cr)) { /* Make molecules whole only for confout writing */ do_pbc_mtop(ir->pbcType, state->s.box, &top_global, state_global->x.rvec_array()); @@ -655,7 +655,7 @@ static bool do_em_step(const t_commrec* cr, s1 = &ems1->s; s2 = &ems2->s; - if (DOMAINDECOMP(cr) && s1->ddp_count != cr->dd->ddp_count) + if (haveDDAtomOrdering(*cr) && s1->ddp_count != cr->dd->ddp_count) { gmx_incons("state mismatch in do_em_step"); } @@ -667,7 +667,7 @@ static bool do_em_step(const t_commrec* cr, state_change_natoms(s2, s1->natoms); ems2->f.resize(s2->natoms); } - if (DOMAINDECOMP(cr) && s2->cg_gl.size() != s1->cg_gl.size()) + if (haveDDAtomOrdering(*cr) && s2->cg_gl.size() != s1->cg_gl.size()) { s2->cg_gl.resize(s1->cg_gl.size()); } @@ -725,7 +725,7 @@ static bool do_em_step(const t_commrec* cr, } } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { /* OpenMP does not supported unsigned loop variables */ #pragma omp for schedule(static) nowait @@ -736,7 +736,7 @@ static bool do_em_step(const t_commrec* cr, } } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { s2->ddp_count = s1->ddp_count; s2->ddp_count_cg_gl = s1->ddp_count_cg_gl; @@ -967,7 +967,7 @@ void EnergyEvaluator::run(em_state_t* ems, rvec mu_tot, tensor vir, tensor pres, // Compute the buffer size of the pair list const real bufferSize = inputrec->rlist - std::max(inputrec->rcoulomb, inputrec->rvdw); - if (bFirst || bufferSize <= 0 || (DOMAINDECOMP(cr) && ems->s.ddp_count != ddpCountPairSearch)) + if (bFirst || bufferSize <= 0 || (haveDDAtomOrdering(*cr) && ems->s.ddp_count != ddpCountPairSearch)) { /* This is the first state or an old state used before the last ns */ bNS = TRUE; @@ -981,7 +981,7 @@ void EnergyEvaluator::run(em_state_t* ems, rvec mu_tot, tensor vir, tensor pres, > bufferSize; } - if (DOMAINDECOMP(cr) && bNS) + if (haveDDAtomOrdering(*cr) && bNS) { /* Repartition the domain decomposition */ em_dd_partition_system( @@ -1202,7 +1202,7 @@ static real pr_beta(const t_commrec* cr, * and might have to sum it in parallel runs. */ - if (!DOMAINDECOMP(cr) + if (!haveDDAtomOrdering(*cr) || (s_min->s.ddp_count == cr->dd->ddp_count && s_b->s.ddp_count == cr->dd->ddp_count)) { auto fm = s_min->f.view().force(); @@ -1548,7 +1548,7 @@ void LegacySimulator::do_cg() a = 0.0; c = a + stepsize; /* reference position along line is zero */ - if (DOMAINDECOMP(cr) && s_min->s.ddp_count < cr->dd->ddp_count) + if (haveDDAtomOrdering(*cr) && s_min->s.ddp_count < cr->dd->ddp_count) { em_dd_partition_system(fplog, mdlog, @@ -1663,7 +1663,7 @@ void LegacySimulator::do_cg() b = 0.5 * (a + c); } - if (DOMAINDECOMP(cr) && s_min->s.ddp_count != cr->dd->ddp_count) + if (haveDDAtomOrdering(*cr) && s_min->s.ddp_count != cr->dd->ddp_count) { /* Reload the old state */ em_dd_partition_system(fplog, @@ -1978,7 +1978,7 @@ void LegacySimulator::do_lbfgs() "be available in a different form in a future version of GROMACS, " "e.g. gmx minimize and an .mdp option."); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { gmx_fatal(FARGS, "L_BFGS is currently not supported"); } @@ -3017,7 +3017,7 @@ void LegacySimulator::do_steep() /* If energy is not smaller make the step smaller... */ ustep *= 0.5; - if (DOMAINDECOMP(cr) && s_min->s.ddp_count != cr->dd->ddp_count) + if (haveDDAtomOrdering(*cr) && s_min->s.ddp_count != cr->dd->ddp_count) { /* Reload the old state */ em_dd_partition_system(fplog, diff --git a/src/gromacs/mdrun/replicaexchange.cpp b/src/gromacs/mdrun/replicaexchange.cpp index 5ec63824c2..d569a3077c 100644 --- a/src/gromacs/mdrun/replicaexchange.cpp +++ b/src/gromacs/mdrun/replicaexchange.cpp @@ -235,7 +235,7 @@ gmx_repl_ex_t init_replica_exchange(FILE* fplog, * is true! * * Since we are using a dynamical integrator, the only - * decomposition is DD, so PAR(cr) and DOMAINDECOMP(cr) are + * decomposition is DD, so PAR(cr) and haveDDAtomOrdering(*cr) are * synonymous. The only way for cr->nnodes > 1 to be true is * if we are using DD. */ } @@ -1286,7 +1286,7 @@ gmx_bool replica_exchange(FILE* fplog, * each simulation know whether they need to participate in * collecting the state. Otherwise, they might as well get on with * the next thing to do. */ - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { #if GMX_MPI MPI_Bcast(&bThisReplicaExchanged, sizeof(gmx_bool), MPI_BYTE, MASTERRANK(cr), cr->mpi_comm_mygroup); @@ -1297,7 +1297,7 @@ gmx_bool replica_exchange(FILE* fplog, { /* Exchange the states */ /* Collect the global state on the master node */ - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_collect_state(cr->dd, state_local, state); } @@ -1338,7 +1338,7 @@ gmx_bool replica_exchange(FILE* fplog, } /* With domain decomposition the global state is distributed later */ - if (!DOMAINDECOMP(cr)) + if (!haveDDAtomOrdering(*cr)) { /* Copy the global state to the local state data structure */ copy_state_serial(state, state_local); diff --git a/src/gromacs/mdrun/rerun.cpp b/src/gromacs/mdrun/rerun.cpp index 48372cebfd..14eb21ffad 100644 --- a/src/gromacs/mdrun/rerun.cpp +++ b/src/gromacs/mdrun/rerun.cpp @@ -319,7 +319,7 @@ void gmx::LegacySimulator::do_rerun() top_global, constr ? constr->numFlexibleConstraints() : 0, ir->nstcalcenergy, - DOMAINDECOMP(cr), + haveDDAtomOrdering(*cr), runScheduleWork->simulationWork.useGpuPme); { @@ -330,7 +330,7 @@ void gmx::LegacySimulator::do_rerun() } } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { // Local state only becomes valid now. dd_init_local_state(*cr->dd, state_global, state); @@ -565,7 +565,7 @@ void gmx::LegacySimulator::do_rerun() if (MASTER(cr)) { const bool constructVsites = ((vsite != nullptr) && mdrunOptions.rerunConstructVsites); - if (constructVsites && DOMAINDECOMP(cr)) + if (constructVsites && haveDDAtomOrdering(*cr)) { gmx_fatal(FARGS, "Vsite recalculation with -rerun is not implemented with domain " @@ -577,7 +577,7 @@ void gmx::LegacySimulator::do_rerun() isLastStep = isLastStep || stopHandler->stoppingAfterCurrentStep(bNS); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { /* Repartition the domain decomposition */ const bool bMasterState = true; @@ -867,7 +867,7 @@ void gmx::LegacySimulator::do_rerun() } cycles = wallcycle_stop(wcycle, WallCycleCounter::Step); - if (DOMAINDECOMP(cr) && wcycle) + if (haveDDAtomOrdering(*cr) && wcycle) { dd_cycles_add(cr->dd, cycles, ddCyclStep); } diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index d409b82136..5daf1606ca 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -739,7 +739,7 @@ static void finish_run(FILE* fplog, print_flop(fplog, nrnb_tot, &nbfs, &mflop); } - if (thisRankHasDuty(cr, DUTY_PP) && DOMAINDECOMP(cr)) + if (thisRankHasDuty(cr, DUTY_PP) && haveDDAtomOrdering(*cr)) { print_dd_statistics(cr, inputrec, fplog); } @@ -1113,7 +1113,7 @@ int Mdrunner::mdrunner() globalState = std::make_unique(); } broadcastStateWithoutDynamics( - cr->mpiDefaultCommunicator, DOMAINDECOMP(cr), PAR(cr), globalState.get()); + cr->mpiDefaultCommunicator, haveDDAtomOrdering(*cr), PAR(cr), globalState.get()); } /* A parallel command line option consistency check that we can @@ -1595,7 +1595,7 @@ int Mdrunner::mdrunner() // Enable Peer access between GPUs where available // Only for DD, only master PP rank needs to perform setup, and only if thread MPI plus // any of the GPU communication features are active. - if (DOMAINDECOMP(cr) && MASTER(cr) && thisRankHasDuty(cr, DUTY_PP) && GMX_THREAD_MPI + if (haveDDAtomOrdering(*cr) && MASTER(cr) && thisRankHasDuty(cr, DUTY_PP) && GMX_THREAD_MPI && (runScheduleWork.simulationWork.useGpuHaloExchange || runScheduleWork.simulationWork.useGpuPmePpCommunication)) { @@ -1788,7 +1788,7 @@ int Mdrunner::mdrunner() } } // Make the DD reverse topology, now that any vsites that are present are available - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_make_reverse_top(fplog, cr->dd, mtop, vsite.get(), *inputrec, domdecOptions.ddBondedChecking); } @@ -2006,7 +2006,7 @@ int Mdrunner::mdrunner() mdrunOptions.imdOptions, startingBehavior); - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { GMX_RELEASE_ASSERT(fr, "fr was NULL while cr->duty was DUTY_PP"); /* This call is not included in init_domain_decomposition diff --git a/src/gromacs/mdrun/shellfc.cpp b/src/gromacs/mdrun/shellfc.cpp index 7f15b180bc..2f4c2d6e93 100644 --- a/src/gromacs/mdrun/shellfc.cpp +++ b/src/gromacs/mdrun/shellfc.cpp @@ -540,7 +540,7 @@ void gmx::make_local_shells(const t_commrec* cr, const t_mdatoms& md, gmx_shellf int a0, a1; gmx_domdec_t* dd = nullptr; - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd = cr->dd; a0 = 0; @@ -833,7 +833,7 @@ static void init_adir(gmx_shellfc_t* shfc, double dt, w_dt; int n, d; - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { n = dd_ac1; } @@ -983,7 +983,7 @@ void relax_shell_flexcon(FILE* fplog, ArrayRef shells = shfc->shells; const int nflexcon = shfc->nflexcon; - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { nat = dd_natoms_vsite(*cr->dd); if (nflexcon > 0) @@ -1019,7 +1019,7 @@ void relax_shell_flexcon(FILE* fplog, ArrayRef x = xPadded.unpaddedArrayRef(); ArrayRef v = vPadded.unpaddedArrayRef(); - if (bDoNS && inputrec->pbcType != PbcType::No && !DOMAINDECOMP(cr)) + if (bDoNS && inputrec->pbcType != PbcType::No && !haveDDAtomOrdering(*cr)) { /* This is the only time where the coordinates are used * before do_force is called, which normally puts all diff --git a/src/gromacs/mdtypes/commrec.h b/src/gromacs/mdtypes/commrec.h index 0307de3d5f..69ed6a2c9d 100644 --- a/src/gromacs/mdtypes/commrec.h +++ b/src/gromacs/mdtypes/commrec.h @@ -158,16 +158,22 @@ inline bool thisRankHasDuty(const t_commrec* cr, int duty) //! The node id for the master #define MASTERRANK(cr) (0) -/*! \brief Returns whether the domain decomposition machinery is active +/*! \brief Returns whether the domain decomposition machinery is active and reorders atoms + * + * This tells whether atoms are reordered at pair search steps. When the return value + * is true, atoms are not in the order of the input and mtop. * * Note that when the return value is true, there are not necessarily * multiple domains. The domain decomposition machinery is also active and * reorders the atoms also with a single MPI rank, or 1 PP and 1 PME rank, * with most integrators. Only a few special non-integrator "integrators" * do not (yet) support the domain decomposition machinery and therefore - * this macro is still needed. + * this function is still needed. */ -#define DOMAINDECOMP(cr) ((cr)->dd != nullptr) +static bool inline haveDDAtomOrdering(const t_commrec& cr) +{ + return cr.dd != nullptr; +} /*! \brief Returns whether we have actual domain decomposition for the particle-particle interactions * diff --git a/src/gromacs/modularsimulator/andersentemperaturecoupling.cpp b/src/gromacs/modularsimulator/andersentemperaturecoupling.cpp index cf5743bc40..5db8ff6141 100644 --- a/src/gromacs/modularsimulator/andersentemperaturecoupling.cpp +++ b/src/gromacs/modularsimulator/andersentemperaturecoupling.cpp @@ -100,7 +100,7 @@ void AndersenTemperatureCoupling::apply(Step step) UniformRealDistribution uniformDist; TabulatedNormalDistribution normalDist; - const bool doDomainDecomposition = DOMAINDECOMP(cr_); + const bool atomOrderingIsDD = haveDDAtomOrdering(*cr_); auto velocities = statePropagatorData_->velocitiesView().unpaddedArrayRef(); @@ -112,7 +112,7 @@ void AndersenTemperatureCoupling::apply(Step step) continue; } - const int globalAtomIdx = doDomainDecomposition ? cr_->dd->globalAtomIndices[atomIdx] : atomIdx; + const int globalAtomIdx = atomOrderingIsDD ? cr_->dd->globalAtomIndices[atomIdx] : atomIdx; rng.restart(step, globalAtomIdx); // For massive Andersen, this function is only called periodically, but we apply each time diff --git a/src/gromacs/modularsimulator/domdechelper.cpp b/src/gromacs/modularsimulator/domdechelper.cpp index 30d3d4ea15..4ee3524cc3 100644 --- a/src/gromacs/modularsimulator/domdechelper.cpp +++ b/src/gromacs/modularsimulator/domdechelper.cpp @@ -94,7 +94,8 @@ DomDecHelper::DomDecHelper(bool isVerbose, imdSession_(imdSession), pull_work_(pull_work) { - GMX_ASSERT(DOMAINDECOMP(cr), "Domain decomposition Helper constructed in non-DD simulation"); + GMX_ASSERT(haveDDAtomOrdering(*cr), + "Domain decomposition Helper constructed in non-DD simulation"); } void DomDecHelper::setup() diff --git a/src/gromacs/modularsimulator/expandedensembleelement.cpp b/src/gromacs/modularsimulator/expandedensembleelement.cpp index 17ec878ebc..5a76dbe67d 100644 --- a/src/gromacs/modularsimulator/expandedensembleelement.cpp +++ b/src/gromacs/modularsimulator/expandedensembleelement.cpp @@ -155,7 +155,7 @@ void ExpandedEnsembleElement::restoreCheckpointState(std::optional(&checkpointData.value()); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_distribute_dfhist(cr->dd, dfhist_.get()); } diff --git a/src/gromacs/modularsimulator/firstorderpressurecoupling.cpp b/src/gromacs/modularsimulator/firstorderpressurecoupling.cpp index ed9363d8ec..4499d6ed47 100644 --- a/src/gromacs/modularsimulator/firstorderpressurecoupling.cpp +++ b/src/gromacs/modularsimulator/firstorderpressurecoupling.cpp @@ -187,7 +187,7 @@ void FirstOrderPressureCoupling::restoreCheckpointState(std::optional(&checkpointData.value()); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_bcast(cr->dd, sizeof(conservedEnergyContribution_), &conservedEnergyContribution_); dd_bcast(cr->dd, sizeof(conservedEnergyContributionStep_), &conservedEnergyContributionStep_); diff --git a/src/gromacs/modularsimulator/forceelement.cpp b/src/gromacs/modularsimulator/forceelement.cpp index 3e4c0f414e..b41fdca27a 100644 --- a/src/gromacs/modularsimulator/forceelement.cpp +++ b/src/gromacs/modularsimulator/forceelement.cpp @@ -95,7 +95,7 @@ ForceElement::ForceElement(StatePropagatorData* statePropagatorData, globalTopology, constr ? constr->numFlexibleConstraints() : 0, inputrec->nstcalcenergy, - DOMAINDECOMP(cr), + haveDDAtomOrdering(*cr), runScheduleWork->simulationWork.useGpuPme)), doShellFC_(shellfc_ != nullptr), nextNSStep_(-1), @@ -137,7 +137,7 @@ ForceElement::ForceElement(StatePropagatorData* statePropagatorData, { std::fill(lambda_.begin(), lambda_.end(), 0); - if (doShellFC_ && !DOMAINDECOMP(cr)) + if (doShellFC_ && !haveDDAtomOrdering(*cr)) { // This was done in mdAlgorithmsSetupAtomData(), but shellfc // won't be available outside this element. @@ -178,7 +178,7 @@ void ForceElement::run(Step step, Time time, unsigned int flags) gmx_multisim_t* ms = nullptr; - if (!DOMAINDECOMP(cr_) && (flags & GMX_FORCE_NS) && inputrecDynamicBox(inputrec_)) + if (!haveDDAtomOrdering(*cr_) && (flags & GMX_FORCE_NS) && inputrecDynamicBox(inputrec_)) { // TODO: Correcting the box is done in DomDecHelper (if using DD) or here (non-DD simulations). // Think about unifying this responsibility, could this be done in one place? diff --git a/src/gromacs/modularsimulator/freeenergyperturbationdata.cpp b/src/gromacs/modularsimulator/freeenergyperturbationdata.cpp index 544660f577..ce268aac30 100644 --- a/src/gromacs/modularsimulator/freeenergyperturbationdata.cpp +++ b/src/gromacs/modularsimulator/freeenergyperturbationdata.cpp @@ -229,7 +229,7 @@ void FreeEnergyPerturbationData::Element::restoreCheckpointState(std::optional(&checkpointData.value()); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_bcast(cr->dd, sizeof(int), &freeEnergyPerturbationData_->currentFEPState_); dd_bcast(cr->dd, diff --git a/src/gromacs/modularsimulator/mttk.cpp b/src/gromacs/modularsimulator/mttk.cpp index 22517e5238..ba5f0c9219 100644 --- a/src/gromacs/modularsimulator/mttk.cpp +++ b/src/gromacs/modularsimulator/mttk.cpp @@ -79,7 +79,7 @@ void MttkData::build(LegacySimulatorData* legacySimulatorData // When using domain decomposition, statePropagatorData might not have the initial // box yet, so we get it from the legacy state_global instead. // TODO: Make sure we have a valid state in statePropagatorData at all times (#3421) - if (DOMAINDECOMP(legacySimulatorData->cr)) + if (haveDDAtomOrdering(*legacySimulatorData->cr)) { if (MASTER(legacySimulatorData->cr)) { @@ -307,7 +307,7 @@ void MttkData::restoreCheckpointState(std::optional checkpoi { doCheckpointData(&checkpointData.value()); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_bcast(cr->dd, int(sizeof(real)), &etaVelocity_); dd_bcast(cr->dd, int(sizeof(real)), &invMass_); diff --git a/src/gromacs/modularsimulator/nosehooverchains.cpp b/src/gromacs/modularsimulator/nosehooverchains.cpp index 60826edc88..3abb8028f8 100644 --- a/src/gromacs/modularsimulator/nosehooverchains.cpp +++ b/src/gromacs/modularsimulator/nosehooverchains.cpp @@ -429,7 +429,7 @@ void NoseHooverChainsData::restoreCheckpointState(std::optionaldd); } diff --git a/src/gromacs/modularsimulator/parrinellorahmanbarostat.cpp b/src/gromacs/modularsimulator/parrinellorahmanbarostat.cpp index d38f669fb5..2f10b3285e 100644 --- a/src/gromacs/modularsimulator/parrinellorahmanbarostat.cpp +++ b/src/gromacs/modularsimulator/parrinellorahmanbarostat.cpp @@ -303,7 +303,7 @@ void ParrinelloRahmanBarostat::restoreCheckpointState(std::optional(&checkpointData.value()); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_bcast(cr->dd, sizeof(boxVelocity_), boxVelocity_); dd_bcast(cr->dd, sizeof(boxRel_), boxRel_); diff --git a/src/gromacs/modularsimulator/simulatoralgorithm.cpp b/src/gromacs/modularsimulator/simulatoralgorithm.cpp index 2d127f41ef..5d07cc83aa 100644 --- a/src/gromacs/modularsimulator/simulatoralgorithm.cpp +++ b/src/gromacs/modularsimulator/simulatoralgorithm.cpp @@ -303,7 +303,7 @@ void ModularSimulatorAlgorithm::postStep(Step step, Time gmx_unused time) } double cycles = wallcycle_stop(wcycle, WallCycleCounter::Step); - if (DOMAINDECOMP(cr) && wcycle) + if (haveDDAtomOrdering(*cr) && wcycle) { dd_cycles_add(cr->dd, static_cast(cycles), ddCyclStep); } @@ -588,7 +588,7 @@ ModularSimulatorAlgorithm ModularSimulatorAlgorithmBuilder::build() registerWithInfrastructureAndSignallers(trajectoryElement.get()); // Build domdec helper (free energy element is a client, so keep this after it is built) - if (DOMAINDECOMP(legacySimulatorData_->cr)) + if (haveDDAtomOrdering(*legacySimulatorData_->cr)) { algorithm.domDecHelper_ = domDecHelperBuilder_.build(legacySimulatorData_->mdrunOptions.verbose, diff --git a/src/gromacs/modularsimulator/statepropagatordata.cpp b/src/gromacs/modularsimulator/statepropagatordata.cpp index c57ec7c061..b19ca468bb 100644 --- a/src/gromacs/modularsimulator/statepropagatordata.cpp +++ b/src/gromacs/modularsimulator/statepropagatordata.cpp @@ -179,7 +179,7 @@ StatePropagatorData::StatePropagatorData(int numAtoms, { bool stateHasVelocities; // Local state only becomes valid now. - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_init_local_state(*cr->dd, globalState, localState); stateHasVelocities = ((localState->flags & enumValueToBitMask(StateEntry::V)) != 0); @@ -203,7 +203,7 @@ StatePropagatorData::StatePropagatorData(int numAtoms, changePinningPolicy(&x_, gmx::PinningPolicy::PinnedIfSupported); } - if (DOMAINDECOMP(cr) && MASTER(cr)) + if (haveDDAtomOrdering(*cr) && MASTER(cr)) { xGlobal_.resizeWithPadding(totalNumAtoms_); previousXGlobal_.resizeWithPadding(totalNumAtoms_); @@ -605,7 +605,7 @@ void StatePropagatorData::doCheckpointData(CheckpointData* checkpoint void StatePropagatorData::Element::saveCheckpointState(std::optional checkpointData, const t_commrec* cr) { - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { // Collect state from all ranks into global vectors dd_collect_vec(cr->dd, @@ -670,7 +670,7 @@ void StatePropagatorData::Element::restoreCheckpointState(std::optionalglobalState_, statePropagatorData_->xGlobal_, @@ -681,7 +681,7 @@ void StatePropagatorData::Element::restoreCheckpointState(std::optionalcgGl_); } // Everything is local - copy global vectors to local ones - if (!DOMAINDECOMP(cr)) + if (!haveDDAtomOrdering(*cr)) { statePropagatorData_->x_.resizeWithPadding(statePropagatorData_->totalNumAtoms_); statePropagatorData_->v_.resizeWithPadding(statePropagatorData_->totalNumAtoms_); @@ -712,7 +712,7 @@ void StatePropagatorData::Element::trajectoryWriterTeardown(gmx_mdoutf* gmx_unus GMX_ASSERT(localStateBackupValid_, "Final trajectory writing called, but no state saved."); wallcycle_start(mdoutf_get_wcycle(outf), WallCycleCounter::Traj); - if (DOMAINDECOMP(cr_)) + if (haveDDAtomOrdering(*cr_)) { auto globalXRef = MASTER(cr_) ? statePropagatorData_->globalState_->x : gmx::ArrayRef(); diff --git a/src/gromacs/modularsimulator/topologyholder.cpp b/src/gromacs/modularsimulator/topologyholder.cpp index d697a2c96b..d96fea554d 100644 --- a/src/gromacs/modularsimulator/topologyholder.cpp +++ b/src/gromacs/modularsimulator/topologyholder.cpp @@ -61,7 +61,7 @@ TopologyHolder::TopologyHolder(std::vector clients, VirtualSitesHandler* vsite) : globalTopology_(globalTopology), localTopology_(localTopology), clients_(std::move(clients)) { - if (!DOMAINDECOMP(cr)) + if (!haveDDAtomOrdering(*cr)) { // Generate and initialize new topology // Note that most of the data needed for the constructor is used here - diff --git a/src/gromacs/modularsimulator/velocityscalingtemperaturecoupling.cpp b/src/gromacs/modularsimulator/velocityscalingtemperaturecoupling.cpp index 47df3fc82a..5caeafae33 100644 --- a/src/gromacs/modularsimulator/velocityscalingtemperaturecoupling.cpp +++ b/src/gromacs/modularsimulator/velocityscalingtemperaturecoupling.cpp @@ -452,7 +452,7 @@ public: { doCheckpointData(&checkpointData.value()); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_bcast(cr->dd, xi_.size() * sizeof(real), xi_.data()); dd_bcast(cr->dd, xiVelocities_.size() * sizeof(real), xiVelocities_.data()); @@ -702,7 +702,7 @@ void VelocityScalingTemperatureCoupling::restoreCheckpointState(std::optional(&checkpointData.value()); } - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { dd_bcast(cr->dd, ssize(temperatureCouplingIntegral_) * int(sizeof(double)), diff --git a/src/gromacs/nbnxm/nbnxm_setup.cpp b/src/gromacs/nbnxm/nbnxm_setup.cpp index 42e3511853..b279596730 100644 --- a/src/gromacs/nbnxm/nbnxm_setup.cpp +++ b/src/gromacs/nbnxm/nbnxm_setup.cpp @@ -223,7 +223,7 @@ const char* lookup_kernel_name(const KernelType kernelType) case KernelType::Cpu4xN_Simd_2xNN: #if GMX_SIMD return "SIMD"; -#else // GMX_SIMD +#else // GMX_SIMD return "not available"; #endif // GMX_SIMD case KernelType::Gpu8x8x8: return "GPU"; @@ -458,15 +458,15 @@ std::unique_ptr init_nb_verlet(const gmx::MDLogger& mdlog, auto pairlistSets = std::make_unique( pairlistParams, haveMultipleDomains, minimumIlistCountForGpuBalancing); - auto pairSearch = - std::make_unique(inputrec.pbcType, - EI_TPI(inputrec.eI), - DOMAINDECOMP(commrec) ? &commrec->dd->numCells : nullptr, - DOMAINDECOMP(commrec) ? domdec_zones(commrec->dd) : nullptr, - pairlistParams.pairlistType, - bFEP_NonBonded, - gmx_omp_nthreads_get(ModuleMultiThread::Pairsearch), - pinPolicy); + auto pairSearch = std::make_unique( + inputrec.pbcType, + EI_TPI(inputrec.eI), + haveDDAtomOrdering(*commrec) ? &commrec->dd->numCells : nullptr, + haveDDAtomOrdering(*commrec) ? domdec_zones(commrec->dd) : nullptr, + pairlistParams.pairlistType, + bFEP_NonBonded, + gmx_omp_nthreads_get(ModuleMultiThread::Pairsearch), + pinPolicy); return std::make_unique( std::move(pairlistSets), std::move(pairSearch), std::move(nbat), kernelSetup, gpu_nbv, wcycle); diff --git a/src/gromacs/nbnxm/pairlist_tuning.cpp b/src/gromacs/nbnxm/pairlist_tuning.cpp index 48f409254a..548a0747b2 100644 --- a/src/gromacs/nbnxm/pairlist_tuning.cpp +++ b/src/gromacs/nbnxm/pairlist_tuning.cpp @@ -280,12 +280,12 @@ void increaseNstlist(FILE* fp, /* Does rlist fit in the box? */ bBox = (gmx::square(rlist_new) < max_cutoff2(ir->pbcType, box)); bDD = true; - if (bBox && DOMAINDECOMP(cr)) + if (bBox && haveDDAtomOrdering(*cr)) { /* Currently (as of July 2020), the code in this if clause is never executed. * increaseNstlist(...) is only called from prepare_verlet_scheme, which in turns - * gets called by the runner _before_ setting up DD. DOMAINDECOMP(cr) will therefore - * always be false here. See #3334. + * gets called by the runner _before_ setting up DD. haveDDAtomOrdering(*cr) will + * therefore always be false here. See #3334. */ /* Check if rlist fits in the domain decomposition */ if (inputrec2nboundeddim(ir) < DIM) diff --git a/src/gromacs/pulling/pull.cpp b/src/gromacs/pulling/pull.cpp index 106861bb68..cbef32a402 100644 --- a/src/gromacs/pulling/pull.cpp +++ b/src/gromacs/pulling/pull.cpp @@ -2048,7 +2048,7 @@ struct pull_t* init_pull(FILE* fplog, maxNumThreads); } - if (cr != nullptr && DOMAINDECOMP(cr)) + if (cr != nullptr && haveDDAtomOrdering(*cr)) { /* Set up the global to local atom mapping for PBC atoms */ for (pull_group_work_t& group : pull->group) @@ -2398,7 +2398,7 @@ struct pull_t* init_pull(FILE* fplog, * when we have an external pull potential, since then the external * potential provider expects each rank to have the coordinate. */ - comm->bParticipateAll = (cr == nullptr || !DOMAINDECOMP(cr) || cr->dd->nnodes <= 32 + comm->bParticipateAll = (cr == nullptr || !haveDDAtomOrdering(*cr) || cr->dd->nnodes <= 32 || pull->numCoordinatesWithExternalPotential > 0 || getenv("GMX_PULL_PARTICIPATE_ALL") != nullptr); /* This sub-commicator is not used with comm->bParticipateAll, diff --git a/src/gromacs/pulling/pull_rotation.cpp b/src/gromacs/pulling/pull_rotation.cpp index 325c3f65b9..bcea9f3db1 100644 --- a/src/gromacs/pulling/pull_rotation.cpp +++ b/src/gromacs/pulling/pull_rotation.cpp @@ -3980,7 +3980,7 @@ void do_rotation(const t_commrec* cr, /**************************************************************************/ /* Done communicating, we can start to count cycles for the load balancing now ... */ - if (DOMAINDECOMP(cr)) + if (haveDDAtomOrdering(*cr)) { ddReopenBalanceRegionCpu(cr->dd); } diff --git a/src/gromacs/pulling/pullutil.cpp b/src/gromacs/pulling/pullutil.cpp index b4cf5f3c0f..cf7a9778ec 100644 --- a/src/gromacs/pulling/pullutil.cpp +++ b/src/gromacs/pulling/pullutil.cpp @@ -542,7 +542,7 @@ void pull_calc_coms(const t_commrec* cr, { pull_set_pbcatoms(cr, pull, x, comm->pbcAtomBuffer); - if (cr != nullptr && DOMAINDECOMP(cr)) + if (cr != nullptr && haveDDAtomOrdering(*cr)) { /* We can keep these PBC reference coordinates fixed for nstlist * steps, since atoms won't jump over PBC. diff --git a/src/gromacs/restraint/restraintmdmodule.cpp b/src/gromacs/restraint/restraintmdmodule.cpp index bc4233cba3..4e988dbd33 100644 --- a/src/gromacs/restraint/restraintmdmodule.cpp +++ b/src/gromacs/restraint/restraintmdmodule.cpp @@ -115,7 +115,7 @@ void RestraintForceProvider::calculateForces(const ForceProviderInput& forceProv } // All ranks wait for the update to finish. // tMPI ranks are depending on structures that may have just been updated. - if (DOMAINDECOMP(&cr)) + if (haveDDAtomOrdering(cr)) { // Note: this assumes that all ranks are hitting this line, which is not generally true. // I need to find the right subcommunicator. What I really want is a _scoped_ communicator... diff --git a/src/gromacs/restraint/restraintmdmodule_impl.h b/src/gromacs/restraint/restraintmdmodule_impl.h index 8cfab33f45..bc22320e5a 100644 --- a/src/gromacs/restraint/restraintmdmodule_impl.h +++ b/src/gromacs/restraint/restraintmdmodule_impl.h @@ -132,7 +132,7 @@ public: // Center of mass to return for the site. Currently the only form of site // implemented is as a global atomic coordinate. gmx::RVec r = { 0, 0, 0 }; - if (DOMAINDECOMP(&cr)) // Domain decomposition + if (haveDDAtomOrdering(cr)) // Domain decomposition { // Get global-to-local indexing structure auto* crossRef = cr.dd->ga2la; diff --git a/src/gromacs/swap/swapcoords.cpp b/src/gromacs/swap/swapcoords.cpp index 172d4024a0..e8213aa095 100644 --- a/src/gromacs/swap/swapcoords.cpp +++ b/src/gromacs/swap/swapcoords.cpp @@ -1555,7 +1555,7 @@ t_swap* init_swapcoords(FILE* fplog, swapstateIons_t* gs; swaphistory_t* swapstate = nullptr; - if ((PAR(cr)) && !DOMAINDECOMP(cr)) + if ((PAR(cr)) && !haveDDAtomOrdering(*cr)) { gmx_fatal(FARGS, "Position swapping is only implemented for domain decomposition!"); } -- 2.22.0