Skip to content
Snippets Groups Projects
Commit 87f505ca authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Added detailed timers for action

Can be activated with DEBUG DETAILED_TIMERS, and provide action by action
timing. Useful for optimization
parent 4f460d14
No related branches found
No related tags found
No related merge requests found
......@@ -66,7 +66,8 @@ PlumedMain::PlumedMain():
restart(false),
stopFlag(NULL),
stopNow(false),
novirial(false)
novirial(false),
detailedTimers(false)
{
log.link(comm);
log.setLinePrefix("PLUMED: ");
......@@ -522,8 +523,15 @@ void PlumedMain::justCalculate(){
stopwatch.start("4 Calculating (forward loop)");
bias=0.0;
int iaction=0;
// calculate the active actions in order (assuming *backward* dependence)
for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){
std::string actionNumberLabel;
if(detailedTimers){
Tools::convert(iaction,actionNumberLabel);
actionNumberLabel="4A "+actionNumberLabel+" "+(*p)->getLabel();
stopwatch.start(actionNumberLabel);
}
ActionWithValue*av=dynamic_cast<ActionWithValue*>(*p);
ActionAtomistic*aa=dynamic_cast<ActionAtomistic*>(*p);
{
......@@ -543,6 +551,9 @@ void PlumedMain::justCalculate(){
ActionWithVirtualAtom*avv=dynamic_cast<ActionWithVirtualAtom*>(*p);
if(avv)avv->setGradientsIfNeeded();
}
if(detailedTimers) stopwatch.stop(actionNumberLabel);
iaction++;
}
stopwatch.stop("4 Calculating (forward loop)");
}
......@@ -550,22 +561,40 @@ void PlumedMain::justCalculate(){
void PlumedMain::justApply(){
if(!active)return;
int iaction=0;
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();
ActionAtomistic*a=dynamic_cast<ActionAtomistic*>(*p);
if((*p)->isActive()){
std::string actionNumberLabel;
if(detailedTimers){
Tools::convert(iaction,actionNumberLabel);
actionNumberLabel="5A "+actionNumberLabel+" "+(*p)->getLabel();
stopwatch.start(actionNumberLabel);
}
(*p)->apply();
ActionAtomistic*a=dynamic_cast<ActionAtomistic*>(*p);
// still ActionAtomistic has a special treatment, since they may need to add forces on atoms
if(a) if(a->isActive()) a->applyForces();
if(a) a->applyForces();
if(detailedTimers) stopwatch.stop(actionNumberLabel);
}
iaction++;
}
// this is updating the MD copy of the forces
if(detailedTimers) stopwatch.start("5B Update forces");
if(atoms.getNatoms()>0) atoms.updateForces();
if(detailedTimers) stopwatch.stop("5B Update forces");
if(detailedTimers) stopwatch.start("5C Update");
// update step (for statistics, etc)
for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){
if((*p)->isActive()) (*p)->update();
}
if(detailedTimers) stopwatch.stop("5C Update");
// Check that no action has told the calculation to stop
if(stopNow){
if(stopFlag) (*stopFlag)=1;
......
......@@ -135,6 +135,8 @@ public:
/// Flag to switch off virial calculation (for debug and MD codes with no barostat)
bool novirial;
/// Flag to switch on detailed timers
bool detailedTimers;
/// Add a citation, returning a string containing the reference number, something like "[10]"
std::string cite(const std::string&);
......
......@@ -49,6 +49,7 @@ class Debug:
bool logActivity;
bool logRequestedAtoms;
bool novirial;
bool detailedTimers;
public:
Debug(const ActionOptions&ao);
/// Register all the relevant keywords for the action
......@@ -66,6 +67,7 @@ void Debug::registerKeywords( Keywords& keys ){
keys.addFlag("logActivity",false,"write in the log which actions are inactive and which are inactive");
keys.addFlag("logRequestedAtoms",false,"write in the log which atoms have been requested at a given time");
keys.addFlag("NOVIRIAL",false,"switch off the virial contribution for the entirity of the simulation");
keys.addFlag("DETAILED_TIMERS",false,"switch on detailed timers");
}
Debug::Debug(const ActionOptions&ao):
......@@ -81,6 +83,9 @@ novirial(false){
parseFlag("NOVIRIAL",novirial);
if(novirial) log.printf(" Switching off virial contribution\n");
if(novirial) plumed.novirial=true;
parseFlag("DETAILED_TIMERS",detailedTimers);
if(detailedTimers) log.printf(" Detailed timing on\n");
plumed.detailedTimers=true;
checkRead();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment