Skip to content

Commit 94d33a9

Browse files
author
Gareth Aneurin Tribello
committed
Added some optimisations in AdjacencyMatrixBase
1 parent cd6f553 commit 94d33a9

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/adjmat/AdjacencyMatrixBase.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,12 @@ void AdjacencyMatrixBase::performTask( const std::string& controller, const unsi
308308
// Update dynamic list indices for virial
309309
unsigned base = 3*getNumberOfAtoms(); for(unsigned j=0; j<9; ++j) myvals.updateIndex( w_ind, base+j );
310310
// And the indices for the derivatives of the row of the matrix
311-
unsigned nmat = getConstPntrToComponent(0)->getPositionInMatrixStash(), nmat_ind = myvals.getNumberOfMatrixRowDerivatives( nmat );
312-
std::vector<unsigned>& matrix_indices( myvals.getMatrixRowDerivativeIndices( nmat ) );
313-
matrix_indices[nmat_ind+0]=3*index2+0; matrix_indices[nmat_ind+1]=3*index2+1; matrix_indices[nmat_ind+2]=3*index2+2;
314-
myvals.setNumberOfMatrixRowDerivatives( nmat, nmat_ind+3 );
311+
if( chainContinuesAfterThisAction() ) {
312+
unsigned nmat = getConstPntrToComponent(0)->getPositionInMatrixStash(), nmat_ind = myvals.getNumberOfMatrixRowDerivatives( nmat );
313+
std::vector<unsigned>& matrix_indices( myvals.getMatrixRowDerivativeIndices( nmat ) );
314+
matrix_indices[nmat_ind+0]=3*index2+0; matrix_indices[nmat_ind+1]=3*index2+1; matrix_indices[nmat_ind+2]=3*index2+2;
315+
myvals.setNumberOfMatrixRowDerivatives( nmat, nmat_ind+3 );
316+
}
315317
}
316318

317319
// Calculate the components if we need them
@@ -352,18 +354,20 @@ void AdjacencyMatrixBase::performTask( const std::string& controller, const unsi
352354
myvals.addDerivative( z_index, base+1, 0 ); myvals.addDerivative( z_index, base+4, 0 ); myvals.addDerivative( z_index, base+7, 0 );
353355
myvals.addDerivative( z_index, base+2, -atom[0] ); myvals.addDerivative( z_index, base+5, -atom[1] ); myvals.addDerivative( z_index, base+8, -atom[2] );
354356
for(unsigned k=0; k<9; ++k) { myvals.updateIndex( x_index, base+k ); myvals.updateIndex( y_index, base+k ); myvals.updateIndex( z_index, base+k ); }
355-
for(unsigned k=1; k<4; ++k) {
356-
unsigned nmat = getConstPntrToComponent(k)->getPositionInMatrixStash(), nmat_ind = myvals.getNumberOfMatrixRowDerivatives( nmat );
357-
std::vector<unsigned>& matrix_indices( myvals.getMatrixRowDerivativeIndices( nmat ) );
358-
matrix_indices[nmat_ind+0]=3*index2+0; matrix_indices[nmat_ind+1]=3*index2+1; matrix_indices[nmat_ind+2]=3*index2+2;
359-
myvals.setNumberOfMatrixRowDerivatives( nmat, nmat_ind+3 );
357+
if( chainContinuesAfterThisAction() ) {
358+
for(unsigned k=1; k<4; ++k) {
359+
unsigned nmat = getConstPntrToComponent(k)->getPositionInMatrixStash(), nmat_ind = myvals.getNumberOfMatrixRowDerivatives( nmat );
360+
std::vector<unsigned>& matrix_indices( myvals.getMatrixRowDerivativeIndices( nmat ) );
361+
matrix_indices[nmat_ind+0]=3*index2+0; matrix_indices[nmat_ind+1]=3*index2+1; matrix_indices[nmat_ind+2]=3*index2+2;
362+
myvals.setNumberOfMatrixRowDerivatives( nmat, nmat_ind+3 );
363+
}
360364
}
361365
}
362366
}
363367
}
364368

365369
void AdjacencyMatrixBase::runEndOfRowJobs( const unsigned& ind, const std::vector<unsigned> & indices, MultiValue& myvals ) const {
366-
if( doNotCalculateDerivatives() ) return;
370+
if( doNotCalculateDerivatives() || !chainContinuesAfterThisAction() ) return;
367371

368372
for(int k=0; k<getNumberOfComponents(); ++k) {
369373
unsigned nmat = getConstPntrToComponent(k)->getPositionInMatrixStash(), nmat_ind = myvals.getNumberOfMatrixRowDerivatives( nmat );

src/core/ActionWithVector.h

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class ActionWithVector:
125125
bool doNotCalculateDerivatives() const override ;
126126
/// Are we running this command in a chain
127127
bool actionInChain() const ;
128+
bool chainContinuesAfterThisAction() const ;
128129
/// This is overwritten within ActionWithMatrix and is used to build the chain of just matrix actions
129130
virtual void finishChainBuild( ActionWithVector* act );
130131
/// Check if there are any stored values in arguments
@@ -185,6 +186,11 @@ bool ActionWithVector::actionInChain() const {
185186
return (action_to_do_before!=NULL);
186187
}
187188

189+
inline
190+
bool ActionWithVector::chainContinuesAfterThisAction() const {
191+
return (action_to_do_after!=NULL);
192+
}
193+
188194
inline
189195
bool ActionWithVector::runInSerial() const {
190196
return serial;

0 commit comments

Comments
 (0)