diff --git a/Makefile b/Makefile index 90e3ce1..c91a710 100644 --- a/Makefile +++ b/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 $@ diff --git a/src/allocate.c b/src/core/allocate.c similarity index 100% rename from src/allocate.c rename to src/core/allocate.c diff --git a/src/atom.c b/src/core/atom.c similarity index 100% rename from src/atom.c rename to src/core/atom.c diff --git a/src/force.c b/src/core/force.c similarity index 100% rename from src/force.c rename to src/core/force.c diff --git a/src/neighbor.c b/src/core/neighbor.c similarity index 98% rename from src/neighbor.c rename to src/core/neighbor.c index 05591ed..72a6ee1 100644 --- a/src/neighbor.c +++ b/src/core/neighbor.c @@ -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; diff --git a/src/pbc.c b/src/core/pbc.c similarity index 100% rename from src/pbc.c rename to src/core/pbc.c diff --git a/src/thermo.c b/src/core/thermo.c similarity index 100% rename from src/thermo.c rename to src/core/thermo.c diff --git a/src/timing.c b/src/core/timing.c similarity index 100% rename from src/timing.c rename to src/core/timing.c diff --git a/src/util.c b/src/core/util.c similarity index 100% rename from src/util.c rename to src/core/util.c diff --git a/src/includes/parameter.h b/src/includes/parameter.h index 4f6f914..3bf8b9f 100644 --- a/src/includes/parameter.h +++ b/src/includes/parameter.h @@ -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 diff --git a/src/main.c b/src/main.c index 15d71fd..6b09c8e 100644 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/src/stub.c b/src/stub.c new file mode 100644 index 0000000..5d6ebf7 --- /dev/null +++ b/src/stub.c @@ -0,0 +1,143 @@ +#include +#include +//--- +#include +//--- +#include +#include +#include +#include +#include +#include +#include + +#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 : set number of timesteps for simulation\n"); + printf("-nx/-ny/-nz : 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; +}