2020-08-11 16:34:22 +02:00
|
|
|
/*
|
|
|
|
* =======================================================================================
|
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* Author: Jan Eitzinger (je), jan.eitzinger@fau.de
|
|
|
|
* Copyright (c) 2020 RRZE, University Erlangen-Nuremberg
|
2020-08-11 16:34:22 +02:00
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* This file is part of MD-Bench.
|
2020-08-11 16:34:22 +02:00
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* MD-Bench is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-08-11 16:34:22 +02:00
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* MD-Bench is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
* details.
|
2020-08-11 16:34:22 +02:00
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
* with MD-Bench. If not, see <https://www.gnu.org/licenses/>.
|
2020-08-11 16:34:22 +02:00
|
|
|
* =======================================================================================
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
|
2020-11-05 12:41:44 +01:00
|
|
|
#include <likwid-marker.h>
|
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
#include <timing.h>
|
2020-08-18 14:27:28 +02:00
|
|
|
#include <allocate.h>
|
|
|
|
#include <neighbor.h>
|
|
|
|
#include <parameter.h>
|
|
|
|
#include <atom.h>
|
|
|
|
#include <thermo.h>
|
|
|
|
#include <pbc.h>
|
|
|
|
|
2020-08-11 16:34:22 +02:00
|
|
|
#define HLINE "----------------------------------------------------------------------------\n"
|
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
typedef enum {
|
|
|
|
TOTAL = 0,
|
|
|
|
NEIGH,
|
|
|
|
FORCE,
|
|
|
|
NUMTIMER
|
|
|
|
} timertype;
|
2020-08-11 16:34:22 +02:00
|
|
|
|
2021-03-30 22:17:30 +02:00
|
|
|
extern double computeForce( Parameter*, Atom*, Neighbor*, int);
|
2020-08-14 08:32:36 +02:00
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
void init(Parameter *param)
|
|
|
|
{
|
2020-08-11 16:34:22 +02:00
|
|
|
param->epsilon = 1.0;
|
|
|
|
param->sigma6 = 1.0;
|
|
|
|
param->rho = 0.8442;
|
|
|
|
param->ntimes = 200;
|
|
|
|
param->dt = 0.005;
|
|
|
|
param->nx = 32;
|
|
|
|
param->ny = 32;
|
|
|
|
param->nz = 32;
|
|
|
|
param->cutforce = 2.5;
|
2020-08-18 14:27:28 +02:00
|
|
|
param->cutneigh = param->cutforce + 0.30;
|
2020-08-11 16:34:22 +02:00
|
|
|
param->temp = 1.44;
|
|
|
|
param->nstat = 100;
|
|
|
|
param->mass = 1.0;
|
|
|
|
param->dtforce = 0.5 * param->dt;
|
2020-08-18 14:27:28 +02:00
|
|
|
param->every = 20;
|
2020-08-14 08:32:36 +02:00
|
|
|
}
|
|
|
|
|
2020-08-19 09:22:43 +02:00
|
|
|
double setup(
|
|
|
|
Parameter *param,
|
|
|
|
Atom *atom,
|
|
|
|
Neighbor *neighbor)
|
|
|
|
{
|
|
|
|
double S, E;
|
2021-03-30 01:54:56 +02:00
|
|
|
param->lattice = pow((4.0 / param->rho), (1.0 / 3.0));
|
|
|
|
param->xprd = param->nx * param->lattice;
|
|
|
|
param->yprd = param->ny * param->lattice;
|
|
|
|
param->zprd = param->nz * param->lattice;
|
2020-08-19 09:22:43 +02:00
|
|
|
|
|
|
|
S = getTimeStamp();
|
2020-08-19 09:00:35 +02:00
|
|
|
initAtom(atom);
|
|
|
|
initNeighbor(neighbor, param);
|
|
|
|
initPbc();
|
|
|
|
setupNeighbor();
|
|
|
|
createAtom(atom, param);
|
|
|
|
setupThermo(param, atom->Natoms);
|
|
|
|
adjustThermo(param, atom);
|
|
|
|
setupPbc(atom, param);
|
|
|
|
updatePbc(atom, param);
|
|
|
|
buildNeighbor(atom, neighbor);
|
2020-08-19 09:22:43 +02:00
|
|
|
E = getTimeStamp();
|
|
|
|
|
|
|
|
return E-S;
|
|
|
|
}
|
|
|
|
|
|
|
|
double reneighbour(
|
|
|
|
Parameter *param,
|
|
|
|
Atom *atom,
|
|
|
|
Neighbor *neighbor)
|
|
|
|
{
|
|
|
|
double S, E;
|
|
|
|
|
|
|
|
S = getTimeStamp();
|
2020-11-05 12:41:44 +01:00
|
|
|
LIKWID_MARKER_START("reneighbour");
|
2020-08-19 09:22:43 +02:00
|
|
|
updateAtomsPbc(atom, param);
|
|
|
|
setupPbc(atom, param);
|
|
|
|
updatePbc(atom, param);
|
|
|
|
/* sortAtom(); */
|
|
|
|
buildNeighbor(atom, neighbor);
|
2020-11-05 12:41:44 +01:00
|
|
|
LIKWID_MARKER_STOP("reneighbour");
|
2020-08-19 09:22:43 +02:00
|
|
|
E = getTimeStamp();
|
|
|
|
|
|
|
|
return E-S;
|
2020-08-19 09:00:35 +02:00
|
|
|
}
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
void initialIntegrate(Parameter *param, Atom *atom)
|
2020-08-14 08:32:36 +02:00
|
|
|
{
|
2020-11-05 12:41:44 +01:00
|
|
|
MD_FLOAT* fx = atom->fx; MD_FLOAT* fy = atom->fy; MD_FLOAT* fz = atom->fz;
|
|
|
|
MD_FLOAT* vx = atom->vx; MD_FLOAT* vy = atom->vy; MD_FLOAT* vz = atom->vz;
|
2020-08-11 16:34:22 +02:00
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
for(int i = 0; i < atom->Nlocal; i++) {
|
2020-08-11 16:34:22 +02:00
|
|
|
vx[i] += param->dtforce * fx[i];
|
|
|
|
vy[i] += param->dtforce * fy[i];
|
|
|
|
vz[i] += param->dtforce * fz[i];
|
2021-03-23 09:26:41 +01:00
|
|
|
atom_x(i) = atom_x(i) + param->dt * vx[i];
|
|
|
|
atom_y(i) = atom_y(i) + param->dt * vy[i];
|
|
|
|
atom_z(i) = atom_z(i) + param->dt * vz[i];
|
2020-08-11 16:34:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
void finalIntegrate(Parameter *param, Atom *atom)
|
2020-08-11 16:34:22 +02:00
|
|
|
{
|
2020-11-05 12:41:44 +01:00
|
|
|
MD_FLOAT* fx = atom->fx; MD_FLOAT* fy = atom->fy; MD_FLOAT* fz = atom->fz;
|
|
|
|
MD_FLOAT* vx = atom->vx; MD_FLOAT* vy = atom->vy; MD_FLOAT* vz = atom->vz;
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < atom->Nlocal; i++) {
|
2020-08-11 16:34:22 +02:00
|
|
|
vx[i] += param->dtforce * fx[i];
|
|
|
|
vy[i] += param->dtforce * fy[i];
|
|
|
|
vz[i] += param->dtforce * fz[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
void printAtomState(Atom *atom)
|
|
|
|
{
|
|
|
|
printf("Atom counts: Natoms=%d Nlocal=%d Nghost=%d Nmax=%d\n",
|
|
|
|
atom->Natoms, atom->Nlocal, atom->Nghost, atom->Nmax);
|
|
|
|
|
2020-08-19 10:00:19 +02:00
|
|
|
/* int nall = atom->Nlocal + atom->Nghost; */
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2020-08-19 10:00:19 +02:00
|
|
|
/* for (int i=0; i<nall; i++) { */
|
|
|
|
/* printf("%d %f %f %f\n", i, atom->x[i], atom->y[i], atom->z[i]); */
|
|
|
|
/* } */
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
2020-08-11 16:34:22 +02:00
|
|
|
int main (int argc, char** argv)
|
|
|
|
{
|
2020-08-19 09:00:35 +02:00
|
|
|
double timer[NUMTIMER];
|
2020-08-18 14:27:28 +02:00
|
|
|
Atom atom;
|
2020-08-11 16:34:22 +02:00
|
|
|
Neighbor neighbor;
|
|
|
|
Parameter param;
|
|
|
|
|
2020-11-05 12:41:44 +01:00
|
|
|
LIKWID_MARKER_INIT;
|
|
|
|
#pragma omp parallel
|
|
|
|
{
|
|
|
|
LIKWID_MARKER_REGISTER("force");
|
|
|
|
LIKWID_MARKER_REGISTER("reneighbour");
|
|
|
|
LIKWID_MARKER_REGISTER("pbc");
|
|
|
|
}
|
2020-08-19 09:00:35 +02:00
|
|
|
init(¶m);
|
|
|
|
|
|
|
|
for(int i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
if((strcmp(argv[i], "-n") == 0) || (strcmp(argv[i], "--nsteps") == 0))
|
|
|
|
{
|
|
|
|
param.ntimes = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((strcmp(argv[i], "-nx") == 0))
|
|
|
|
{
|
|
|
|
param.nx = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((strcmp(argv[i], "-ny") == 0))
|
|
|
|
{
|
|
|
|
param.ny = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((strcmp(argv[i], "-nz") == 0))
|
|
|
|
{
|
|
|
|
param.nz = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0))
|
|
|
|
{
|
|
|
|
printf("MD Bench: A minimalistic re-implementation of miniMD\n");
|
|
|
|
printf(HLINE);
|
2020-08-19 09:22:43 +02:00
|
|
|
printf("-n / --nsteps <int>: set number of timesteps for simulation\n");
|
|
|
|
printf("-nx/-ny/-nz <int>: set linear dimension of systembox in x/y/z direction\n");
|
2020-08-19 09:00:35 +02:00
|
|
|
printf(HLINE);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setup(¶m, &atom, &neighbor);
|
2020-08-18 14:27:28 +02:00
|
|
|
computeThermo(0, ¶m, &atom);
|
2021-03-30 22:17:30 +02:00
|
|
|
computeForce(¶m, &atom, &neighbor, 1);
|
2020-08-11 16:34:22 +02:00
|
|
|
|
2020-08-19 09:22:43 +02:00
|
|
|
timer[FORCE] = 0.0;
|
|
|
|
timer[NEIGH] = 0.0;
|
|
|
|
timer[TOTAL] = getTimeStamp();
|
|
|
|
|
2020-08-11 16:34:22 +02:00
|
|
|
for(int n = 0; n < param.ntimes; n++) {
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
initialIntegrate(¶m, &atom);
|
2020-08-11 16:34:22 +02:00
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
if((n + 1) % param.every) {
|
|
|
|
updatePbc(&atom, ¶m);
|
2020-08-17 14:01:46 +02:00
|
|
|
} else {
|
2020-08-19 09:22:43 +02:00
|
|
|
timer[NEIGH] += reneighbour(¶m, &atom, &neighbor);
|
2020-08-11 16:34:22 +02:00
|
|
|
}
|
|
|
|
|
2021-03-30 22:17:30 +02:00
|
|
|
timer[FORCE] += computeForce(¶m, &atom, &neighbor, 1);
|
2020-08-18 14:27:28 +02:00
|
|
|
finalIntegrate(¶m, &atom);
|
2020-08-11 16:34:22 +02:00
|
|
|
|
2020-08-17 14:01:46 +02:00
|
|
|
if(!((n + 1) % param.nstat) && (n+1) < param.ntimes) {
|
2020-08-18 14:27:28 +02:00
|
|
|
computeThermo(n + 1, ¶m, &atom);
|
2020-08-11 16:34:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 09:22:43 +02:00
|
|
|
timer[TOTAL] = getTimeStamp() - timer[TOTAL];
|
2020-08-18 14:27:28 +02:00
|
|
|
computeThermo(-1, ¶m, &atom);
|
2020-08-12 15:38:08 +02:00
|
|
|
|
2020-08-19 09:22:43 +02:00
|
|
|
printf(HLINE);
|
2021-03-22 21:51:47 +01:00
|
|
|
printf("Data layout for positions: %s\n", POS_DATA_LAYOUT);
|
2020-11-05 12:41:44 +01:00
|
|
|
#if PRECISION == 1
|
|
|
|
printf("Using single precision floating point.\n");
|
|
|
|
#else
|
|
|
|
printf("Using double precision floating point.\n");
|
|
|
|
#endif
|
|
|
|
printf(HLINE);
|
2020-08-19 10:00:19 +02:00
|
|
|
printf("System: %d atoms %d ghost atoms, Steps: %d\n", atom.Natoms, atom.Nghost, param.ntimes);
|
2020-08-19 09:22:43 +02:00
|
|
|
printf("TOTAL %.2fs FORCE %.2fs NEIGH %.2fs REST %.2fs\n",
|
|
|
|
timer[TOTAL], timer[FORCE], timer[NEIGH], timer[TOTAL]-timer[FORCE]-timer[NEIGH]);
|
|
|
|
printf(HLINE);
|
2020-08-19 10:00:19 +02:00
|
|
|
printf("Performance: %.2f million atom updates per second\n",
|
|
|
|
1e-6 * (double) atom.Natoms * param.ntimes / timer[TOTAL]);
|
2020-08-19 09:22:43 +02:00
|
|
|
|
2020-11-05 12:41:44 +01:00
|
|
|
LIKWID_MARKER_CLOSE;
|
2020-08-11 16:34:22 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|