2020-08-11 16:34:22 +02:00
|
|
|
/*
|
2022-09-05 10:39:42 +02:00
|
|
|
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
|
|
|
* All rights reserved. This file is part of MD-Bench.
|
|
|
|
* Use of this source code is governed by a LGPL-3.0
|
|
|
|
* license that can be found in the LICENSE file.
|
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-18 14:27:28 +02:00
|
|
|
#include <allocate.h>
|
|
|
|
#include <atom.h>
|
2022-08-12 18:12:29 +02:00
|
|
|
#include <device.h>
|
|
|
|
#include <eam.h>
|
|
|
|
#include <integrate.h>
|
2020-08-18 14:27:28 +02:00
|
|
|
#include <thermo.h>
|
2022-08-12 18:12:29 +02:00
|
|
|
#include <timing.h>
|
|
|
|
#include <neighbor.h>
|
|
|
|
#include <parameter.h>
|
2020-08-18 14:27:28 +02:00
|
|
|
#include <pbc.h>
|
2022-08-12 18:12:29 +02:00
|
|
|
#include <stats.h>
|
2021-10-12 22:39:54 +02:00
|
|
|
#include <timers.h>
|
2021-12-01 00:07:45 +01:00
|
|
|
#include <util.h>
|
2022-08-12 18:12:29 +02:00
|
|
|
#include <vtk.h>
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2020-08-11 16:34:22 +02:00
|
|
|
#define HLINE "----------------------------------------------------------------------------\n"
|
|
|
|
|
2022-04-05 02:57:23 +02:00
|
|
|
extern double computeForceLJFullNeigh_plain_c(Parameter*, Atom*, Neighbor*, Stats*);
|
|
|
|
extern double computeForceLJFullNeigh_simd(Parameter*, Atom*, Neighbor*, Stats*);
|
2022-03-10 16:30:37 +01:00
|
|
|
extern double computeForceLJHalfNeigh(Parameter*, Atom*, Neighbor*, Stats*);
|
2021-12-01 00:07:45 +01:00
|
|
|
extern double computeForceEam(Eam*, Parameter*, Atom*, Neighbor*, Stats*);
|
2022-07-07 00:47:38 +02:00
|
|
|
extern double computeForceDemFullNeigh(Parameter*, Atom*, Neighbor*, Stats*);
|
2020-08-14 08:32:36 +02:00
|
|
|
|
2022-08-09 18:53:53 +02:00
|
|
|
#ifdef CUDA_TARGET
|
2022-08-12 17:28:06 +02:00
|
|
|
extern double computeForceLJFullNeigh_cuda(Parameter*, Atom*, Neighbor*);
|
2022-04-05 02:57:23 +02:00
|
|
|
#endif
|
|
|
|
|
2022-08-12 17:28:06 +02:00
|
|
|
double setup(Parameter *param, Eam *eam, Atom *atom, Neighbor *neighbor, Stats *stats) {
|
2021-10-29 16:52:19 +02:00
|
|
|
if(param->force_field == FF_EAM) { initEam(eam, param); }
|
2020-08-19 09:22:43 +02:00
|
|
|
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);
|
2021-11-03 00:57:24 +01:00
|
|
|
initPbc(atom);
|
2021-10-12 15:04:08 +02:00
|
|
|
initStats(stats);
|
2021-11-30 01:33:55 +01:00
|
|
|
initNeighbor(neighbor, param);
|
|
|
|
if(param->input_file == NULL) {
|
|
|
|
createAtom(atom, param);
|
|
|
|
} else {
|
|
|
|
readAtom(atom, param);
|
|
|
|
}
|
2022-03-17 02:44:34 +01:00
|
|
|
|
2021-11-30 01:33:55 +01:00
|
|
|
setupNeighbor(param);
|
2020-08-19 09:00:35 +02:00
|
|
|
setupThermo(param, atom->Natoms);
|
2021-11-30 01:33:55 +01:00
|
|
|
if(param->input_file == NULL) { adjustThermo(param, atom); }
|
2020-08-19 09:00:35 +02:00
|
|
|
setupPbc(atom, param);
|
2022-08-12 18:12:29 +02:00
|
|
|
initDevice(atom, neighbor);
|
2022-08-12 17:28:06 +02:00
|
|
|
updatePbc(atom, param, true);
|
|
|
|
buildNeighbor(atom, neighbor);
|
2020-08-19 09:22:43 +02:00
|
|
|
E = getTimeStamp();
|
|
|
|
return E-S;
|
|
|
|
}
|
|
|
|
|
2022-08-12 17:28:06 +02:00
|
|
|
double reneighbour(Parameter *param, Atom *atom, Neighbor *neighbor) {
|
2020-08-19 09:22:43 +02:00
|
|
|
double S, E;
|
|
|
|
S = getTimeStamp();
|
2020-11-05 12:41:44 +01:00
|
|
|
LIKWID_MARKER_START("reneighbour");
|
2022-08-12 17:28:06 +02:00
|
|
|
updateAtomsPbc(atom, param);
|
2020-08-19 09:22:43 +02:00
|
|
|
setupPbc(atom, param);
|
2022-08-12 17:28:06 +02:00
|
|
|
updatePbc(atom, param, true);
|
2021-11-03 00:57:24 +01:00
|
|
|
//sortAtom(atom);
|
2022-08-12 17:28:06 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-03-17 02:44:34 +01:00
|
|
|
void printAtomState(Atom *atom) {
|
2022-07-07 00:47:38 +02:00
|
|
|
printf("Atom counts: Natoms=%d Nlocal=%d Nghost=%d Nmax=%d\n", atom->Natoms, atom->Nlocal, atom->Nghost, atom->Nmax);
|
|
|
|
// int nall = atom->Nlocal + atom->Nghost;
|
|
|
|
// for (int i=0; i<nall; i++) {
|
|
|
|
// printf("%d %f %f %f\n", i, atom->x[i], atom->y[i], atom->z[i]);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
2022-08-12 17:28:06 +02:00
|
|
|
double computeForce(Eam *eam, Parameter *param, Atom *atom, Neighbor *neighbor, Stats *stats) {
|
2022-07-07 00:47:38 +02:00
|
|
|
if(param->force_field == FF_EAM) {
|
|
|
|
return computeForceEam(eam, param, atom, neighbor, stats);
|
|
|
|
} else if(param->force_field == FF_DEM) {
|
|
|
|
if(param->half_neigh) {
|
2022-07-13 02:34:33 +02:00
|
|
|
fprintf(stderr, "Error: DEM cannot use half neighbor-lists!\n");
|
|
|
|
return 0.0;
|
2022-07-07 00:47:38 +02:00
|
|
|
} else {
|
|
|
|
return computeForceDemFullNeigh(param, atom, neighbor, stats);
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2022-07-07 00:47:38 +02:00
|
|
|
if(param->half_neigh) {
|
|
|
|
return computeForceLJHalfNeigh(param, atom, neighbor, stats);
|
|
|
|
}
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2022-08-09 18:53:53 +02:00
|
|
|
#ifdef CUDA_TARGET
|
2022-08-12 17:28:06 +02:00
|
|
|
return computeForceLJFullNeigh(param, atom, neighbor);
|
2022-08-09 18:53:53 +02:00
|
|
|
#else
|
2022-07-07 00:47:38 +02:00
|
|
|
return computeForceLJFullNeigh(param, atom, neighbor, stats);
|
2022-08-09 18:53:53 +02:00
|
|
|
#endif
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 02:44:34 +01:00
|
|
|
int main(int argc, char** argv) {
|
2020-08-19 09:00:35 +02:00
|
|
|
double timer[NUMTIMER];
|
2021-10-26 00:40:39 +02:00
|
|
|
Eam eam;
|
2022-08-12 17:28:06 +02:00
|
|
|
Atom atom;
|
|
|
|
Neighbor neighbor;
|
2021-10-12 15:04:08 +02:00
|
|
|
Stats stats;
|
2020-08-11 16:34:22 +02:00
|
|
|
Parameter param;
|
|
|
|
|
2020-11-05 12:41:44 +01:00
|
|
|
LIKWID_MARKER_INIT;
|
|
|
|
#pragma omp parallel
|
|
|
|
{
|
|
|
|
LIKWID_MARKER_REGISTER("force");
|
2021-07-16 00:24:43 +02:00
|
|
|
//LIKWID_MARKER_REGISTER("reneighbour");
|
|
|
|
//LIKWID_MARKER_REGISTER("pbc");
|
2020-11-05 12:41:44 +01:00
|
|
|
}
|
2020-08-19 09:00:35 +02:00
|
|
|
|
2022-03-17 02:44:34 +01:00
|
|
|
initParameter(¶m);
|
|
|
|
for(int i = 0; i < argc; i++) {
|
|
|
|
if((strcmp(argv[i], "-p") == 0)) {
|
|
|
|
readParameter(¶m, argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "-f") == 0)) {
|
2021-10-26 00:40:39 +02:00
|
|
|
if((param.force_field = str2ff(argv[++i])) < 0) {
|
|
|
|
fprintf(stderr, "Invalid force field!\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "-i") == 0)) {
|
2021-10-26 00:40:39 +02:00
|
|
|
param.input_file = strdup(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "-e") == 0)) {
|
2021-11-30 01:33:55 +01:00
|
|
|
param.eam_file = strdup(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "-n") == 0) || (strcmp(argv[i], "--nsteps") == 0)) {
|
2020-08-19 09:00:35 +02:00
|
|
|
param.ntimes = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "-nx") == 0)) {
|
2020-08-19 09:00:35 +02:00
|
|
|
param.nx = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "-ny") == 0)) {
|
2020-08-19 09:00:35 +02:00
|
|
|
param.ny = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "-nz") == 0)) {
|
2020-08-19 09:00:35 +02:00
|
|
|
param.nz = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-03-18 01:28:11 +01:00
|
|
|
if((strcmp(argv[i], "-half") == 0)) {
|
|
|
|
param.half_neigh = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "-r") == 0) || (strcmp(argv[i], "--radius") == 0)) {
|
|
|
|
param.cutforce = atof(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--skin") == 0)) {
|
|
|
|
param.skin = atof(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((strcmp(argv[i], "--freq") == 0)) {
|
2021-10-12 15:04:08 +02:00
|
|
|
param.proc_freq = atof(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "--vtk") == 0)) {
|
2021-10-29 16:52:19 +02:00
|
|
|
param.vtk_file = strdup(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-28 22:34:42 +01:00
|
|
|
if((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)) {
|
2020-08-19 09:00:35 +02:00
|
|
|
printf("MD Bench: A minimalistic re-implementation of miniMD\n");
|
|
|
|
printf(HLINE);
|
2022-03-17 02:44:34 +01:00
|
|
|
printf("-p <string>: file to read parameters from (can be specified more than once)\n");
|
2022-07-07 00:47:38 +02:00
|
|
|
printf("-f <string>: force field (lj, eam or dem), default lj\n");
|
2021-11-30 01:33:55 +01:00
|
|
|
printf("-i <string>: input file with atom positions (dump)\n");
|
|
|
|
printf("-e <string>: input file for EAM\n");
|
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");
|
2022-02-28 22:34:42 +01:00
|
|
|
printf("-r / --radius <real>: set cutoff radius\n");
|
|
|
|
printf("-s / --skin <real>: set skin (verlet buffer)\n");
|
2021-10-26 00:40:39 +02:00
|
|
|
printf("--freq <real>: processor frequency (GHz)\n");
|
2021-10-29 16:52:19 +02:00
|
|
|
printf("--vtk <string>: VTK file for visualization\n");
|
2020-08-19 09:00:35 +02:00
|
|
|
printf(HLINE);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 22:34:42 +01:00
|
|
|
param.cutneigh = param.cutforce + param.skin;
|
2022-08-12 17:28:06 +02:00
|
|
|
setup(¶m, &eam, &atom, &neighbor, &stats);
|
2022-03-17 02:44:34 +01:00
|
|
|
printParameter(¶m);
|
2022-08-16 18:36:47 +02:00
|
|
|
printf(HLINE);
|
2022-03-17 02:44:34 +01:00
|
|
|
|
|
|
|
printf("step\ttemp\t\tpressure\n");
|
2020-08-18 14:27:28 +02:00
|
|
|
computeThermo(0, ¶m, &atom);
|
2022-08-09 18:53:53 +02:00
|
|
|
#if defined(MEM_TRACER) || defined(INDEX_TRACER)
|
2021-12-01 00:07:45 +01:00
|
|
|
traceAddresses(¶m, &atom, &neighbor, n + 1);
|
2022-08-09 18:53:53 +02:00
|
|
|
#endif
|
2020-08-11 16:34:22 +02:00
|
|
|
|
2022-08-12 17:28:06 +02:00
|
|
|
timer[FORCE] = computeForce(&eam, ¶m, &atom, &neighbor, &stats);
|
2020-08-19 09:22:43 +02:00
|
|
|
timer[NEIGH] = 0.0;
|
|
|
|
timer[TOTAL] = getTimeStamp();
|
|
|
|
|
2021-10-29 16:52:19 +02:00
|
|
|
if(param.vtk_file != NULL) {
|
|
|
|
write_atoms_to_vtk_file(param.vtk_file, &atom, 0);
|
|
|
|
}
|
|
|
|
|
2020-08-11 16:34:22 +02:00
|
|
|
for(int n = 0; n < param.ntimes; n++) {
|
2022-08-09 18:53:53 +02:00
|
|
|
bool reneigh = (n + 1) % param.reneigh_every == 0;
|
2022-08-12 17:28:06 +02:00
|
|
|
initialIntegrate(reneigh, ¶m, &atom);
|
2022-03-17 02:44:34 +01:00
|
|
|
if((n + 1) % param.reneigh_every) {
|
2022-08-12 17:28:06 +02:00
|
|
|
updatePbc(&atom, ¶m, false);
|
2020-08-17 14:01:46 +02:00
|
|
|
} else {
|
2022-08-12 17:28:06 +02:00
|
|
|
timer[NEIGH] += reneighbour(¶m, &atom, &neighbor);
|
2020-08-11 16:34:22 +02:00
|
|
|
}
|
|
|
|
|
2022-08-09 18:53:53 +02:00
|
|
|
#if defined(MEM_TRACER) || defined(INDEX_TRACER)
|
2021-12-01 00:07:45 +01:00
|
|
|
traceAddresses(¶m, &atom, &neighbor, n + 1);
|
2022-08-09 18:53:53 +02:00
|
|
|
#endif
|
2021-12-01 00:07:45 +01:00
|
|
|
|
2022-08-12 17:28:06 +02:00
|
|
|
timer[FORCE] += computeForce(&eam, ¶m, &atom, &neighbor, &stats);
|
|
|
|
finalIntegrate(reneigh, ¶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) {
|
2022-08-09 18:53:53 +02:00
|
|
|
#ifdef CUDA_TARGET
|
2022-08-12 17:28:06 +02:00
|
|
|
memcpyFromGPU(atom.x, atom.d_atom.x, atom.Nmax * sizeof(MD_FLOAT) * 3);
|
2022-08-09 18:53:53 +02:00
|
|
|
#endif
|
2020-08-18 14:27:28 +02:00
|
|
|
computeThermo(n + 1, ¶m, &atom);
|
2020-08-11 16:34:22 +02:00
|
|
|
}
|
2021-10-29 16:52:19 +02:00
|
|
|
|
|
|
|
if(param.vtk_file != NULL) {
|
|
|
|
write_atoms_to_vtk_file(param.vtk_file, &atom, n + 1);
|
|
|
|
}
|
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-11-05 12:41:44 +01:00
|
|
|
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]);
|
2021-10-26 09:16:31 +02:00
|
|
|
#ifdef COMPUTE_STATS
|
2021-10-12 22:39:54 +02:00
|
|
|
displayStatistics(&atom, ¶m, &stats, timer);
|
2021-10-26 09:11:17 +02:00
|
|
|
#endif
|
2020-11-05 12:41:44 +01:00
|
|
|
LIKWID_MARKER_CLOSE;
|
2020-08-11 16:34:22 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|