diff --git a/Makefile b/Makefile index a4d42b1..defffb6 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,10 @@ ifneq ($(ASM_SYNTAX), ATT) ASFLAGS += -masm=intel endif +ifeq ($(strip $(SORT_ATOMS)),true) + DEFINES += -DSORT_ATOMS +endif + ifeq ($(strip $(EXPLICIT_TYPES)),true) DEFINES += -DEXPLICIT_TYPES endif diff --git a/common/parameter.c b/common/parameter.c index 0ac5468..1d6d593 100644 --- a/common/parameter.c +++ b/common/parameter.c @@ -169,6 +169,11 @@ void printParameter(Parameter *param) { printf("\tNumber of timesteps: %d\n", param->ntimes); printf("\tReport stats every (timesteps): %d\n", param->nstat); printf("\tReneighbor every (timesteps): %d\n", param->reneigh_every); + #ifdef SORT_ATOMS + printf("\tSort atoms when reneighboring: yes\n"); + #else + printf("\tSort atoms when reneighboring: no\n"); + #endif printf("\tPrune every (timesteps): %d\n", param->prune_every); printf("\tOutput positions every (timesteps): %d\n", param->x_out_every); printf("\tOutput velocities every (timesteps): %d\n", param->v_out_every); diff --git a/lammps/main.c b/lammps/main.c index 1cc5c46..713c86e 100644 --- a/lammps/main.c +++ b/lammps/main.c @@ -63,6 +63,10 @@ double setup(Parameter *param, Eam *eam, Atom *atom, Neighbor *neighbor, Stats * setupNeighbor(param); setupThermo(param, atom->Natoms); if(param->input_file == NULL) { adjustThermo(param, atom); } + #ifdef SORT_ATOMS + atom->Nghost = 0; + sortAtom(atom); + #endif setupPbc(atom, param); initDevice(atom, neighbor); updatePbc(atom, param, true); @@ -76,9 +80,12 @@ double reneighbour(Parameter *param, Atom *atom, Neighbor *neighbor) { S = getTimeStamp(); LIKWID_MARKER_START("reneighbour"); updateAtomsPbc(atom, param); + #ifdef SORT_ATOMS + atom->Nghost = 0; + sortAtom(atom); + #endif setupPbc(atom, param); updatePbc(atom, param, true); - //sortAtom(atom); buildNeighbor(atom, neighbor); LIKWID_MARKER_STOP("reneighbour"); E = getTimeStamp(); diff --git a/lammps/neighbor.c b/lammps/neighbor.c index 1c88096..c06f678 100644 --- a/lammps/neighbor.c +++ b/lammps/neighbor.c @@ -326,45 +326,45 @@ void sortAtom(Atom* atom) { int Nmax = atom->Nmax; int* binpos = bincount; - for(int i=1; ix; MD_FLOAT* old_y = atom->y; MD_FLOAT* old_z = atom->z; MD_FLOAT* old_vx = atom->vx; MD_FLOAT* old_vy = atom->vy; MD_FLOAT* old_vz = atom->vz; - for(int mybin = 0; mybin0?binpos[mybin-1]:0; + for(int mybin = 0; mybin < mbins; mybin++) { + int start = mybin > 0 ? binpos[mybin - 1] : 0; int count = binpos[mybin] - start; - for(int k=0; kvx); atom->x = new_x; atom->vx = new_vx; -#ifndef AOS + #ifndef AOS free(atom->y); free(atom->z); free(atom->vy); @@ -381,5 +381,5 @@ void sortAtom(Atom* atom) { atom->z = new_z; atom->vy = new_vy; atom->vz = new_vz; -#endif + #endif }