Skip to content

Commit

Permalink
move openmp directive in Ewald.cpp line 1499.Results in about 1 secon…
Browse files Browse the repository at this point in the history
…d faster with 5000 steps with 8 nodes.
  • Loading branch information
roryslange committed Sep 15, 2024
1 parent ca8191d commit bb01152
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Ewald.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ along with this program, also can be found at
#endif
#include "GOMCEventsProfile.h"

//writing to file for rory BoxForceReciprocal
#include <iostream>
#include <fstream>

Expand Down Expand Up @@ -1498,6 +1499,8 @@ void compareDouble(const double &x, const double &y, const int &i) {
void Ewald::BoxForceReciprocal(XYZArray const &molCoords,
XYZArray &atomForceRec, XYZArray &molForceRec,
uint box) {

//std::cout << "box:" << box << std::endl;
if (multiParticleEnabled && (box < BOXES_WITH_U_NB)) {
std::ofstream countFile;
int whileLoop, for1, for2 = 0;
Expand Down Expand Up @@ -1555,6 +1558,14 @@ void Ewald::BoxForceReciprocal(XYZArray const &molCoords,
start = mols.MolStart(molIndex);
double lambdaCoef = GetLambdaCoef(molIndex, box);

#ifdef _OPENMP
#pragma omp parallel for default(none) shared(box, lambdaCoef, molCoords, p) reduction(+:X, Y, Z)
#endif




#pragma omp for
for (p = start; p < start + length; p++) {
for1++;
double X = 0.0, Y = 0.0, Z = 0.0;
Expand All @@ -1577,9 +1588,9 @@ void Ewald::BoxForceReciprocal(XYZArray const &molCoords,
Z -= intraForce * distVect.z;
}
}
#ifdef _OPENMP
#pragma omp parallel for default(none) shared(box, lambdaCoef, molCoords, p) reduction(+:X, Y, Z)
#endif

//omp was here

for (int i = 0; i < (int)imageSizeRef[box]; i++) {
double dot =
Dot(p, kxRef[box][i], kyRef[box][i], kzRef[box][i], molCoords);
Expand All @@ -1600,7 +1611,7 @@ void Ewald::BoxForceReciprocal(XYZArray const &molCoords,
}
#endif
GOMC_EVENT_STOP(1, GomcProfileEvent::RECIP_BOX_FORCE);
countFile.open("countOut.txt");
countFile.open("countOut.txt", std::ofstream::out | std::ofstream::app);
countFile << "While loop: " << whileLoop << "\n for1: " << for1 << "\n for2: " << for2;
countFile.close();
}
Expand Down

0 comments on commit bb01152

Please sign in to comment.