Merge release-2019 branch into master
[alexxy/gromacs.git] / src / gromacs / mdrun / md.cpp
index 68d166d24b1990d456cac22da98420692cbb05c1..765ffd18a627c57c52c7687a4235ee1284a6a9f2 100644 (file)
@@ -356,18 +356,21 @@ void gmx::Integrator::do_md()
             /* Update mdebin with energy history if appending to output files */
             if (continuationOptions.appendFiles)
             {
-                restore_energyhistory_from_state(mdebin, observablesHistory->energyHistory.get());
-            }
-            else
-            {
-                if (observablesHistory->energyHistory != nullptr)
+                /* If no history is available (because a checkpoint is from before
+                 * it was written) make a new one later, otherwise restore it.
+                 */
+                if (observablesHistory->energyHistory)
                 {
-                    /* We might have read an energy history from checkpoint.
-                     * As we are not appending, we want to restart the statistics.
-                     * Free the allocated memory and reset the counts.
-                     */
-                    observablesHistory->energyHistory = {};
+                    restore_energyhistory_from_state(mdebin, observablesHistory->energyHistory.get());
                 }
+            }
+            else if (observablesHistory->energyHistory)
+            {
+                /* We might have read an energy history from checkpoint.
+                 * As we are not appending, we want to restart the statistics.
+                 * Free the allocated memory and reset the counts.
+                 */
+                observablesHistory->energyHistory = {};
                 /* We might have read a pull history from checkpoint.
                  * We will still want to keep the statistics, so that the files
                  * can be joined and still be meaningful.
@@ -375,26 +378,12 @@ void gmx::Integrator::do_md()
                  * should not be reset.
                  */
             }
-            if (ir->pull && ir->pull->bSetPbcRefToPrevStepCOM)
-            {
-                /* Copy the pull group COM of the previous step from the checkpoint state to the pull state */
-                setPrevStepPullComFromState(ir->pull_work, state);
-            }
         }
-        else if (ir->pull && ir->pull->bSetPbcRefToPrevStepCOM)
-        {
-            allocStatePrevStepPullCom(state, ir->pull_work);
-            t_pbc pbc;
-            set_pbc(&pbc, ir->ePBC, state->box);
-            initPullComFromPrevStep(cr, ir->pull_work, mdatoms, &pbc, as_rvec_array(state->x.data()));
-            updatePrevStepCom(ir->pull_work);
-            setStatePrevStepPullCom(ir->pull_work, state);
-        }
-        if (observablesHistory->energyHistory == nullptr)
+        if (!observablesHistory->energyHistory)
         {
             observablesHistory->energyHistory = compat::make_unique<energyhistory_t>();
         }
-        if (observablesHistory->pullHistory == nullptr)
+        if (!observablesHistory->pullHistory)
         {
             observablesHistory->pullHistory = compat::make_unique<PullHistory>();
         }
@@ -402,6 +391,8 @@ void gmx::Integrator::do_md()
         update_energyhistory(observablesHistory->energyHistory.get(), mdebin);
     }
 
+    preparePrevStepPullCom(ir, mdatoms, state, state_global, cr, startingFromCheckpoint);
+
     // TODO: Remove this by converting AWH into a ForceProvider
     auto awh = prepareAwhModule(fplog, *ir, state_global, cr, ms, startingFromCheckpoint,
                                 shellfc != nullptr,
@@ -857,7 +848,7 @@ void gmx::Integrator::do_md()
                                 constr, enerd, fcd,
                                 state, f.arrayRefWithPadding(), force_vir, mdatoms,
                                 nrnb, wcycle, graph, groups,
-                                shellfc, fr, t, mu_tot,
+                                shellfc, fr, ppForceWorkload, t, mu_tot,
                                 vsite,
                                 ddOpenBalanceRegion, ddCloseBalanceRegion);
         }
@@ -886,7 +877,7 @@ void gmx::Integrator::do_md()
                      state->box, state->x.arrayRefWithPadding(), &state->hist,
                      f.arrayRefWithPadding(), force_vir, mdatoms, enerd, fcd,
                      state->lambda, graph,
-                     fr, vsite, mu_tot, t, ed ? ed->getLegacyED() : nullptr,
+                     fr, ppForceWorkload, vsite, mu_tot, t, ed ? ed->getLegacyED() : nullptr,
                      (bNS ? GMX_FORCE_NS : 0) | force_flags,
                      ddOpenBalanceRegion, ddCloseBalanceRegion);
         }
@@ -1172,10 +1163,9 @@ void gmx::Integrator::do_md()
                       state, graph,
                       nrnb, wcycle, upd, constr);
 
-        if (MASTER(cr) && ir->bPull && ir->pull->bSetPbcRefToPrevStepCOM)
+        if (ir->bPull && ir->pull->bSetPbcRefToPrevStepCOM)
         {
-            updatePrevStepCom(ir->pull_work);
-            setStatePrevStepPullCom(ir->pull_work, state);
+            updatePrevStepPullCom(ir->pull_work, state);
         }
 
         if (ir->eI == eiVVAK)