From 858065029d27622049e64388a642a7d2b986b258 Mon Sep 17 00:00:00 2001 From: David Nicholson Date: Sun, 12 Nov 2017 15:46:51 -0500 Subject: [PATCH 1/4] 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: From c16b7a3273f469c75a982a944b01865ecd0d303a Mon Sep 17 00:00:00 2001 From: David Nicholson Date: Sun, 12 Nov 2017 15:57:53 -0500 Subject: [PATCH 2/4] Multiple run fix for cluster/aggregate computes --- src/compute_aggregate_atom.cpp | 2 +- src/compute_cluster_atom.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compute_aggregate_atom.cpp b/src/compute_aggregate_atom.cpp index f92bf02cba..b3daf5f98c 100644 --- a/src/compute_aggregate_atom.cpp +++ b/src/compute_aggregate_atom.cpp @@ -121,7 +121,7 @@ void ComputeAggregateAtom::compute_peratom() // invoke full neighbor list (will copy or build if necessary) - neighbor->build_one(list); + neighbor->build_one(list,1); // if group is dynamic, insure ghost atom masks are current diff --git a/src/compute_cluster_atom.cpp b/src/compute_cluster_atom.cpp index 5ee6368504..d01402d480 100644 --- a/src/compute_cluster_atom.cpp +++ b/src/compute_cluster_atom.cpp @@ -113,7 +113,7 @@ void ComputeClusterAtom::compute_peratom() // invoke full neighbor list (will copy or build if necessary) - neighbor->build_one(list); + neighbor->build_one(list,1); inum = list->inum; ilist = list->ilist; From a085ee0c554024209762d9e4633c775aaf289e88 Mon Sep 17 00:00:00 2001 From: David Nicholson Date: Mon, 13 Nov 2017 04:53:16 -0500 Subject: [PATCH 3/4] Always build occasional lists on first step --- src/compute_aggregate_atom.cpp | 2 +- src/compute_cluster_atom.cpp | 2 +- src/neighbor.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compute_aggregate_atom.cpp b/src/compute_aggregate_atom.cpp index b3daf5f98c..f92bf02cba 100644 --- a/src/compute_aggregate_atom.cpp +++ b/src/compute_aggregate_atom.cpp @@ -121,7 +121,7 @@ void ComputeAggregateAtom::compute_peratom() // invoke full neighbor list (will copy or build if necessary) - neighbor->build_one(list,1); + neighbor->build_one(list); // if group is dynamic, insure ghost atom masks are current diff --git a/src/compute_cluster_atom.cpp b/src/compute_cluster_atom.cpp index d01402d480..5ee6368504 100644 --- a/src/compute_cluster_atom.cpp +++ b/src/compute_cluster_atom.cpp @@ -113,7 +113,7 @@ void ComputeClusterAtom::compute_peratom() // invoke full neighbor list (will copy or build if necessary) - neighbor->build_one(list,1); + neighbor->build_one(list); inum = list->inum; ilist = list->ilist; diff --git a/src/neighbor.cpp b/src/neighbor.cpp index cc2e5d6d11..46b921191b 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -2144,7 +2144,7 @@ void Neighbor::build_one(class NeighList *mylist, int preflag) NPair *np = neigh_pair[mylist->index]; - if (preflag) { + if (preflag || update->firststep == update->ntimestep) { if (np->last_build > lastcall) return; } else { if (np->last_build >= lastcall) return; From e55c90cc443b4f3b40fd4c7ff5fa6222b835027c Mon Sep 17 00:00:00 2001 From: David Nicholson Date: Tue, 14 Nov 2017 14:01:07 -0500 Subject: [PATCH 4/4] Moved rerun bug fix to individual affected styles --- src/compute_aggregate_atom.cpp | 4 +++- src/compute_cluster_atom.cpp | 4 +++- src/compute_hexorder_atom.cpp | 4 +++- src/neighbor.cpp | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/compute_aggregate_atom.cpp b/src/compute_aggregate_atom.cpp index f92bf02cba..674fecb8c0 100644 --- a/src/compute_aggregate_atom.cpp +++ b/src/compute_aggregate_atom.cpp @@ -120,8 +120,10 @@ void ComputeAggregateAtom::compute_peratom() } // invoke full neighbor list (will copy or build if necessary) + // on the first step of a run, set preflag to one in neighbor->build_one(...) - neighbor->build_one(list); + if (update->firststep == update->ntimestep) neighbor->build_one(list,1); + else neighbor->build_one(list); // if group is dynamic, insure ghost atom masks are current diff --git a/src/compute_cluster_atom.cpp b/src/compute_cluster_atom.cpp index 5ee6368504..9a7df03e49 100644 --- a/src/compute_cluster_atom.cpp +++ b/src/compute_cluster_atom.cpp @@ -112,8 +112,10 @@ void ComputeClusterAtom::compute_peratom() } // invoke full neighbor list (will copy or build if necessary) + // on the first step of a run, set preflag to one in neighbor->build_one(...) - neighbor->build_one(list); + if (update->firststep == update->ntimestep) neighbor->build_one(list,1); + else neighbor->build_one(list); inum = list->inum; ilist = list->ilist; diff --git a/src/compute_hexorder_atom.cpp b/src/compute_hexorder_atom.cpp index 013036f364..85324651c1 100644 --- a/src/compute_hexorder_atom.cpp +++ b/src/compute_hexorder_atom.cpp @@ -154,8 +154,10 @@ void ComputeHexOrderAtom::compute_peratom() } // invoke full neighbor list (will copy or build if necessary) + // on the first step of a run, set preflag to one in neighbor->build_one(...) - neighbor->build_one(list); + if (update->firststep == update->ntimestep) neighbor->build_one(list,1); + else neighbor->build_one(list); inum = list->inum; ilist = list->ilist; diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 46b921191b..cc2e5d6d11 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -2144,7 +2144,7 @@ void Neighbor::build_one(class NeighList *mylist, int preflag) NPair *np = neigh_pair[mylist->index]; - if (preflag || update->firststep == update->ntimestep) { + if (preflag) { if (np->last_build > lastcall) return; } else { if (np->last_build >= lastcall) return;