From 0214184a379f8f7be655222295e96cd872142973 Mon Sep 17 00:00:00 2001 From: Joe Jordan Date: Mon, 12 Apr 2021 18:18:53 +0000 Subject: [PATCH] Pass cFREEZE and cTC to update after DD partitioning --- src/gromacs/mdlib/tests/leapfrogtestdata.cpp | 4 +- src/gromacs/mdlib/update.cpp | 113 +++++++++---------- src/gromacs/mdlib/update.h | 8 +- src/gromacs/mdrun/md.cpp | 27 ++++- 4 files changed, 84 insertions(+), 68 deletions(-) diff --git a/src/gromacs/mdlib/tests/leapfrogtestdata.cpp b/src/gromacs/mdlib/tests/leapfrogtestdata.cpp index c00fbbd4c0..9d1f7780be 100644 --- a/src/gromacs/mdlib/tests/leapfrogtestdata.cpp +++ b/src/gromacs/mdlib/tests/leapfrogtestdata.cpp @@ -172,7 +172,9 @@ LeapFrogTestData::LeapFrogTestData(int numAtoms, mdAtoms_.cFREEZE = nullptr; update_ = std::make_unique(inputRecord_, nullptr); - update_->setNumAtoms(numAtoms); + update_->updateAfterPartition(numAtoms, + gmx::ArrayRef(), + gmx::arrayRefFromArray(mdAtoms_.cTC, mdAtoms_.nr)); doPressureCouple_ = (nstpcouple != 0); diff --git a/src/gromacs/mdlib/update.cpp b/src/gromacs/mdlib/update.cpp index 1ad97b2c5e..14f03826ed 100644 --- a/src/gromacs/mdlib/update.cpp +++ b/src/gromacs/mdlib/update.cpp @@ -125,8 +125,6 @@ public: int homenr, bool havePartiallyFrozenAtoms, gmx::ArrayRef ptype, - gmx::ArrayRef cFREEZE, - gmx::ArrayRef cTC, gmx::ArrayRef invMass, gmx::ArrayRef invMassPerDim, t_state* state, @@ -144,21 +142,19 @@ public: gmx_wallcycle_t wcycle, bool haveConstraints); - void update_sd_second_half(const t_inputrec& inputRecord, - int64_t step, - real* dvdlambda, - int homenr, - gmx::ArrayRef ptype, - gmx::ArrayRef cFREEZE, - gmx::ArrayRef cTC, - gmx::ArrayRef invMass, - t_state* state, - const t_commrec* cr, - t_nrnb* nrnb, - gmx_wallcycle_t wcycle, - gmx::Constraints* constr, - bool do_log, - bool do_ene); + void update_sd_second_half(const t_inputrec& inputRecord, + int64_t step, + real* dvdlambda, + int homenr, + gmx::ArrayRef ptype, + gmx::ArrayRef invMass, + t_state* state, + const t_commrec* cr, + t_nrnb* nrnb, + gmx_wallcycle_t wcycle, + gmx::Constraints* constr, + bool do_log, + bool do_ene); void update_for_constraint_virial(const t_inputrec& inputRecord, int homenr, @@ -179,6 +175,11 @@ public: BoxDeformation* deform() const { return deform_; } + //! Group index for freezing + gmx::ArrayRef cFREEZE_; + //! Group index for temperature coupling + gmx::ArrayRef cTC_; + private: //! stochastic dynamics struct gmx_stochd_t sd_; @@ -230,10 +231,6 @@ void Update::update_coords(const t_inputrec& inpu md->homenr, md->havePartiallyFrozenAtoms, gmx::arrayRefFromArray(md->ptype, md->nr), - md->cFREEZE ? gmx::arrayRefFromArray(md->cFREEZE, md->nr) - : gmx::ArrayRef(), - md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr) - : gmx::ArrayRef(), gmx::arrayRefFromArray(md->invmass, md->nr), gmx::arrayRefFromArray(md->invMassPerDim, md->nr), state, @@ -272,10 +269,6 @@ void Update::update_sd_second_half(const t_inputrec& inputRecord, dvdlambda, md->homenr, gmx::arrayRefFromArray(md->ptype, md->nr), - md->cFREEZE ? gmx::arrayRefFromArray(md->cFREEZE, md->nr) - : gmx::ArrayRef(), - md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr) - : gmx::ArrayRef(), gmx::arrayRefFromArray(md->invmass, md->nr), state, cr, @@ -1026,10 +1019,14 @@ Update::Impl::Impl(const t_inputrec& inputRecord, BoxDeformation* boxDeformation xp_.resizeWithPadding(0); } -void Update::setNumAtoms(int numAtoms) +void Update::updateAfterPartition(int numAtoms, + gmx::ArrayRef cFREEZE, + gmx::ArrayRef cTC) { impl_->xp()->resizeWithPadding(numAtoms); + impl_->cFREEZE_ = cFREEZE; + impl_->cTC_ = cTC; } /*! \brief Sets the SD update type */ @@ -1388,21 +1385,19 @@ void getThreadAtomRange(int numThreads, int threadIndex, int numAtoms, int* star } } -void Update::Impl::update_sd_second_half(const t_inputrec& inputRecord, - int64_t step, - real* dvdlambda, - int homenr, - gmx::ArrayRef ptype, - gmx::ArrayRef cFREEZE, - gmx::ArrayRef cTC, - gmx::ArrayRef invMass, - t_state* state, - const t_commrec* cr, - t_nrnb* nrnb, - gmx_wallcycle_t wcycle, - gmx::Constraints* constr, - bool do_log, - bool do_ene) +void Update::Impl::update_sd_second_half(const t_inputrec& inputRecord, + int64_t step, + real* dvdlambda, + int homenr, + gmx::ArrayRef ptype, + gmx::ArrayRef invMass, + t_state* state, + const t_commrec* cr, + t_nrnb* nrnb, + gmx_wallcycle_t wcycle, + gmx::Constraints* constr, + bool do_log, + bool do_ene) { if (!constr) { @@ -1440,8 +1435,8 @@ void Update::Impl::update_sd_second_half(const t_inputrec& inp gmx::arrayRefFromArray(inputRecord.opts.nFreeze, inputRecord.opts.ngfrz), invMass, ptype, - cFREEZE, - cTC, + cFREEZE_, + cTC_, state->x.rvec_array(), xp_.rvec_array(), state->v.rvec_array(), @@ -1529,16 +1524,14 @@ void Update::Impl::finish_update(const t_inputrec& inputRecord, wallcycle_stop(wcycle, ewcUPDATE); } -void Update::Impl::update_coords(const t_inputrec& inputRecord, - int64_t step, - int homenr, - bool havePartiallyFrozenAtoms, - gmx::ArrayRef ptype, - gmx::ArrayRef cFREEZE, - gmx::ArrayRef cTC, - gmx::ArrayRef invMass, - gmx::ArrayRef invMassPerDim, - t_state* state, +void Update::Impl::update_coords(const t_inputrec& inputRecord, + int64_t step, + int homenr, + bool havePartiallyFrozenAtoms, + gmx::ArrayRef ptype, + gmx::ArrayRef invMass, + gmx::ArrayRef invMassPerDim, + t_state* state, const gmx::ArrayRefWithPadding& f, const t_fcdata& fcdata, const gmx_ekindata_t* ekind, @@ -1597,7 +1590,7 @@ void Update::Impl::update_coords(const t_inputrec& inputRecord inputRecord.epc, inputRecord.nsttcouple, inputRecord.nstpcouple, - cTC, + cTC_, invMass, invMassPerDim, ekind, @@ -1618,8 +1611,8 @@ void Update::Impl::update_coords(const t_inputrec& inputRecord gmx::arrayRefFromArray(inputRecord.opts.nFreeze, inputRecord.opts.ngfrz), invMass, ptype, - cFREEZE, - cTC, + cFREEZE_, + cTC_, inputRecord.ld_seed, cr, sd_, @@ -1637,8 +1630,8 @@ void Update::Impl::update_coords(const t_inputrec& inputRecord gmx::arrayRefFromArray(inputRecord.opts.nFreeze, inputRecord.opts.ngfrz), invMass, ptype, - cFREEZE, - cTC, + cFREEZE_, + cTC_, inputRecord.bd_fric, sd_.bd_rf.data(), inputRecord.ld_seed, @@ -1664,7 +1657,7 @@ void Update::Impl::update_coords(const t_inputrec& inputRecord inputRecord.opts.ngfrz), invMass, ptype, - cFREEZE, + cFREEZE_, v_rvec, f_rvec, bExtended, @@ -1678,7 +1671,7 @@ void Update::Impl::update_coords(const t_inputrec& inputRecord gmx::arrayRefFromArray(inputRecord.opts.nFreeze, inputRecord.opts.ngfrz), ptype, - cFREEZE, + cFREEZE_, x_rvec, xp_rvec, v_rvec, diff --git a/src/gromacs/mdlib/update.h b/src/gromacs/mdlib/update.h index 1e7a5d530f..10a93faa51 100644 --- a/src/gromacs/mdlib/update.h +++ b/src/gromacs/mdlib/update.h @@ -93,11 +93,15 @@ public: * \returns handle to box deformation class */ BoxDeformation* deform() const; - /*! \brief Resizes buffer that stores intermediate coordinates. + /*! \brief Sets data that changes only at domain decomposition time. * * \param[in] numAtoms Updated number of atoms. + * \param[in] cFREEZE Group index for freezing + * \param[in] cTC Group index for center of mass motion removal */ - void setNumAtoms(int numAtoms); + void updateAfterPartition(int numAtoms, + gmx::ArrayRef cFREEZE, + gmx::ArrayRef cTC); /*! \brief Perform numerical integration step. * diff --git a/src/gromacs/mdrun/md.cpp b/src/gromacs/mdrun/md.cpp index 7ac685d7f2..e398e7693e 100644 --- a/src/gromacs/mdrun/md.cpp +++ b/src/gromacs/mdrun/md.cpp @@ -358,10 +358,11 @@ void gmx::LegacySimulator::do_md() auto mdatoms = mdAtoms->mdatoms(); - ForceBuffers f(fr->useMts, + ForceBuffers f(fr->useMts, ((useGpuForNonbonded && useGpuForBufferOps) || useGpuForUpdate) ? PinningPolicy::PinnedIfSupported : PinningPolicy::CannotBePinned); + const t_mdatoms* md = mdAtoms->mdatoms(); if (DOMAINDECOMP(cr)) { stateInstance = std::make_unique(); @@ -390,7 +391,11 @@ void gmx::LegacySimulator::do_md() nrnb, nullptr, FALSE); - upd.setNumAtoms(state->natoms); + upd.updateAfterPartition(state->natoms, + md->cFREEZE ? gmx::arrayRefFromArray(md->cFREEZE, md->nr) + : gmx::ArrayRef(), + md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr) + : gmx::ArrayRef()); } else { @@ -401,7 +406,11 @@ void gmx::LegacySimulator::do_md() /* Generate and initialize new topology */ mdAlgorithmsSetupAtomData(cr, *ir, top_global, &top, fr, &f, mdAtoms, constr, vsite, shellfc); - upd.setNumAtoms(state->natoms); + upd.updateAfterPartition(state->natoms, + md->cFREEZE ? gmx::arrayRefFromArray(md->cFREEZE, md->nr) + : gmx::ArrayRef(), + md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr) + : gmx::ArrayRef()); } std::unique_ptr integrator; @@ -1009,7 +1018,11 @@ void gmx::LegacySimulator::do_md() nrnb, wcycle, do_verbose && !bPMETunePrinting); - upd.setNumAtoms(state->natoms); + upd.updateAfterPartition(state->natoms, + md->cFREEZE ? gmx::arrayRefFromArray(md->cFREEZE, md->nr) + : gmx::ArrayRef(), + md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr) + : gmx::ArrayRef()); } } @@ -1891,7 +1904,11 @@ void gmx::LegacySimulator::do_md() nrnb, wcycle, FALSE); - upd.setNumAtoms(state->natoms); + upd.updateAfterPartition(state->natoms, + md->cFREEZE ? gmx::arrayRefFromArray(md->cFREEZE, md->nr) + : gmx::ArrayRef(), + md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr) + : gmx::ArrayRef()); } bFirstStep = FALSE; -- 2.22.0