diff --git a/src/fix_balance.cpp b/src/fix_balance.cpp index f24fa0a43a..41affb53b7 100644 --- a/src/fix_balance.cpp +++ b/src/fix_balance.cpp @@ -101,6 +101,7 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) : imbfinal = imbprev = balance->imbalance_nlocal(maxperproc); itercount = 0; + pending = 0; } /* ---------------------------------------------------------------------- */ @@ -118,6 +119,7 @@ int FixBalance::setmask() { int mask = 0; mask |= PRE_EXCHANGE; + mask |= PRE_NEIGHBOR; return mask; } @@ -133,6 +135,13 @@ void FixBalance::init() /* ---------------------------------------------------------------------- */ +void FixBalance::setup(int vflag) +{ + pre_neighbor(); +} + +/* ---------------------------------------------------------------------- */ + void FixBalance::setup_pre_exchange() { // insure atoms are in current box & update box via shrink-wrap @@ -186,6 +195,18 @@ void FixBalance::pre_exchange() if (nevery) next_reneighbor = (update->ntimestep/nevery)*nevery + nevery; } +/* ---------------------------------------------------------------------- + compute final imbalance factor based on nlocal after comm->exchange() + only do this if rebalancing just occured +------------------------------------------------------------------------- */ + +void FixBalance::pre_neighbor() +{ + if (!pending) return; + imbfinal = balance->imbalance_nlocal(maxperproc); + pending = 0; +} + /* ---------------------------------------------------------------------- perform dynamic load balancing ------------------------------------------------------------------------- */ @@ -211,7 +232,7 @@ void FixBalance::rebalance() // if splits moved further than neighboring processor // move atoms to new processors via irregular() // only needed if migrate_check() says an atom moves to far, - // else allow comm->exchange that follows in caller to do it + // else allow caller's comm->exchange() to do it if (domain->triclinic) domain->x2lamda(atom->nlocal); if (irregular->migrate_check()) irregular->migrate_atoms(); @@ -221,9 +242,10 @@ void FixBalance::rebalance() // check that new sub-domains are valid with KSpace constraints // if (kspace_flag) force->kspace->check(); - // imbfinal = final imbalance based on final nlocal + // pending triggers pre_neighbor() to compute final imbalance factor + // can only be done after atoms migrate in caller's comm->exchange() - imbfinal = balance->imbalance_nlocal(maxperproc); + pending = 1; } /* ---------------------------------------------------------------------- diff --git a/src/fix_balance.h b/src/fix_balance.h index 74afd965c8..61cd88cf77 100644 --- a/src/fix_balance.h +++ b/src/fix_balance.h @@ -31,8 +31,10 @@ class FixBalance : public Fix { ~FixBalance(); int setmask(); void init(); + void setup(int); void setup_pre_exchange(); void pre_exchange(); + void pre_neighbor(); double compute_scalar(); double compute_vector(int); double memory_usage(); @@ -49,6 +51,7 @@ class FixBalance : public Fix { int maxperproc; // max atoms on any processor int itercount; // iteration count of last call to Balance int kspace_flag; // 1 if KSpace solver defined + int pending; class Balance *balance; class Irregular *irregular;