Improve stubbed force calculation version

Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com>
This commit is contained in:
Rafael Ravedutti 2021-03-30 22:17:30 +02:00
parent 7efd30791a
commit 77a0774208
4 changed files with 90 additions and 41 deletions

View File

@ -1,7 +1,9 @@
# Supported: GCC, CLANG, ICC # Supported: GCC, CLANG, ICC
TAG ?= GCC TAG ?= GCC
DATA_TYPE ?= SP#SP or DP # SP or DP
DATA_LAYOUT ?= SoA#AOS or SOA DATA_TYPE ?= DP
# AOS or SOA
DATA_LAYOUT ?= SOA
#Feature options #Feature options
OPTIONS += -DALIGNMENT=64 OPTIONS += -DALIGNMENT=64

View File

@ -30,7 +30,8 @@
double computeForce( double computeForce(
Parameter *param, Parameter *param,
Atom *atom, Atom *atom,
Neighbor *neighbor) Neighbor *neighbor,
int profile)
{ {
int Nlocal = atom->Nlocal; int Nlocal = atom->Nlocal;
int* neighs; int* neighs;
@ -47,7 +48,9 @@ double computeForce(
fz[i] = 0.0; fz[i] = 0.0;
} }
if(profile) {
LIKWID_MARKER_START("force"); LIKWID_MARKER_START("force");
}
#pragma omp parallel for #pragma omp parallel for
for(int i = 0; i < Nlocal; i++) { for(int i = 0; i < Nlocal; i++) {
@ -82,8 +85,11 @@ double computeForce(
fy[i] += fiy; fy[i] += fiy;
fz[i] += fiz; fz[i] += fiz;
} }
LIKWID_MARKER_STOP("force");
E = getTimeStamp();
if(profile) {
LIKWID_MARKER_STOP("force");
}
E = getTimeStamp();
return E-S; return E-S;
} }

View File

@ -47,7 +47,7 @@ typedef enum {
NUMTIMER NUMTIMER
} timertype; } timertype;
extern double computeForce( Parameter*, Atom*, Neighbor*); extern double computeForce( Parameter*, Atom*, Neighbor*, int);
void init(Parameter *param) void init(Parameter *param)
{ {
@ -205,7 +205,7 @@ int main (int argc, char** argv)
setup(&param, &atom, &neighbor); setup(&param, &atom, &neighbor);
computeThermo(0, &param, &atom); computeThermo(0, &param, &atom);
computeForce(&param, &atom, &neighbor); computeForce(&param, &atom, &neighbor, 1);
timer[FORCE] = 0.0; timer[FORCE] = 0.0;
timer[NEIGH] = 0.0; timer[NEIGH] = 0.0;
@ -221,7 +221,7 @@ int main (int argc, char** argv)
timer[NEIGH] += reneighbour(&param, &atom, &neighbor); timer[NEIGH] += reneighbour(&param, &atom, &neighbor);
} }
timer[FORCE] += computeForce(&param, &atom, &neighbor); timer[FORCE] += computeForce(&param, &atom, &neighbor, 1);
finalIntegrate(&param, &atom); finalIntegrate(&param, &atom);
if(!((n + 1) % param.nstat) && (n+1) < param.ntimes) { if(!((n + 1) % param.nstat) && (n+1) < param.ntimes) {

View File

@ -15,24 +15,18 @@
#define LATTICE_DISTANCE 10.0 #define LATTICE_DISTANCE 10.0
#define NEIGH_DISTANCE 1.0 #define NEIGH_DISTANCE 1.0
#define NX 4
#define NY 4
#define NZ 2
extern double computeForce( Parameter*, Atom*, Neighbor*); extern double computeForce( Parameter*, Atom*, Neighbor*, int);
void init(Parameter *param) { void init(Parameter *param) {
param->epsilon = 1.0; param->epsilon = 1.0;
param->sigma6 = 1.0; param->sigma6 = 1.0;
param->rho = 0.8442; param->rho = 0.8442;
param->ntimes = 200; param->ntimes = 200;
param->nx = NX; param->nx = 4;
param->ny = NY; param->ny = 4;
param->nz = NZ; param->nz = 2;
param->lattice = LATTICE_DISTANCE; param->lattice = LATTICE_DISTANCE;
param->xprd = NX * LATTICE_DISTANCE;
param->yprd = NY * LATTICE_DISTANCE;
param->zprd = NZ * LATTICE_DISTANCE;
param->cutforce = 5.0; param->cutforce = 5.0;
param->cutneigh = param->cutforce; param->cutneigh = param->cutforce;
param->mass = 1.0; param->mass = 1.0;
@ -44,6 +38,11 @@ void init(Parameter *param) {
param->every = 20; param->every = 20;
} }
// Show debug messages
//#define DEBUG printf
// Do not show debug messages
#define DEBUG
#define ADD_ATOM(x, y, z, vx, vy, vz) atom_x(atom->Nlocal) = base_x + x * NEIGH_DISTANCE; \ #define ADD_ATOM(x, y, z, vx, vy, vz) atom_x(atom->Nlocal) = base_x + x * NEIGH_DISTANCE; \
atom_y(atom->Nlocal) = base_y + y * NEIGH_DISTANCE; \ atom_y(atom->Nlocal) = base_y + y * NEIGH_DISTANCE; \
atom_z(atom->Nlocal) = base_z + z * NEIGH_DISTANCE; \ atom_z(atom->Nlocal) = base_z + z * NEIGH_DISTANCE; \
@ -60,7 +59,7 @@ int main(int argc, const char *argv[]) {
LIKWID_MARKER_INIT; LIKWID_MARKER_INIT;
LIKWID_MARKER_REGISTER("force"); LIKWID_MARKER_REGISTER("force");
printf("Initializing parameters...\n"); DEBUG("Initializing parameters...\n");
init(&param); init(&param);
for(int i = 0; i < argc; i++) for(int i = 0; i < argc; i++)
@ -96,17 +95,19 @@ int main(int argc, const char *argv[]) {
} }
} }
printf("Initializing atoms...\n"); param.xprd = param.nx * LATTICE_DISTANCE;
param.yprd = param.ny * LATTICE_DISTANCE;
param.zprd = param.nz * LATTICE_DISTANCE;
DEBUG("Initializing atoms...\n");
initAtom(atom); initAtom(atom);
printf("Creating atoms...\n"); DEBUG("Creating atoms...\n");
// Neighbors per atom const int atoms_per_unit_cell = 16;
// Total atoms: NX * NY * NZ * atoms_per_unit_cell
const int atoms_per_unit_cell = 8;
for(int i = 0; i < NX; ++i) { for(int i = 0; i < param.nx; ++i) {
for(int j = 0; j < NY; ++j) { for(int j = 0; j < param.ny; ++j) {
for(int k = 0; k < NZ; ++k) { for(int k = 0; k < param.nz; ++k) {
MD_FLOAT base_x = i * LATTICE_DISTANCE; MD_FLOAT base_x = i * LATTICE_DISTANCE;
MD_FLOAT base_y = j * LATTICE_DISTANCE; MD_FLOAT base_y = j * LATTICE_DISTANCE;
MD_FLOAT base_z = k * LATTICE_DISTANCE; MD_FLOAT base_z = k * LATTICE_DISTANCE;
@ -118,6 +119,12 @@ int main(int argc, const char *argv[]) {
growAtom(atom); growAtom(atom);
} }
if(atoms_per_unit_cell == 4) {
ADD_ATOM(0.0, 0.0, 0.0, vx, vy, vz);
ADD_ATOM(1.0, 0.0, 0.0, vx, vy, vz);
ADD_ATOM(0.0, 1.0, 0.0, vx, vy, vz);
ADD_ATOM(0.0, 0.0, 1.0, vx, vy, vz);
} else if(atoms_per_unit_cell == 8) {
ADD_ATOM(0.0, 0.0, 0.0, vx, vy, vz); ADD_ATOM(0.0, 0.0, 0.0, vx, vy, vz);
ADD_ATOM(1.0, 0.0, 0.0, vx, vy, vz); ADD_ATOM(1.0, 0.0, 0.0, vx, vy, vz);
ADD_ATOM(0.0, 1.0, 0.0, vx, vy, vz); ADD_ATOM(0.0, 1.0, 0.0, vx, vy, vz);
@ -126,18 +133,52 @@ int main(int argc, const char *argv[]) {
ADD_ATOM(1.0, 0.0, 1.0, vx, vy, vz); ADD_ATOM(1.0, 0.0, 1.0, vx, vy, vz);
ADD_ATOM(0.0, 1.0, 1.0, vx, vy, vz); ADD_ATOM(0.0, 1.0, 1.0, vx, vy, vz);
ADD_ATOM(1.0, 1.0, 1.0, vx, vy, vz); ADD_ATOM(1.0, 1.0, 1.0, vx, vy, vz);
} else if(atoms_per_unit_cell == 16) {
ADD_ATOM(0.0, 0.0, 0.0, vx, vy, vz);
ADD_ATOM(1.0, 0.0, 0.0, vx, vy, vz);
ADD_ATOM(0.0, 1.0, 0.0, vx, vy, vz);
ADD_ATOM(0.0, 0.0, 1.0, vx, vy, vz);
ADD_ATOM(1.0, 1.0, 0.0, vx, vy, vz);
ADD_ATOM(1.0, 0.0, 1.0, vx, vy, vz);
ADD_ATOM(0.0, 1.0, 1.0, vx, vy, vz);
ADD_ATOM(1.0, 1.0, 1.0, vx, vy, vz);
ADD_ATOM(0.5, 0.5, 0.5, vx, vy, vz);
ADD_ATOM(1.5, 0.5, 0.5, vx, vy, vz);
ADD_ATOM(0.5, 1.5, 0.5, vx, vy, vz);
ADD_ATOM(0.5, 0.5, 1.5, vx, vy, vz);
ADD_ATOM(1.5, 1.5, 0.5, vx, vy, vz);
ADD_ATOM(1.5, 0.5, 1.5, vx, vy, vz);
ADD_ATOM(0.5, 1.5, 1.5, vx, vy, vz);
ADD_ATOM(1.5, 1.5, 1.5, vx, vy, vz);
} else {
printf("Invalid number of atoms per unit cell, must be: 4, 8 or 16\n");
return EXIT_FAILURE;
}
} }
} }
} }
printf("Initializing neighbor lists...\n"); const double estim_volume = (double)(atom->Nlocal * 6 * sizeof(MD_FLOAT) + (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);
printf("Estimated memory volume (kB): %.4f\n", estim_volume);
DEBUG("Initializing neighbor lists...\n");
initNeighbor(&neighbor, &param); initNeighbor(&neighbor, &param);
printf("Setting up neighbor lists...\n"); DEBUG("Setting up neighbor lists...\n");
setupNeighbor(); setupNeighbor();
printf("Building neighbor lists...\n"); DEBUG("Building neighbor lists...\n");
buildNeighbor(atom, &neighbor); buildNeighbor(atom, &neighbor);
printf("Computing forces...\n"); DEBUG("Computing forces...\n");
computeForce(&param, atom, &neighbor); computeForce(&param, atom, &neighbor, 0);
double T_accum = 0.0;
for(int i = 0; i < param.ntimes; i++) {
T_accum += computeForce(&param, atom, &neighbor, 1);
}
printf("Total time: %.4f, Time/force: %.4f\n", T_accum, T_accum / param.ntimes);
LIKWID_MARKER_CLOSE; LIKWID_MARKER_CLOSE;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }