diff --git a/src/core/PlumedMain.cpp b/src/core/PlumedMain.cpp index 37ea9d90461c75c25949352234426948254991c2..4acb1a2c9436449e4938e36a3c33e4653d09d2ac 100644 --- a/src/core/PlumedMain.cpp +++ b/src/core/PlumedMain.cpp @@ -47,7 +47,7 @@ using namespace std; -enum { SETBOX, SETPOSITIONS, SETMASSES, SETCHARGES, SETPOSITIONSX, SETPOSITIONSY, SETPOSITIONSZ, SETVIRIAL, SETENERGY, SETFORCES, SETFORCESX, SETFORCESY, SETFORCESZ, CALC, PREPAREDEPENDENCIES, SHAREDATA, PREPARECALC, PERFORMCALC, SETSTEP, SETSTEPLONG, SETATOMSNLOCAL, SETATOMSGATINDEX, SETATOMSFGATINDEX, SETATOMSCONTIGUOUS, CREATEFULLLIST, GETFULLLIST, CLEARFULLLIST, READ, CLEAR, GETAPIVERSION, INIT, SETREALPRECISION, SETMDLENGTHUNITS, SETMDENERGYUNITS, SETMDTIMEUNITS, SETMDCHARGEUNITS, SETMDMASSUNITS, SETNATURALUNITS, SETNOVIRIAL, SETPLUMEDDAT, SETMPICOMM, SETMPIFCOMM, SETMPIMULTISIMCOMM, SETNATOMS, SETTIMESTEP, SETMDENGINE, SETLOG, SETLOGFILE, SETSTOPFLAG, GETEXCHANGESFLAG, SETEXCHANGESSEED, SETNUMBEROFREPLICAS, GETEXCHANGESLIST, RUNFINALJOBS, ISENERGYNEEDED, GETBIAS, SETKBT, SETRESTART, READINPUTLINE }; +enum { SETBOX, SETPOSITIONS, SETMASSES, SETCHARGES, SETPOSITIONSX, SETPOSITIONSY, SETPOSITIONSZ, SETVIRIAL, SETENERGY, SETFORCES, SETFORCESX, SETFORCESY, SETFORCESZ, CALC, PREPAREDEPENDENCIES, SHAREDATA, PREPARECALC, PERFORMCALC, PERFORMCALCNOUPDATE, UPDATE, SETSTEP, SETSTEPLONG, SETATOMSNLOCAL, SETATOMSGATINDEX, SETATOMSFGATINDEX, SETATOMSCONTIGUOUS, CREATEFULLLIST, GETFULLLIST, CLEARFULLLIST, READ, CLEAR, GETAPIVERSION, INIT, SETREALPRECISION, SETMDLENGTHUNITS, SETMDENERGYUNITS, SETMDTIMEUNITS, SETMDCHARGEUNITS, SETMDMASSUNITS, SETNATURALUNITS, SETNOVIRIAL, SETPLUMEDDAT, SETMPICOMM, SETMPIFCOMM, SETMPIMULTISIMCOMM, SETNATOMS, SETTIMESTEP, SETMDENGINE, SETLOG, SETLOGFILE, SETSTOPFLAG, GETEXCHANGESFLAG, SETEXCHANGESSEED, SETNUMBEROFREPLICAS, GETEXCHANGESLIST, RUNFINALJOBS, ISENERGYNEEDED, GETBIAS, SETKBT, SETRESTART, READINPUTLINE }; namespace PLMD{ @@ -97,6 +97,8 @@ PlumedMain::PlumedMain(): word_map["shareData"]=SHAREDATA; word_map["prepareCalc"]=PREPARECALC; word_map["performCalc"]=PERFORMCALC; + word_map["performCalcNoUpdate"]=PERFORMCALCNOUPDATE; + word_map["update"]=UPDATE; word_map["setStep"]=SETSTEP; word_map["setStepLong"]=SETSTEPLONG; word_map["setAtomsNlocal"]=SETATOMSNLOCAL; @@ -251,6 +253,14 @@ void PlumedMain::cmd(const std::string & word,void*val){ CHECK_INIT(initialized,word); performCalc(); break; + case PERFORMCALCNOUPDATE: + CHECK_INIT(initialized,word); + performCalcNoUpdate(); + break; + case UPDATE: + CHECK_INIT(initialized,word); + update(); + break; case SETSTEP: CHECK_INIT(initialized,word); CHECK_NULL(val,word); @@ -647,10 +657,17 @@ void PlumedMain::shareData(){ stopwatch.stop("2 Sharing data"); } +void PlumedMain::performCalcNoUpdate(){ + waitData(); + justCalculate(); + backwardPropagate(); +} + void PlumedMain::performCalc(){ waitData(); justCalculate(); - justApply(); + backwardPropagate(); + update(); } void PlumedMain::waitData(){ @@ -703,7 +720,11 @@ void PlumedMain::justCalculate(){ } void PlumedMain::justApply(){ + backwardPropagate(); + update(); +} +void PlumedMain::backwardPropagate(){ if(!active)return; int iaction=0; stopwatch.start("5 Applying (backward loop)"); @@ -732,8 +753,13 @@ void PlumedMain::justApply(){ if(detailedTimers) stopwatch.start("5B Update forces"); if(atoms.getNatoms()>0) atoms.updateForces(); if(detailedTimers) stopwatch.stop("5B Update forces"); + stopwatch.stop("5 Applying (backward loop)"); +} - if(detailedTimers) stopwatch.start("5C Update"); +void PlumedMain::update(){ + if(!active)return; + + stopwatch.start("6 Update"); // update step (for statistics, etc) updateFlags.push(true); for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){ @@ -741,14 +767,12 @@ void PlumedMain::justApply(){ if((*p)->isActive() && (*p)->checkUpdate() && updateFlagsTop()) (*p)->update(); } while(!updateFlags.empty()) updateFlags.pop(); - if(detailedTimers) stopwatch.stop("5C Update"); if(!updateFlags.empty()) plumed_merror("non matching changes in the update flags"); // Check that no action has told the calculation to stop if(stopNow){ if(stopFlag) (*stopFlag)=1; else plumed_merror("your md code cannot handle plumed stop events - add a call to plumed.comm(stopFlag,stopCondition)"); } - stopwatch.stop("5 Applying (backward loop)"); // flush by default every 10000 steps // hopefully will not affect performance @@ -757,6 +781,7 @@ void PlumedMain::justApply(){ log.flush(); for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p) (*p)->fflush(); } + stopwatch.stop("6 Update"); } void PlumedMain::load(const std::string& ss){ diff --git a/src/core/PlumedMain.h b/src/core/PlumedMain.h index 7cfa1e5286ae1a7f9f64839850bfbbbc7313b2a4..09a4976d1fbcc30969435681b2d505fdca29dbd7 100644 --- a/src/core/PlumedMain.h +++ b/src/core/PlumedMain.h @@ -228,9 +228,15 @@ public: void shareData(); /** Perform the calculation. - Shortcut for waitData() + justCalculate() + justApply() + Shortcut for waitData() + justCalculate() + justApply(). + Equivalently: waitData() + justCalculate() + backwardPropagate() + update(). */ void performCalc(); +/** + Perform the calculation without update() + Shortcut for: waitData() + justCalculate() + backwardPropagate() +*/ + void performCalcNoUpdate(); /** Complete PLUMED calculation. Shortcut for prepareCalc() + performCalc() @@ -246,11 +252,21 @@ public: Perform the forward loop on active actions. */ void justCalculate(); +/** + Backward propagate and update. + Shortcut for backwardPropagate() + update() + I leave it here for backward compatibility +*/ + void justApply(); /** Perform the backward loop on active actions. Needed to apply the forces back. */ - void justApply(); + void backwardPropagate(); +/** + Call the update() method. +*/ + void update(); /** If there are calculations that need to be done at the very end of the calculations this makes sures they are done