Skip to content

Commit

Permalink
Reduced the amount of memory that is used in Q6 so you can now run 4 …
Browse files Browse the repository at this point in the history
…threads
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed Sep 24, 2024
1 parent 8628615 commit 636898f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
22 changes: 13 additions & 9 deletions src/core/ActionWithVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ bool ActionWithVector::checkChainForNonScalarForces() const {
return false;
}

void ActionWithVector::getNumberOfForceDerivatives( unsigned& nforces, unsigned& nderiv ) const {
nforces=0; unsigned nargs = getNumberOfArguments(); int nmasks = getNumberOfMasks();
if( nargs>=nmasks && nmasks>0 ) nargs = nargs - nmasks;
if( getNumberOfAtoms()>0 ) nforces += 3*getNumberOfAtoms() + 9;
for(unsigned i=0; i<nargs; ++i) {
nforces += getPntrToArgument(i)->getNumberOfStoredValues();
}
nderiv = nforces;
}

bool ActionWithVector::checkForForces() {
if( getPntrToComponent(0)->getRank()==0 ) return ActionWithValue::checkForForces();

Expand All @@ -357,13 +367,8 @@ bool ActionWithVector::checkForForces() {
if( omp_forces.size()!=nt ) omp_forces.resize(nt);

// Recover the number of derivatives we require (this should be equal to the number of forces)
unsigned nderiv=0, nargs = getNumberOfArguments(); int nmasks = getNumberOfMasks();
if( nargs>=nmasks && nmasks>0 ) nargs = nargs - nmasks;
if( getNumberOfAtoms()>0 ) nderiv += 3*getNumberOfAtoms() + 9;
for(unsigned i=0; i<nargs; ++i) {
nderiv += getPntrToArgument(i)->getNumberOfStoredValues();
}
if( forcesForApply.size()!=nderiv ) forcesForApply.resize( nderiv );
unsigned nderiv, nforces; getNumberOfForceDerivatives( nforces, nderiv );
if( forcesForApply.size()!=nforces ) forcesForApply.resize( nforces );
// Clear force buffer
forcesForApply.assign( forcesForApply.size(), 0.0 );

Expand Down Expand Up @@ -408,8 +413,7 @@ bool ActionWithVector::checkForTaskForce( const unsigned& itask, const Value* my
}

void ActionWithVector::gatherForcesOnStoredValue( const unsigned& ival, const unsigned& itask, const MultiValue& myvals, std::vector<double>& forces ) const {
const Value* myval = getConstPntrToComponent(ival);
double fforce = myval->getForce(itask);
const Value* myval = getConstPntrToComponent(ival); double fforce = myval->getForce(itask);
for(unsigned j=0; j<myvals.getNumberActive(ival); ++j) {
unsigned jder=myvals.getActiveIndex(ival, j); plumed_dbg_assert( jder<forces.size() );
forces[jder] += fforce*myvals.getDerivative( ival, jder );
Expand Down
2 changes: 2 additions & 0 deletions src/core/ActionWithVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class ActionWithVector:
virtual void gatherForces( const unsigned& i, const MultiValue& myvals, std::vector<double>& forces ) const ;
/// This is to transfer data from the buffer to the final value
void finishComputations( const std::vector<double>& buf );
/// Get the number of forces to use
virtual void getNumberOfForceDerivatives( unsigned& nforces, unsigned& nderiv ) const ;
/// Apply the forces on this data
virtual void apply();
};
Expand Down
30 changes: 27 additions & 3 deletions src/matrixtools/MatrixTimesVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class MatrixTimesVector : public ActionWithVector {
void calculate() override ;
void performTask( const unsigned& task_index, MultiValue& myvals ) const override ;
int checkTaskIsActive( const unsigned& itask ) const override ;
void getNumberOfForceDerivatives( unsigned& nforces, unsigned& nderiv ) const override ;
void gatherForces( const unsigned& itask, const MultiValue& myvals, std::vector<double>& forces ) const override ;
};

PLUMED_REGISTER_ACTION(MatrixTimesVector,"MATRIX_VECTOR_PRODUCT")
Expand Down Expand Up @@ -173,7 +175,7 @@ int MatrixTimesVector::checkTaskIsActive( const unsigned& itask ) const {

void MatrixTimesVector::performTask( const unsigned& task_index, MultiValue& myvals ) const {
if( sumrows ) {
unsigned base=0, n=getNumberOfArguments()-1; Value* myvec = getPntrToArgument(n);
unsigned n=getNumberOfArguments()-1; Value* myvec = getPntrToArgument(n);

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable myvec is not used.
for(unsigned i=0; i<n; ++i) {
Value* mymat = getPntrToArgument(i);
unsigned ncol = mymat->getNumberOfColumns();
Expand All @@ -184,11 +186,10 @@ void MatrixTimesVector::performTask( const unsigned& task_index, MultiValue& myv
// And the derivatives
if( doNotCalculateDerivatives() ) continue;

unsigned dloc = base + task_index*ncol;
unsigned dloc = task_index*ncol;
for(unsigned j=0; j<nmat; ++j) {
myvals.addDerivative( i, dloc + j, 1.0 ); myvals.updateIndex( i, dloc + j );
}
base += mymat->getNumberOfStoredValues();
}
} else if( getPntrToArgument(1)->getRank()==1 ) {
Value* mymat = getPntrToArgument(0);
Expand Down Expand Up @@ -238,5 +239,28 @@ void MatrixTimesVector::performTask( const unsigned& task_index, MultiValue& myv
}
}

void MatrixTimesVector::getNumberOfForceDerivatives( unsigned& nforces, unsigned& nderiv ) const {
ActionWithVector::getNumberOfForceDerivatives( nforces, nderiv );
if( sumrows ) nderiv = getPntrToArgument(0)->getNumberOfStoredValues() + getPntrToArgument(getNumberOfArguments()-1)->getNumberOfStoredValues();
}

void MatrixTimesVector::gatherForces( const unsigned& itask, const MultiValue& myvals, std::vector<double>& forces ) const {
if( !sumrows ) { ActionWithVector::gatherForces( itask, myvals, forces ); return; }
if( checkComponentsForForce() ) {
unsigned base = 0;
for(unsigned ival=0; ival<getNumberOfComponents(); ++ival) {
const Value* myval=getConstPntrToComponent(ival);
if( myval->forcesWereAdded() ) {
double fforce = myval->getForce(itask);
for(unsigned j=0; j<myvals.getNumberActive(ival); ++j) {
unsigned jder=myvals.getActiveIndex(ival, j); plumed_dbg_assert( jder<forces.size() );
forces[base+jder] += fforce*myvals.getDerivative( ival, jder );
}
}
base += getPntrToArgument(ival)->getNumberOfStoredValues();
}
}
}

}
}

1 comment on commit 636898f

@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.