Skip to content

Commit

Permalink
Now turning off derivatives on forward pass through task loop when st…
Browse files Browse the repository at this point in the history
…oring values as they are only needed on the backward pass to calculate forces
  • Loading branch information
Gareth Aneurin Tribello committed Jul 4, 2024
1 parent 2982b55 commit b9b8969
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/core/ActionWithVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Option interpretEnvString(const char* env,const char* str) {
if(!std::strcmp(str,"no"))return Option::no;
plumed_error()<<"Cannot understand env var "<<env<<"\nPossible values: yes/no\nActual value: "<<str;
}

/// Switch on/off chains of actions using PLUMED environment variable
/// export PLUMED_FORBID_CHAINS=yes # forbid the use of chains in this run
/// export PLUMED_FORBID_CHAINS=no # allow chains to be used in the run
Expand All @@ -44,7 +44,7 @@ Option getenvChainForbidden() {
static const char* name="PLUMED_FORBID_CHAINS";
static const auto opt = interpretEnvString(name,std::getenv(name));
return opt;
}
}

void ActionWithVector::registerKeywords( Keywords& keys ) {
Action::registerKeywords( keys );
Expand All @@ -60,6 +60,7 @@ ActionWithVector::ActionWithVector(const ActionOptions&ao):
ActionWithValue(ao),
ActionWithArguments(ao),
serial(false),
forwardPass(false),
action_to_do_before(NULL),
action_to_do_after(NULL),
never_reduce_tasks(false),
Expand Down Expand Up @@ -451,6 +452,11 @@ std::vector<unsigned>& ActionWithVector::getListOfActiveTasks( ActionWithVector*
return active_tasks;
}

bool ActionWithVector::doNotCalculateDerivatives() const {
if( forwardPass ) return true;
return ActionWithValue::doNotCalculateDerivatives();
}

void ActionWithVector::runAllTasks() {
// Skip this if this is done elsewhere
if( action_to_do_before ) return;
Expand All @@ -471,6 +477,12 @@ void ActionWithVector::runAllTasks() {
// Now do all preparations required to run all the tasks
// prepareForTaskLoop();

if( !action_to_do_after ) {
forwardPass=true;
for(unsigned i=0; i<getNumberOfComponents(); ++i) {
if( getConstPntrToComponent(i)->getRank()==0 ) { forwardPass=false; break; }
}
}
// Get the total number of streamed quantities that we need
unsigned nquants=0, nmatrices=0, maxcol=0, nbooks=0;
getNumberOfStreamedQuantities( getLabel(), nquants, nmatrices, maxcol, nbooks );
Expand Down Expand Up @@ -509,7 +521,7 @@ void ActionWithVector::runAllTasks() {

// MPI Gather everything
if( !serial && buffer.size()>0 ) gatherProcesses( buffer );
finishComputations( buffer );
finishComputations( buffer ); forwardPass=false;
}

void ActionWithVector::gatherThreads( const unsigned& nt, const unsigned& bufsize, const std::vector<double>& omp_buffer, std::vector<double>& buffer, MultiValue& myvals ) {
Expand Down
4 changes: 4 additions & 0 deletions src/core/ActionWithVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ActionWithVector:
private:
/// Is the calculation to be done in serial
bool serial;
/// Are we in the forward pass through the calculation
bool forwardPass;
/// The buffer that we use (we keep a copy here to avoid resizing)
std::vector<double> buffer;
/// The list of active tasks
Expand Down Expand Up @@ -119,6 +121,8 @@ class ActionWithVector:
virtual void prepare() override;
void retrieveAtoms( const bool& force=false ) override;
void calculateNumericalDerivatives(ActionWithValue* av) override;
/// Turn off the calculation of the derivatives during the forward pass through a calculation
bool doNotCalculateDerivatives() const override ;
/// Are we running this command in a chain
bool actionInChain() const ;
/// This is overwritten within ActionWithMatrix and is used to build the chain of just matrix actions
Expand Down

1 comment on commit b9b8969

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANGLES.tmp
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/CAVITY.tmp
Found broken examples in automatic/CLASSICAL_MDS.tmp
Found broken examples in automatic/CLUSTER_DIAMETER.tmp
Found broken examples in automatic/CLUSTER_DISTRIBUTION.tmp
Found broken examples in automatic/CLUSTER_PROPERTIES.tmp
Found broken examples in automatic/CONSTANT.tmp
Found broken examples in automatic/CONTACT_MATRIX.tmp
Found broken examples in automatic/CONTACT_MATRIX_PROPER.tmp
Found broken examples in automatic/COORDINATIONNUMBER.tmp
Found broken examples in automatic/DFSCLUSTERING.tmp
Found broken examples in automatic/DISTANCE_FROM_CONTOUR.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FIND_CONTOUR.tmp
Found broken examples in automatic/FIND_CONTOUR_SURFACE.tmp
Found broken examples in automatic/FIND_SPHERICAL_CONTOUR.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/GPROPERTYMAP.tmp
Found broken examples in automatic/HBOND_MATRIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/INCYLINDER.tmp
Found broken examples in automatic/INENVELOPE.tmp
Found broken examples in automatic/INTERPOLATE_GRID.tmp
Found broken examples in automatic/LOCAL_AVERAGE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/METATENSOR.tmp
Found broken examples in automatic/MULTICOLVARDENS.tmp
Found broken examples in automatic/OUTPUT_CLUSTER.tmp
Found broken examples in automatic/PAMM.tmp
Found broken examples in automatic/PCA.tmp
Found broken examples in automatic/PCAVARS.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in automatic/PYCVINTERFACE.tmp
Found broken examples in automatic/PYTHONFUNCTION.tmp
Found broken examples in automatic/Q3.tmp
Found broken examples in automatic/Q4.tmp
Found broken examples in automatic/Q6.tmp
Found broken examples in automatic/QUATERNION.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_LINEAR_PROJ.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_MAHA_DIST.tmp
Found broken examples in automatic/SPRINT.tmp
Found broken examples in automatic/TETRAHEDRALPORE.tmp
Found broken examples in automatic/TORSIONS.tmp
Found broken examples in automatic/WHAM_WEIGHTS.tmp
Found broken examples in AnalysisPP.md
Found broken examples in CollectiveVariablesPP.md
Found broken examples in MiscelaneousPP.md

Please sign in to comment.