Add version with stubbed force calculation
Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com>
This commit is contained in:
parent
2bc3120112
commit
7efd30791a
28
Makefile
28
Makefile
@ -1,10 +1,12 @@
|
||||
#CONFIGURE BUILD SYSTEM
|
||||
TARGET = MDBench-$(TAG)
|
||||
BUILD_DIR = ./$(TAG)
|
||||
SRC_DIR = ./src
|
||||
SRC_DIR = ./src/core
|
||||
MAKE_DIR = ./
|
||||
Q ?= @
|
||||
|
||||
TARGET_MDBENCH = MDBench-$(TAG)
|
||||
TARGET_STUB = stub
|
||||
|
||||
#DO NOT EDIT BELOW
|
||||
include $(MAKE_DIR)/config.mk
|
||||
include $(MAKE_DIR)/include_$(TAG).mk
|
||||
@ -24,12 +26,28 @@ ASM = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.s,$(wildcard $(SRC_DIR)/*.
|
||||
OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c))
|
||||
CPPFLAGS := $(CPPFLAGS) $(DEFINES) $(OPTIONS) $(INCLUDES)
|
||||
|
||||
${TARGET}: $(BUILD_DIR) $(OBJ)
|
||||
@echo "===> LINKING $(TARGET)"
|
||||
$(Q)${LINKER} ${LFLAGS} -o $(TARGET) $(OBJ) $(LIBS)
|
||||
all: ${TARGET_MDBENCH} ${TARGET_STUB}
|
||||
|
||||
${TARGET_MDBENCH}: $(BUILD_DIR) $(OBJ) $(BUILD_DIR)/main.o
|
||||
@echo "===> LINKING $(TARGET_MDBENCH)"
|
||||
$(Q)${LINKER} ${LFLAGS} -o $(TARGET_MDBENCH) $(OBJ) $(BUILD_DIR)/main.o $(LIBS)
|
||||
|
||||
${TARGET_STUB}: $(BUILD_DIR) $(OBJ) $(BUILD_DIR)/stub.o
|
||||
@echo "===> LINKING $(TARGET_STUB)"
|
||||
$(Q)${LINKER} ${LFLAGS} -o $(TARGET_STUB) $(OBJ) $(BUILD_DIR)/stub.o $(LIBS)
|
||||
|
||||
asm: $(BUILD_DIR) $(ASM)
|
||||
|
||||
$(BUILD_DIR)/main.o: ./src/main.c
|
||||
@echo "===> COMPILE $@"
|
||||
$(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
|
||||
$(Q)$(CC) $(CPPFLAGS) -MT $(@:.d=.o) -MM $< > $(BUILD_DIR)/main.d
|
||||
|
||||
$(BUILD_DIR)/stub.o: ./src/stub.c
|
||||
@echo "===> COMPILE $@"
|
||||
$(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
|
||||
$(Q)$(CC) $(CPPFLAGS) -MT $(@:.d=.o) -MM $< > $(BUILD_DIR)/stub.d
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c
|
||||
@echo "===> COMPILE $@"
|
||||
$(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
|
||||
|
@ -53,11 +53,10 @@ static MD_FLOAT bindist(int, int, int);
|
||||
/* exported subroutines */
|
||||
void initNeighbor(Neighbor *neighbor, Parameter *param)
|
||||
{
|
||||
MD_FLOAT lattice = pow((4.0 / param->rho), (1.0 / 3.0));
|
||||
MD_FLOAT neighscale = 5.0 / 6.0;
|
||||
xprd = param->nx * lattice;
|
||||
yprd = param->ny * lattice;
|
||||
zprd = param->nz * lattice;
|
||||
xprd = param->nx * param->lattice;
|
||||
yprd = param->ny * param->lattice;
|
||||
zprd = param->nz * param->lattice;
|
||||
cutneigh = param->cutneigh;
|
||||
nbinx = neighscale * param->nx;
|
||||
nbiny = neighscale * param->ny;
|
@ -43,6 +43,7 @@ typedef struct {
|
||||
MD_FLOAT cutforce;
|
||||
MD_FLOAT cutneigh;
|
||||
int nx, ny, nz;
|
||||
MD_FLOAT lattice;
|
||||
MD_FLOAT xprd, yprd, zprd;
|
||||
} Parameter;
|
||||
#endif
|
||||
|
@ -74,10 +74,10 @@ double setup(
|
||||
Neighbor *neighbor)
|
||||
{
|
||||
double S, E;
|
||||
double lattice = pow((4.0 / param->rho), (1.0 / 3.0));
|
||||
param->xprd = param->nx * lattice;
|
||||
param->yprd = param->ny * lattice;
|
||||
param->zprd = param->nz * lattice;
|
||||
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;
|
||||
|
||||
S = getTimeStamp();
|
||||
initAtom(atom);
|
||||
|
143
src/stub.c
Normal file
143
src/stub.c
Normal file
@ -0,0 +1,143 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
//---
|
||||
#include <likwid-marker.h>
|
||||
//---
|
||||
#include <timing.h>
|
||||
#include <allocate.h>
|
||||
#include <neighbor.h>
|
||||
#include <parameter.h>
|
||||
#include <atom.h>
|
||||
#include <thermo.h>
|
||||
#include <pbc.h>
|
||||
|
||||
#define HLINE "----------------------------------------------------------------------------\n"
|
||||
|
||||
#define LATTICE_DISTANCE 10.0
|
||||
#define NEIGH_DISTANCE 1.0
|
||||
#define NX 4
|
||||
#define NY 4
|
||||
#define NZ 2
|
||||
|
||||
extern double computeForce( Parameter*, Atom*, Neighbor*);
|
||||
|
||||
void init(Parameter *param) {
|
||||
param->epsilon = 1.0;
|
||||
param->sigma6 = 1.0;
|
||||
param->rho = 0.8442;
|
||||
param->ntimes = 200;
|
||||
param->nx = NX;
|
||||
param->ny = NY;
|
||||
param->nz = NZ;
|
||||
param->lattice = LATTICE_DISTANCE;
|
||||
param->xprd = NX * LATTICE_DISTANCE;
|
||||
param->yprd = NY * LATTICE_DISTANCE;
|
||||
param->zprd = NZ * LATTICE_DISTANCE;
|
||||
param->cutforce = 5.0;
|
||||
param->cutneigh = param->cutforce;
|
||||
param->mass = 1.0;
|
||||
// Unused
|
||||
param->dt = 0.005;
|
||||
param->dtforce = 0.5 * param->dt;
|
||||
param->nstat = 100;
|
||||
param->temp = 1.44;
|
||||
param->every = 20;
|
||||
}
|
||||
|
||||
#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_z(atom->Nlocal) = base_z + z * NEIGH_DISTANCE; \
|
||||
atom->vx[atom->Nlocal] = vy; \
|
||||
atom->vy[atom->Nlocal] = vy; \
|
||||
atom->vz[atom->Nlocal] = vz; \
|
||||
atom->Nlocal++
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
Atom atom_data;
|
||||
Atom *atom = (Atom *)(&atom_data);
|
||||
Neighbor neighbor;
|
||||
Parameter param;
|
||||
|
||||
LIKWID_MARKER_INIT;
|
||||
LIKWID_MARKER_REGISTER("force");
|
||||
printf("Initializing parameters...\n");
|
||||
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);
|
||||
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");
|
||||
printf(HLINE);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Initializing atoms...\n");
|
||||
initAtom(atom);
|
||||
|
||||
printf("Creating atoms...\n");
|
||||
// Neighbors per atom
|
||||
// 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 j = 0; j < NY; ++j) {
|
||||
for(int k = 0; k < NZ; ++k) {
|
||||
MD_FLOAT base_x = i * LATTICE_DISTANCE;
|
||||
MD_FLOAT base_y = j * LATTICE_DISTANCE;
|
||||
MD_FLOAT base_z = k * LATTICE_DISTANCE;
|
||||
MD_FLOAT vx = 0.0;
|
||||
MD_FLOAT vy = 0.0;
|
||||
MD_FLOAT vz = 0.0;
|
||||
|
||||
while(atom->Nlocal > atom->Nmax - atoms_per_unit_cell) {
|
||||
growAtom(atom);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Initializing neighbor lists...\n");
|
||||
initNeighbor(&neighbor, ¶m);
|
||||
printf("Setting up neighbor lists...\n");
|
||||
setupNeighbor();
|
||||
printf("Building neighbor lists...\n");
|
||||
buildNeighbor(atom, &neighbor);
|
||||
printf("Computing forces...\n");
|
||||
computeForce(¶m, atom, &neighbor);
|
||||
LIKWID_MARKER_CLOSE;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user