Skip to content

Commit d15c12f

Browse files
Gareth Aneurin TribelloGareth Aneurin Tribello
Gareth Aneurin Tribello
authored and
Gareth Aneurin Tribello
committed
Optimisations in adjacency matrix calculator
1 parent b9b8969 commit d15c12f

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/adjmat/AdjacencyMatrixBase.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ void AdjacencyMatrixBase::updateNeighbourList() {
228228
}
229229
threecells.buildCellLists( ltmp_pos2, threeblocks, getPbc() );
230230
}
231+
// And finally work out maximum number of columns to use
232+
maxcol = nlist[0];
233+
for(unsigned i=1; i<getConstPntrToComponent(0)->getShape()[0]; ++i) {
234+
if( nlist[i]>maxcol ) maxcol = nlist[i];
235+
}
231236
}
232237

233238
void AdjacencyMatrixBase::getAdditionalTasksRequired( ActionWithVector* action, std::vector<unsigned>& atasks ) {
@@ -249,16 +254,6 @@ void AdjacencyMatrixBase::getAdditionalTasksRequired( ActionWithVector* action,
249254
}
250255
}
251256

252-
unsigned AdjacencyMatrixBase::getNumberOfColumns() const {
253-
unsigned maxcol=nlist[0];
254-
for(unsigned i=1; i<getConstPntrToComponent(0)->getShape()[0]; ++i) {
255-
if( nlist[i]>maxcol ) maxcol = nlist[i];
256-
}
257-
// This triggers appropriate storage of symmetric matrices which can only have
258-
// a maximumum of shape[1]-1 non-zero elements
259-
return maxcol;
260-
}
261-
262257
unsigned AdjacencyMatrixBase::retrieveNeighbours( const unsigned& current, std::vector<unsigned> & indices ) const {
263258
unsigned natoms=nlist[current]; indices[0]=current;
264259
unsigned lstart = getConstPntrToComponent(0)->getShape()[0] + current*(1+natoms_per_list); plumed_dbg_assert( nlist[lstart]==current );

src/adjmat/AdjacencyMatrixBase.h

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class AdjacencyMatrixBase : public ActionWithMatrix {
3636
LinkCells linkcells, threecells;
3737
std::vector<unsigned> ablocks, threeblocks;
3838
double nl_cut, nl_cut2;
39+
unsigned maxcol;
3940
unsigned nl_stride;
4041
unsigned natoms_per_list;
4142
std::vector<unsigned> nlist;
@@ -106,6 +107,11 @@ void AdjacencyMatrixBase::addBoxDerivatives( const Tensor& vir, MultiValue& myva
106107
myvals.addDerivative( w_index, nbase+8, vir(2,2) );
107108
}
108109

110+
inline
111+
unsigned AdjacencyMatrixBase::getNumberOfColumns() const {
112+
return maxcol;
113+
}
114+
109115

110116
}
111117
}

0 commit comments

Comments
 (0)