Replace inline calls by macros

Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com>
This commit is contained in:
Rafael Ravedutti 2021-03-22 21:51:47 +01:00
parent 3f7edb5dbf
commit cb0ae2b0bb
2 changed files with 17 additions and 12 deletions

View File

@ -37,21 +37,26 @@ extern void createAtom(Atom*, Parameter*);
extern void growAtom(Atom*); extern void growAtom(Atom*);
#ifdef AOS #ifdef AOS
inline const char *posDataLayout() { return "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_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_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; } inline void set_atom_z(Atom *atom, int i, MD_FLOAT z) { atom->x[i * 3 + 2] = z; }
inline MD_FLOAT get_atom_x(Atom *atom, int i) { return atom->x[i * 3 + 0]; } #define get_atom_x(atom, i) (atom->x[i * 3 + 0])
inline MD_FLOAT get_atom_y(Atom *atom, int i) { return atom->x[i * 3 + 1]; } #define get_atom_y(atom, i) (atom->x[i * 3 + 1])
inline MD_FLOAT get_atom_z(Atom *atom, int i) { return atom->x[i * 3 + 2]; } #define get_atom_z(atom, i) (atom->x[i * 3 + 2])
#else #else
inline const char *posDataLayout() { return "SoA"; } #define POS_DATA_LAYOUT "SoA"
inline void set_atom_x(Atom *atom, int i, MD_FLOAT x) { atom->x[i] = x; } #define set_atom_x(atom, i, v) (atom->x[i] = v)
inline void set_atom_y(Atom *atom, int i, MD_FLOAT y) { atom->y[i] = y; } #define set_atom_y(atom, i, v) (atom->y[i] = v)
inline void set_atom_z(Atom *atom, int i, MD_FLOAT z) { atom->z[i] = z; } #define set_atom_z(atom, i, v) (atom->z[i] = v)
inline MD_FLOAT get_atom_x(Atom *atom, int i) { return atom->x[i]; } #define get_atom_x(atom, i) (atom->x[i])
inline MD_FLOAT get_atom_y(Atom *atom, int i) { return atom->y[i]; } #define get_atom_y(atom, i) (atom->y[i])
inline MD_FLOAT get_atom_z(Atom *atom, int i) { return atom->z[i]; } #define get_atom_z(atom, i) (atom->z[i])
#endif #endif
#endif #endif

View File

@ -291,7 +291,7 @@ int main (int argc, char** argv)
computeThermo(-1, &param, &atom); computeThermo(-1, &param, &atom);
printf(HLINE); printf(HLINE);
printf("Data layout for positions: %s\n", posDataLayout()); printf("Data layout for positions: %s\n", POS_DATA_LAYOUT);
#if PRECISION == 1 #if PRECISION == 1
printf("Using single precision floating point.\n"); printf("Using single precision floating point.\n");
#else #else