Skip to content

Commit

Permalink
I get ~ 3% improvement if I use MPI with 5000 atoms
Browse files Browse the repository at this point in the history
run astyle
  • Loading branch information
Iximiel committed Jul 24, 2024
1 parent cfbbc3d commit 74fa8d1
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

0 comments on commit 74fa8d1

Please sign in to comment.