From 74fa8d1af7ca6d2e5027ff979064f8450601c66b Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:48:54 +0200 Subject: [PATCH] I get ~ 3% improvement if I use MPI with 5000 atoms run astyle --- src/colvar/CoordinationBase.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/colvar/CoordinationBase.cpp b/src/colvar/CoordinationBase.cpp index 9a6cd66eee..e7ab51611c 100644 --- a/src/colvar/CoordinationBase.cpp +++ b/src/colvar/CoordinationBase.cpp @@ -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 omp_deriv(getPositions().size()); Tensor omp_virial; #pragma omp for reduction(+:ncoord) nowait - for(unsigned int i=rank; igetClosePair(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; @@ -187,7 +191,8 @@ void CoordinationBase::calculate() } #pragma omp critical if(nt>1) { - for(unsigned i=0; i