From 706f1c38f29e1f657a1b7c93cb4564bd88031cc2 Mon Sep 17 00:00:00 2001 From: Rafael Ravedutti Date: Wed, 7 Apr 2021 00:46:51 +0200 Subject: [PATCH] Update stubbed force calculation Signed-off-by: Rafael Ravedutti --- config.mk | 2 +- include_GCC.mk | 6 +++-- src/core/force.c | 57 +++++++++++++++++++++++++----------------------- src/main.c | 6 ++--- src/stub.c | 14 +++++------- 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/config.mk b/config.mk index a67dd4d..afbd2ca 100644 --- a/config.mk +++ b/config.mk @@ -6,4 +6,4 @@ DATA_TYPE ?= DP DATA_LAYOUT ?= SOA #Feature options -OPTIONS += -DALIGNMENT=64 +OPTIONS += -DALIGNMENT=64 -DLIKWID_PERFMON diff --git a/include_GCC.mk b/include_GCC.mk index d29cca9..3ec307a 100644 --- a/include_GCC.mk +++ b/include_GCC.mk @@ -11,5 +11,7 @@ CFLAGS = -O3 -march=znver1 -ffast-math -funroll-loops # -fopenmp ASFLAGS = -masm=intel LFLAGS = DEFINES = -D_GNU_SOURCE -INCLUDES = -LIBS = -lm +#INCLUDES = +#LIBS = -lm +INCLUDES = $(LIKWID_INC) +LIBS = -lm $(LIKWID_LIB) -llikwid diff --git a/src/core/force.c b/src/core/force.c index 7ce9d8a..e1cb39d 100644 --- a/src/core/force.c +++ b/src/core/force.c @@ -31,7 +31,8 @@ double computeForce( Parameter *param, Atom *atom, Neighbor *neighbor, - int profile) + int profile, + int ntimes) { int Nlocal = atom->Nlocal; int* neighs; @@ -52,38 +53,40 @@ double computeForce( LIKWID_MARKER_START("force"); } + for(int t = 0; t < ntimes; t++) { #pragma omp parallel for - for(int i = 0; i < Nlocal; i++) { - neighs = &neighbor->neighbors[i * neighbor->maxneighs]; - int numneighs = neighbor->numneigh[i]; - MD_FLOAT xtmp = atom_x(i); - MD_FLOAT ytmp = atom_y(i); - MD_FLOAT ztmp = atom_z(i); + for(int i = 0; i < Nlocal; i++) { + neighs = &neighbor->neighbors[i * neighbor->maxneighs]; + int numneighs = neighbor->numneigh[i]; + MD_FLOAT xtmp = atom_x(i); + MD_FLOAT ytmp = atom_y(i); + MD_FLOAT ztmp = atom_z(i); - MD_FLOAT fix = 0; - MD_FLOAT fiy = 0; - MD_FLOAT fiz = 0; + MD_FLOAT fix = 0; + MD_FLOAT fiy = 0; + MD_FLOAT fiz = 0; - for(int k = 0; k < numneighs; k++) { - int j = neighs[k]; - MD_FLOAT delx = xtmp - atom_x(j); - MD_FLOAT dely = ytmp - atom_y(j); - MD_FLOAT delz = ztmp - atom_z(j); - MD_FLOAT rsq = delx * delx + dely * dely + delz * delz; + for(int k = 0; k < numneighs; k++) { + int j = neighs[k]; + MD_FLOAT delx = xtmp - atom_x(j); + MD_FLOAT dely = ytmp - atom_y(j); + MD_FLOAT delz = ztmp - atom_z(j); + MD_FLOAT rsq = delx * delx + dely * dely + delz * delz; - if(rsq < cutforcesq) { - MD_FLOAT sr2 = 1.0 / rsq; - MD_FLOAT sr6 = sr2 * sr2 * sr2 * sigma6; - MD_FLOAT force = 48.0 * sr6 * (sr6 - 0.5) * sr2 * epsilon; - fix += delx * force; - fiy += dely * force; - fiz += delz * force; + if(rsq < cutforcesq) { + MD_FLOAT sr2 = 1.0 / rsq; + MD_FLOAT sr6 = sr2 * sr2 * sr2 * sigma6; + MD_FLOAT force = 48.0 * sr6 * (sr6 - 0.5) * sr2 * epsilon; + fix += delx * force; + fiy += dely * force; + fiz += delz * force; + } } - } - fx[i] += fix; - fy[i] += fiy; - fz[i] += fiz; + fx[i] += fix; + fy[i] += fiy; + fz[i] += fiz; + } } if(profile) { diff --git a/src/main.c b/src/main.c index 564708e..2b431ae 100644 --- a/src/main.c +++ b/src/main.c @@ -47,7 +47,7 @@ typedef enum { NUMTIMER } timertype; -extern double computeForce( Parameter*, Atom*, Neighbor*, int); +extern double computeForce( Parameter*, Atom*, Neighbor*, int, int); void init(Parameter *param) { @@ -205,7 +205,7 @@ int main (int argc, char** argv) setup(¶m, &atom, &neighbor); computeThermo(0, ¶m, &atom); - computeForce(¶m, &atom, &neighbor, 1); + computeForce(¶m, &atom, &neighbor, 1, 1); timer[FORCE] = 0.0; timer[NEIGH] = 0.0; @@ -221,7 +221,7 @@ int main (int argc, char** argv) timer[NEIGH] += reneighbour(¶m, &atom, &neighbor); } - timer[FORCE] += computeForce(¶m, &atom, &neighbor, 1); + timer[FORCE] += computeForce(¶m, &atom, &neighbor, 1, 1); finalIntegrate(¶m, &atom); if(!((n + 1) % param.nstat) && (n+1) < param.ntimes) { diff --git a/src/stub.c b/src/stub.c index c6f3c24..c82096c 100644 --- a/src/stub.c +++ b/src/stub.c @@ -16,7 +16,7 @@ #define LATTICE_DISTANCE 10.0 #define NEIGH_DISTANCE 1.0 -extern double computeForce( Parameter*, Atom*, Neighbor*, int); +extern double computeForce( Parameter*, Atom*, Neighbor*, int, int); void init(Parameter *param) { param->epsilon = 1.0; @@ -103,7 +103,7 @@ int main(int argc, const char *argv[]) { initAtom(atom); DEBUG("Creating atoms...\n"); - const int atoms_per_unit_cell = 16; + const int atoms_per_unit_cell = 8; for(int i = 0; i < param.nx; ++i) { for(int j = 0; j < param.ny; ++j) { @@ -158,7 +158,7 @@ int main(int argc, const char *argv[]) { } } - const double estim_volume = (double)(atom->Nlocal * 6 * sizeof(MD_FLOAT) + (atoms_per_unit_cell - 1 + 2) * sizeof(int)) / 1000.0; + const double estim_volume = (double)(atom->Nlocal * 6 * sizeof(MD_FLOAT) + atom->Nlocal * (atoms_per_unit_cell - 1 + 2) * sizeof(int)) / 1000.0; printf("System size (unit cells): %dx%dx%d\n", param.nx, param.ny, param.nz); printf("Atoms per unit cell: %d\n", atoms_per_unit_cell); printf("Total number of atoms: %d\n", atom->Nlocal); @@ -171,13 +171,9 @@ int main(int argc, const char *argv[]) { DEBUG("Building neighbor lists...\n"); buildNeighbor(atom, &neighbor); DEBUG("Computing forces...\n"); - computeForce(¶m, atom, &neighbor, 0); - - double T_accum = 0.0; - for(int i = 0; i < param.ntimes; i++) { - T_accum += computeForce(¶m, atom, &neighbor, 1); - } + computeForce(¶m, atom, &neighbor, 0, 1); + double T_accum = computeForce(¶m, atom, &neighbor, 1, param.ntimes); printf("Total time: %.4f, Time/force: %.4f\n", T_accum, T_accum / param.ntimes); LIKWID_MARKER_CLOSE; return EXIT_SUCCESS;