From e9d4b7a10dace9c33fe0332bd6da9230a10fa03c Mon Sep 17 00:00:00 2001 From: sjplimp Date: Thu, 3 Apr 2014 14:57:27 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@11689 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/irregular.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++- src/irregular.h | 8 +++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/irregular.cpp b/src/irregular.cpp index 679428fb48..b9203ebdd8 100644 --- a/src/irregular.cpp +++ b/src/irregular.cpp @@ -24,6 +24,12 @@ using namespace LAMMPS_NS; +// allocate space for static class variable +// prototype for non-class function + +int *Irregular::proc_recv_copy; +int compare_standalone(const void *, const void *); + #define BUFFACTOR 1.5 #define BUFMIN 1000 #define BUFEXTRA 1000 @@ -247,7 +253,7 @@ int Irregular::migrate_check() return total # of doubles I will recv (not including self) ------------------------------------------------------------------------- */ -int Irregular::create_atom(int n, int *sizes, int *proclist) +int Irregular::create_atom(int n, int *sizes, int *proclist, int sort) { int i; @@ -358,6 +364,33 @@ int Irregular::create_atom(int n, int *sizes, int *proclist) nrecvsize += length_recv[i]; } + // sort proc_recv and num_recv by proc ID if requested + // useful for debugging to insure reproducible ordering of received atoms + // invoke by adding final arg = 1 to create_atom() call in migrate_atoms() + + if (sort) { + int *order = new int[nrecv]; + int *proc_recv_ordered = new int[nrecv]; + int *length_recv_ordered = new int[nrecv]; + + for (i = 0; i < nrecv; i++) order[i] = i; + proc_recv_copy = proc_recv; + qsort(order,nrecv,sizeof(int),compare_standalone); + + int j; + for (i = 0; i < nrecv; i++) { + j = order[i]; + proc_recv_ordered[i] = proc_recv[j]; + length_recv_ordered[i] = length_recv[j]; + } + + memcpy(proc_recv,proc_recv_ordered,nrecv*sizeof(int)); + memcpy(length_recv,length_recv_ordered,nrecv*sizeof(int)); + delete [] order; + delete [] proc_recv_ordered; + delete [] length_recv_ordered; + } + // barrier to insure all MPI_ANY_SOURCE messages are received // else another proc could proceed to exchange_atom() and send to me @@ -388,6 +421,21 @@ int Irregular::create_atom(int n, int *sizes, int *proclist) return nrecvsize; } +/* ---------------------------------------------------------------------- + comparison function invoked by qsort() + accesses static class member proc_recv_copy, set before call to qsort() +------------------------------------------------------------------------- */ + +int compare_standalone(const void *iptr, const void *jptr) +{ + int i = *((int *) iptr); + int j = *((int *) jptr); + int *proc_recv = Irregular::proc_recv_copy; + if (proc_recv[i] < proc_recv[j]) return -1; + if (proc_recv[i] > proc_recv[j]) return 1; + return 0; +} + /* ---------------------------------------------------------------------- communicate atoms via PlanAtom sendbuf = list of atoms to send diff --git a/src/irregular.h b/src/irregular.h index 2581551c0f..1ca51a51c9 100644 --- a/src/irregular.h +++ b/src/irregular.h @@ -20,6 +20,11 @@ namespace LAMMPS_NS { class Irregular : protected Pointers { public: + + // static variable across all Irregular objects, for qsort callback + + static int *proc_recv_copy; + Irregular(class LAMMPS *); ~Irregular(); void migrate_atoms(); @@ -82,7 +87,7 @@ class Irregular : protected Pointers { PlanAtom *aplan; PlanData *dplan; - int create_atom(int, int *, int *); + int create_atom(int, int *, int *, int sort = 0); void exchange_atom(double *, int *, double *); void destroy_atom(); int coord2proc(double *, int &, int &, int &); @@ -95,6 +100,7 @@ class Irregular : protected Pointers { } #endif + /* ERROR/WARNING messages: */