From 858065029d27622049e64388a642a7d2b986b258 Mon Sep 17 00:00:00 2001 From: David Nicholson Date: Sun, 12 Nov 2017 15:46:51 -0500 Subject: [PATCH] Reverse communication compute fragment/aggregate --- src/compute_aggregate_atom.cpp | 45 +++++++++++++++++++++++++++++++++- src/compute_aggregate_atom.h | 2 ++ src/compute_fragment_atom.cpp | 45 +++++++++++++++++++++++++++++++++- src/compute_fragment_atom.h | 2 ++ 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/compute_aggregate_atom.cpp b/src/compute_aggregate_atom.cpp index 1155ac437a..f92bf02cba 100644 --- a/src/compute_aggregate_atom.cpp +++ b/src/compute_aggregate_atom.cpp @@ -51,6 +51,7 @@ ComputeAggregateAtom::ComputeAggregateAtom(LAMMPS *lmp, int narg, char **arg) : peratom_flag = 1; size_peratom_cols = 0; comm_forward = 1; + comm_reverse = 1; nmax = 0; } @@ -163,6 +164,11 @@ void ComputeAggregateAtom::compute_peratom() while (1) { comm->forward_comm_compute(this); + // reverse communication when bonds are not stored on every processor + + if (force->newton_bond) + comm->reverse_comm_compute(this); + change = 0; while (1) { done = 1; @@ -252,13 +258,50 @@ void ComputeAggregateAtom::unpack_forward_comm(int n, int first, double *buf) m = 0; last = first + n; if (commflag) - for (i = first; i < last; i++) aggregateID[i] = buf[m++]; + for (i = first; i < last; i++) { + double x = buf[m++]; + + // only overwrite ghost IDs with values lower than current ones + + aggregateID[i] = MIN(x,aggregateID[i]); + } else { int *mask = atom->mask; for (i = first; i < last; i++) mask[i] = (int) ubuf(buf[m++]).i; } } +/* ---------------------------------------------------------------------- */ + +int ComputeAggregateAtom::pack_reverse_comm(int n, int first, double *buf) +{ + int i,m,last; + + m = 0; + last = first + n; + for (i = first; i < last; i++) { + buf[m++] = aggregateID[i]; + } + return m; +} + +/* ---------------------------------------------------------------------- */ + +void ComputeAggregateAtom::unpack_reverse_comm(int n, int *list, double *buf) +{ + int i,j,m; + + m = 0; + for (i = 0; i < n; i++) { + j = list[i]; + double x = buf[m++]; + + // only overwrite local IDs with values lower than current ones + + aggregateID[j] = MIN(x,aggregateID[j]); + } +} + /* ---------------------------------------------------------------------- memory usage of local atom-based array ------------------------------------------------------------------------- */ diff --git a/src/compute_aggregate_atom.h b/src/compute_aggregate_atom.h index 8170aabc7f..dc2e1d7b40 100644 --- a/src/compute_aggregate_atom.h +++ b/src/compute_aggregate_atom.h @@ -33,6 +33,8 @@ class ComputeAggregateAtom : public Compute { void compute_peratom(); int pack_forward_comm(int, int *, double *, int, int *); void unpack_forward_comm(int, int, double *); + int pack_reverse_comm(int, int, double *); + void unpack_reverse_comm(int, int *, double *); double memory_usage(); private: diff --git a/src/compute_fragment_atom.cpp b/src/compute_fragment_atom.cpp index 2dfb20a570..8606f54933 100644 --- a/src/compute_fragment_atom.cpp +++ b/src/compute_fragment_atom.cpp @@ -44,6 +44,7 @@ ComputeFragmentAtom::ComputeFragmentAtom(LAMMPS *lmp, int narg, char **arg) : peratom_flag = 1; size_peratom_cols = 0; comm_forward = 1; + comm_reverse = 1; nmax = 0; } @@ -122,6 +123,11 @@ void ComputeFragmentAtom::compute_peratom() while (1) { comm->forward_comm_compute(this); + // reverse communication when bonds are not stored on every processor + + if (force->newton_bond) + comm->reverse_comm_compute(this); + change = 0; while (1) { done = 1; @@ -183,13 +189,50 @@ void ComputeFragmentAtom::unpack_forward_comm(int n, int first, double *buf) m = 0; last = first + n; if (commflag) - for (i = first; i < last; i++) fragmentID[i] = buf[m++]; + for (i = first; i < last; i++) { + double x = buf[m++]; + + // only overwrite ghost IDs with values lower than current ones + + fragmentID[i] = MIN(x,fragmentID[i]); + } else { int *mask = atom->mask; for (i = first; i < last; i++) mask[i] = (int) ubuf(buf[m++]).i; } } +/* ---------------------------------------------------------------------- */ + +int ComputeFragmentAtom::pack_reverse_comm(int n, int first, double *buf) +{ + int i,m,last; + + m = 0; + last = first + n; + for (i = first; i < last; i++) { + buf[m++] = fragmentID[i]; + } + return m; +} + +/* ---------------------------------------------------------------------- */ + +void ComputeFragmentAtom::unpack_reverse_comm(int n, int *list, double *buf) +{ + int i,j,m; + + m = 0; + for (i = 0; i < n; i++) { + j = list[i]; + double x = buf[m++]; + + // only overwrite local IDs with values lower than current ones + + fragmentID[j] = MIN(x,fragmentID[j]); + } +} + /* ---------------------------------------------------------------------- memory usage of local atom-based array ------------------------------------------------------------------------- */ diff --git a/src/compute_fragment_atom.h b/src/compute_fragment_atom.h index a56239dbda..2365b6028b 100644 --- a/src/compute_fragment_atom.h +++ b/src/compute_fragment_atom.h @@ -32,6 +32,8 @@ class ComputeFragmentAtom : public Compute { void compute_peratom(); int pack_forward_comm(int, int *, double *, int, int *); void unpack_forward_comm(int, int, double *); + int pack_reverse_comm(int, int, double *); + void unpack_reverse_comm(int, int *, double *); double memory_usage(); private: