From 6679b6c8aa1e8cc3bc917bf0e794aa1eaba9634b Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Tue, 23 Mar 2021 09:26:41 +0100 Subject: [PATCH] Simplify macros for data structure access. Still segvaults for AoS. --- Makefile | 2 +- include_CLANG.mk | 6 +++--- src/atom.c | 12 +++++++----- src/includes/atom.h | 25 +++++++------------------ src/main.c | 18 +++++++++--------- src/neighbor.c | 16 ++++++++-------- src/pbc.c | 30 +++++++++++++++--------------- 7 files changed, 50 insertions(+), 59 deletions(-) diff --git a/Makefile b/Makefile index 7727bfe..4275bf1 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ TARGET = MDBench-$(TAG) BUILD_DIR = ./$(TAG) SRC_DIR = ./src MAKE_DIR = ./ -FLAGS = #-DAOS +FLAGS = -DAOS Q ?= @ #DO NOT EDIT BELOW diff --git a/include_CLANG.mk b/include_CLANG.mk index 68e0076..93c499c 100644 --- a/include_CLANG.mk +++ b/include_CLANG.mk @@ -1,5 +1,5 @@ CC = cc -CXX = cc +CXX = gcc LINKER = $(CC) ANSI_CFLAGS = -ansi @@ -7,11 +7,11 @@ ANSI_CFLAGS += -std=c99 ANSI_CFLAGS += -pedantic ANSI_CFLAGS += -Wextra -CFLAGS = -Ofast $(ANSI_CFLAGS) -Xpreprocessor -fopenmp #-g +CFLAGS = -Ofast $(ANSI_CFLAGS) -g #-Xpreprocessor -fopenmp -g ASFLAGS = -masm=intel CXXFLAGS = $(CFLAGS) FCFLAGS = LFLAGS = DEFINES = -D_GNU_SOURCE -DALIGNMENT=64 -DPRECISION=2 INCLUDES = -LIBS = -lomp +LIBS = #-lomp diff --git a/src/atom.c b/src/atom.c index f70bc35..687de55 100644 --- a/src/atom.c +++ b/src/atom.c @@ -1,8 +1,10 @@ /* * ======================================================================================= * - * Author: Jan Eitzinger (je), jan.eitzinger@fau.de - * Copyright (c) 2020 RRZE, University Erlangen-Nuremberg + * Authors: Jan Eitzinger (je), jan.eitzinger@fau.de + * Rafael Ravedutti (rr), rafaelravedutti@gmail.com + * + * Copyright (c) 2021 RRZE, University Erlangen-Nuremberg * * This file is part of MD-Bench. * @@ -111,9 +113,9 @@ void createAtom(Atom *atom, Parameter *param) growAtom(atom); } - set_atom_x(atom, atom->Nlocal, xtmp); - set_atom_y(atom, atom->Nlocal, ytmp); - set_atom_z(atom, atom->Nlocal, ztmp); + atom_x(atom->Nlocal) = xtmp; + atom_y(atom->Nlocal) = ytmp; + atom_z(atom->Nlocal) = ztmp; atom->vx[atom->Nlocal] = vxtmp; atom->vy[atom->Nlocal] = vytmp; atom->vz[atom->Nlocal] = vztmp; diff --git a/src/includes/atom.h b/src/includes/atom.h index 72fce88..abc425e 100644 --- a/src/includes/atom.h +++ b/src/includes/atom.h @@ -2,7 +2,7 @@ * ======================================================================================= * * Author: Jan Eitzinger (je), jan.eitzinger@fau.de - * Copyright (c) 2020 RRZE, University Erlangen-Nuremberg + * Copyright (c) 2021 RRZE, University Erlangen-Nuremberg * * This file is part of MD-Bench. * @@ -38,25 +38,14 @@ extern void growAtom(Atom*); #ifdef AOS #define POS_DATA_LAYOUT "AoS" -/* FIXME: these macros are resulting in segfault -#define set_atom_x(atom, i, v) (atom->x[i * 3 + 0] = v) -#define set_atom_y(atom, i, v) (atom->x[i * 3 + 1] = v) -#define set_atom_z(atom, i, v) (atom->x[i * 3 + 2] = v) -*/ -inline void set_atom_x(Atom *atom, int i, MD_FLOAT x) { atom->x[i * 3 + 0] = x; } -inline void set_atom_y(Atom *atom, int i, MD_FLOAT y) { atom->x[i * 3 + 1] = y; } -inline void set_atom_z(Atom *atom, int i, MD_FLOAT z) { atom->x[i * 3 + 2] = z; } -#define get_atom_x(atom, i) (atom->x[i * 3 + 0]) -#define get_atom_y(atom, i) (atom->x[i * 3 + 1]) -#define get_atom_z(atom, i) (atom->x[i * 3 + 2]) +#define atom_x(i) atom->x[i * 3 + 0] +#define atom_y(i) atom->x[i * 3 + 1] +#define atom_z(i) atom->x[i * 3 + 2] #else #define POS_DATA_LAYOUT "SoA" -#define set_atom_x(atom, i, v) (atom->x[i] = v) -#define set_atom_y(atom, i, v) (atom->y[i] = v) -#define set_atom_z(atom, i, v) (atom->z[i] = v) -#define get_atom_x(atom, i) (atom->x[i]) -#define get_atom_y(atom, i) (atom->y[i]) -#define get_atom_z(atom, i) (atom->z[i]) +#define atom_x(i) atom->x[i] +#define atom_y(i) atom->y[i] +#define atom_z(i) atom->z[i] #endif #endif diff --git a/src/main.c b/src/main.c index 27a3f4f..c064815 100644 --- a/src/main.c +++ b/src/main.c @@ -123,9 +123,9 @@ void initialIntegrate(Parameter *param, Atom *atom) vx[i] += param->dtforce * fx[i]; vy[i] += param->dtforce * fy[i]; vz[i] += param->dtforce * fz[i]; - set_atom_x(atom, i, get_atom_x(atom, i) + param->dt * vx[i]); - set_atom_y(atom, i, get_atom_y(atom, i) + param->dt * vy[i]); - set_atom_z(atom, i, get_atom_z(atom, i) + param->dt * vz[i]); + 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]; } } @@ -164,9 +164,9 @@ double computeForce(Parameter *param, Atom *atom, Neighbor *neighbor) for(int i = 0; i < Nlocal; i++) { neighs = &neighbor->neighbors[i * neighbor->maxneighs]; int numneighs = neighbor->numneigh[i]; - MD_FLOAT xtmp = get_atom_x(atom, i); - MD_FLOAT ytmp = get_atom_y(atom, i); - MD_FLOAT ztmp = get_atom_z(atom, i); + MD_FLOAT xtmp = atom_x(i); + MD_FLOAT ytmp = atom_y(i); + MD_FLOAT ztmp = atom_z(i); MD_FLOAT fix = 0; MD_FLOAT fiy = 0; @@ -174,9 +174,9 @@ double computeForce(Parameter *param, Atom *atom, Neighbor *neighbor) for(int k = 0; k < numneighs; k++) { int j = neighs[k]; - MD_FLOAT delx = xtmp - get_atom_x(atom, j); - MD_FLOAT dely = ytmp - get_atom_y(atom, j); - MD_FLOAT delz = ztmp - get_atom_z(atom, j); + MD_FLOAT delx = xtmp - atom_x(j); + MD_FLOAT dely = ytmp - atom_y(j); + MD_FLOAT delz = ztmp - atom_z(j); MD_FLOAT rsq = delx * delx + dely * dely + delz * delz; if(rsq < cutforcesq) { diff --git a/src/neighbor.c b/src/neighbor.c index fc80909..05591ed 100644 --- a/src/neighbor.c +++ b/src/neighbor.c @@ -2,7 +2,7 @@ * ======================================================================================= * * Author: Jan Eitzinger (je), jan.eitzinger@fau.de - * Copyright (c) 2020 RRZE, University Erlangen-Nuremberg + * Copyright (c) 2021 RRZE, University Erlangen-Nuremberg * * This file is part of MD-Bench. * @@ -193,9 +193,9 @@ void buildNeighbor(Atom *atom, Neighbor *neighbor) for(int i = 0; i < atom->Nlocal; i++) { int* neighptr = &(neighbor->neighbors[i * neighbor->maxneighs]); int n = 0; - MD_FLOAT xtmp = get_atom_x(atom, i); - MD_FLOAT ytmp = get_atom_y(atom, i); - MD_FLOAT ztmp = get_atom_z(atom, i); + MD_FLOAT xtmp = atom_x(i); + MD_FLOAT ytmp = atom_y(i); + MD_FLOAT ztmp = atom_z(i); int ibin = coord2bin(xtmp, ytmp, ztmp); for(int k = 0; k < nstencil; k++) { @@ -209,9 +209,9 @@ void buildNeighbor(Atom *atom, Neighbor *neighbor) continue; } - MD_FLOAT delx = xtmp - get_atom_x(atom, j); - MD_FLOAT dely = ytmp - get_atom_y(atom, j); - MD_FLOAT delz = ztmp - get_atom_z(atom, j); + MD_FLOAT delx = xtmp - atom_x(j); + MD_FLOAT dely = ytmp - atom_y(j); + MD_FLOAT delz = ztmp - atom_z(j); MD_FLOAT rsq = delx * delx + dely * dely + delz * delz; if( rsq <= cutneighsq ) { @@ -316,7 +316,7 @@ void binatoms(Atom *atom) } for(int i = 0; i < nall; i++) { - int ibin = coord2bin(get_atom_x(atom, i), get_atom_y(atom, i), get_atom_z(atom, i)); + int ibin = coord2bin(atom_x(i), atom_y(i), atom_z(i)); if(bincount[ibin] < atoms_per_bin) { int ac = bincount[ibin]++; diff --git a/src/pbc.c b/src/pbc.c index 7631e16..a32faf8 100644 --- a/src/pbc.c +++ b/src/pbc.c @@ -53,9 +53,9 @@ void updatePbc(Atom *atom, Parameter *param) MD_FLOAT zprd = param->zprd; for(int i = 0; i < atom->Nghost; i++) { - set_atom_x(atom, nlocal + i, get_atom_x(atom, BorderMap[i]) + PBCx[i] * xprd); - set_atom_y(atom, nlocal + i, get_atom_y(atom, BorderMap[i]) + PBCy[i] * yprd); - set_atom_z(atom, nlocal + i, get_atom_z(atom, BorderMap[i]) + PBCz[i] * zprd); + atom_x(nlocal + i) = atom_x(BorderMap[i]) + PBCx[i] * xprd; + atom_y(nlocal + i) = atom_y(BorderMap[i]) + PBCy[i] * yprd; + atom_z(nlocal + i) = atom_z(BorderMap[i]) + PBCz[i] * zprd; } } @@ -68,26 +68,26 @@ void updateAtomsPbc(Atom *atom, Parameter *param) MD_FLOAT zprd = param->zprd; for(int i = 0; i < atom->Nlocal; i++) { - MD_FLOAT x = get_atom_x(atom, i); - MD_FLOAT y = get_atom_y(atom, i); - MD_FLOAT z = get_atom_z(atom, i); + MD_FLOAT x = atom_x(i); + MD_FLOAT y = atom_y(i); + MD_FLOAT z = atom_z(i); if(x < 0.0) { - set_atom_x(atom, i, x + xprd); + atom_x(i) = x + xprd; } else if(x >= xprd) { - set_atom_x(atom, i, x - xprd); + atom_x(i) = x - xprd; } if(y < 0.0) { - set_atom_y(atom, i, y + yprd); + atom_y(i) = y + yprd; } else if(y >= yprd) { - set_atom_y(atom, i, y - yprd); + atom_y(i) = y - yprd; } if(z < 0.0) { - set_atom_z(atom, i, z + zprd); + atom_z(i) = z + zprd; } else if(z >= zprd) { - set_atom_z(atom, i, z - zprd); + atom_z(i) = z - zprd; } } } @@ -114,9 +114,9 @@ void setupPbc(Atom *atom, Parameter *param) growPbc(); } - MD_FLOAT x = get_atom_x(atom, i); - MD_FLOAT y = get_atom_y(atom, i); - MD_FLOAT z = get_atom_z(atom, i); + MD_FLOAT x = atom_x(i); + MD_FLOAT y = atom_y(i); + MD_FLOAT z = atom_z(i); /* Setup ghost atoms */ /* 6 planes */