Skip to content

Commit

Permalink
Merge pull request #1096 from Iximiel/CoordinationStride
Browse files Browse the repository at this point in the history
Small optimization in CoordinationBase
  • Loading branch information
GiovanniBussi authored Jul 24, 2024
2 parents cfbbc3d + 74fa8d1 commit fe18eee
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/colvar/CoordinationBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,21 @@ void CoordinationBase::calculate()
const unsigned nn=nl->size();
if(nt*stride*10>nn) nt=1;

const unsigned elementsPerRank = std::ceil(double(nn)/stride);
const unsigned int start= rank*elementsPerRank;
const unsigned int end = ((start + elementsPerRank)< nn)?(start + elementsPerRank): nn;

#pragma omp parallel num_threads(nt)
{
std::vector<Vector> omp_deriv(getPositions().size());
Tensor omp_virial;

#pragma omp for reduction(+:ncoord) nowait
for(unsigned int i=rank; i<nn; i+=stride) {
for(unsigned int i=start; i<end; ++i) {

Vector distance;
unsigned i0=nl->getClosePair(i).first;
unsigned i1=nl->getClosePair(i).second;
const unsigned i0=nl->getClosePair(i).first;
const unsigned i1=nl->getClosePair(i).second;

if(getAbsoluteIndex(i0)==getAbsoluteIndex(i1)) continue;

Expand Down Expand Up @@ -187,7 +191,8 @@ void CoordinationBase::calculate()
}
#pragma omp critical
if(nt>1) {
for(unsigned i=0; i<getPositions().size(); i++) deriv[i]+=omp_deriv[i];
for(unsigned i=0; i<getPositions().size(); i++)
deriv[i]+=omp_deriv[i];
virial+=omp_virial;
}
}
Expand Down

1 comment on commit fe18eee

@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/a-masterclass-22-09.txt
Found broken examples in automatic/a-masterclass-22-11.txt
Found broken examples in automatic/a-masterclass-22-12.txt
Found broken examples in automatic/performance-optimization.txt
Found broken examples in automatic/a-trieste-6.txt
Found broken examples in automatic/munster.txt
Found broken examples in automatic/ANN.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/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/INCLUDE.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/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in MiscelaneousPP.md

Please sign in to comment.