diff --git a/src/PlumedMain.cpp b/src/PlumedMain.cpp index 4d6c6561d9efe4376a765c320473245772625ec7..916c1410fefff073ba9510770c4c0625372b2cf6 100644 --- a/src/PlumedMain.cpp +++ b/src/PlumedMain.cpp @@ -18,6 +18,7 @@ #include "DLLoader.h" #include "PlumedCommunicator.h" #include "CLToolMain.h" +#include "Stopwatch.h" using namespace PLMD; using namespace std; @@ -26,6 +27,7 @@ PlumedMain::PlumedMain(): comm(*new PlumedCommunicator), dlloader(*new DLLoader), cltool(NULL), + stopwatch(*new Stopwatch), grex(NULL), initialized(false), log(*new Log(comm)), @@ -35,13 +37,20 @@ PlumedMain::PlumedMain(): actionSet(*new ActionSet(*this)), bias(0.0), novirial(false) -{} +{ + stopwatch.start(); + stopwatch.pause(); +} PlumedMain::~PlumedMain(){ + stopwatch.start(); + stopwatch.stop(); + if(initialized) log<<stopwatch; delete &actionSet; delete &atoms; delete &log; if(grex) delete grex; + delete &stopwatch; if(cltool) delete cltool; delete &dlloader; delete &comm; @@ -56,6 +65,8 @@ PlumedMain::~PlumedMain(){ void PlumedMain::cmd(const std::string & word,void*val){ + stopwatch.start(); + if(false){ // for efficiency, words frequently used are checked first @@ -256,6 +267,8 @@ void PlumedMain::cmd(const std::string & word,void*val){ plumed_merror("cannot interpret cmd(\"" + word + "\"). check plumed developers manual to see the available commands."); }; }; + + stopwatch.pause(); } ///// @@ -358,6 +371,8 @@ void PlumedMain::prepareCalc(){ // traverse them in this order: void PlumedMain::prepareDependencies(){ + stopwatch.start("1 Prepare dependencies"); + // activate all the actions which are on step // activation is recursive and enables also the dependencies // before doing that, the prepare() method is called to see if there is some @@ -388,11 +403,15 @@ void PlumedMain::prepareDependencies(){ } atoms.setCollectEnergy(collectEnergy); + stopwatch.stop("1 Prepare dependencies"); + } void PlumedMain::shareData(){ // atom positions are shared (but only if there is something to do) if(!active)return; + stopwatch.start("2 Sharing data"); + stopwatch.stop("2 Sharing data"); atoms.share(); } @@ -404,12 +423,15 @@ void PlumedMain::performCalc(){ void PlumedMain::waitData(){ if(!active)return; + stopwatch.start("3 Waiting for data"); atoms.wait(); + stopwatch.stop("3 Waiting for data"); } void PlumedMain::justCalculate(){ + stopwatch.start("4 Calculating (forward loop)"); bias=0.0; // calculate the active actions in order (assuming *backward* dependence) @@ -432,10 +454,12 @@ void PlumedMain::justCalculate(){ } } } + stopwatch.stop("4 Calculating (forward loop)"); } void PlumedMain::justApply(){ + stopwatch.start("5 Applying (backward loop)"); // apply them in reverse order for(ActionSet::reverse_iterator p=actionSet.rbegin();p!=actionSet.rend();++p){ if((*p)->isActive()) (*p)->apply(); @@ -451,6 +475,7 @@ void PlumedMain::justApply(){ for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){ if((*p)->isActive()) (*p)->update(); } + stopwatch.stop("5 Applying (backward loop)"); } void PlumedMain::load(std::vector<std::string> & words){ diff --git a/src/PlumedMain.h b/src/PlumedMain.h index ad0f2e4de2eb66b520848b378f0c46ec2178fcfe..902c34127424f24f25253e6b5484a9305e1b575f 100644 --- a/src/PlumedMain.h +++ b/src/PlumedMain.h @@ -34,6 +34,7 @@ class Atoms; class ActionSet; class DLLoader; class PlumedCommunicator; +class Stopwatch; /// Main plumed object. /// In MD engines this object is not manipulated directly but it is wrapped in @@ -52,6 +53,7 @@ private: DLLoader& dlloader; WithCmd* cltool; + Stopwatch& stopwatch; WithCmd* grex; /// Flag to avoid double initialization bool initialized;