Pass cFREEZE and cTC to update after DD partitioning
authorJoe Jordan <ejjordan12@gmail.com>
Mon, 12 Apr 2021 18:18:53 +0000 (18:18 +0000)
committerPascal Merz <pascal.merz@me.com>
Mon, 12 Apr 2021 18:18:53 +0000 (18:18 +0000)
src/gromacs/mdlib/tests/leapfrogtestdata.cpp
src/gromacs/mdlib/update.cpp
src/gromacs/mdlib/update.h
src/gromacs/mdrun/md.cpp

index c00fbbd4c001e0aa4bae2419286fddcf215a931f..9d1f7780be68a05a173877aad803ecd15881f374 100644 (file)
@@ -172,7 +172,9 @@ LeapFrogTestData::LeapFrogTestData(int        numAtoms,
     mdAtoms_.cFREEZE                  = nullptr;
 
     update_ = std::make_unique<Update>(inputRecord_, nullptr);
-    update_->setNumAtoms(numAtoms);
+    update_->updateAfterPartition(numAtoms,
+                                  gmx::ArrayRef<const unsigned short>(),
+                                  gmx::arrayRefFromArray(mdAtoms_.cTC, mdAtoms_.nr));
 
     doPressureCouple_ = (nstpcouple != 0);
 
index 1ad97b2c5e9106d2d701f1c4dac71de68c37c17b..14f03826edd06cbd0d758faa22887f166ca775e5 100644 (file)
@@ -125,8 +125,6 @@ public:
                        int                                              homenr,
                        bool                                             havePartiallyFrozenAtoms,
                        gmx::ArrayRef<const ParticleType>                ptype,
-                       gmx::ArrayRef<const unsigned short>              cFREEZE,
-                       gmx::ArrayRef<const unsigned short>              cTC,
                        gmx::ArrayRef<const real>                        invMass,
                        gmx::ArrayRef<rvec>                              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<const ParticleType>   ptype,
-                               gmx::ArrayRef<const unsigned short> cFREEZE,
-                               gmx::ArrayRef<const unsigned short> cTC,
-                               gmx::ArrayRef<const real>           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<const ParticleType> ptype,
+                               gmx::ArrayRef<const real>         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<const unsigned short> cFREEZE_;
+    //! Group index for temperature coupling
+    gmx::ArrayRef<const unsigned short> 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<const unsigned short>(),
-                                md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr)
-                                        : gmx::ArrayRef<const unsigned short>(),
                                 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<const unsigned short>(),
-                                        md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr)
-                                                : gmx::ArrayRef<const unsigned short>(),
                                         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<const unsigned short> cFREEZE,
+                                  gmx::ArrayRef<const unsigned short> 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<const ParticleType>   ptype,
-                                         gmx::ArrayRef<const unsigned short> cFREEZE,
-                                         gmx::ArrayRef<const unsigned short> cTC,
-                                         gmx::ArrayRef<const real>           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<const ParticleType> ptype,
+                                         gmx::ArrayRef<const real>         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<const ParticleType>   ptype,
-                                 gmx::ArrayRef<const unsigned short> cFREEZE,
-                                 gmx::ArrayRef<const unsigned short> cTC,
-                                 gmx::ArrayRef<const real>           invMass,
-                                 gmx::ArrayRef<rvec>                 invMassPerDim,
-                                 t_state*                            state,
+void Update::Impl::update_coords(const t_inputrec&                 inputRecord,
+                                 int64_t                           step,
+                                 int                               homenr,
+                                 bool                              havePartiallyFrozenAtoms,
+                                 gmx::ArrayRef<const ParticleType> ptype,
+                                 gmx::ArrayRef<const real>         invMass,
+                                 gmx::ArrayRef<rvec>               invMassPerDim,
+                                 t_state*                          state,
                                  const gmx::ArrayRefWithPadding<const gmx::RVec>& 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,
index 1e7a5d530ff9559b561f73a776fbc7f2b2d2d938..10a93faa51871728db8f856be1f8f56326e0b88a 100644 (file)
@@ -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<const unsigned short> cFREEZE,
+                              gmx::ArrayRef<const unsigned short> cTC);
 
     /*! \brief Perform numerical integration step.
      *
index 7ac685d7f2fd5e6c8c92cda4cc538d9c4721ae2a..e398e7693ee77aef4699e453d981c6340636751a 100644 (file)
@@ -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<t_state>();
@@ -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<const unsigned short>(),
+                                 md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr)
+                                         : gmx::ArrayRef<const unsigned short>());
     }
     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<const unsigned short>(),
+                                 md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr)
+                                         : gmx::ArrayRef<const unsigned short>());
     }
 
     std::unique_ptr<UpdateConstrainGpu> 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<const unsigned short>(),
+                                         md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr)
+                                                 : gmx::ArrayRef<const unsigned short>());
             }
         }
 
@@ -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<const unsigned short>(),
+                                     md->cTC ? gmx::arrayRefFromArray(md->cTC, md->nr)
+                                             : gmx::ArrayRef<const unsigned short>());
         }
 
         bFirstStep = FALSE;