add balance styles shift/report and rcb/report for reporting imbalances only

This commit is contained in:
Axel Kohlmeyer
2024-03-05 18:24:38 -05:00
parent e0c0b2fe7e
commit 0dc6e156c1
3 changed files with 32 additions and 8 deletions

View File

@ -14,15 +14,15 @@ Syntax
* balance = style name of this fix command * balance = style name of this fix command
* Nfreq = perform dynamic load balancing every this many steps * Nfreq = perform dynamic load balancing every this many steps
* thresh = imbalance threshold that must be exceeded to perform a re-balance * thresh = imbalance threshold that must be exceeded to perform a re-balance
* style = *shift* or *rcb* * style = *shift* *shift/report* or *rcb* or *rcb/report*
.. parsed-literal:: .. parsed-literal::
shift args = dimstr Niter stopthresh *shift* or *shift/report* args = dimstr Niter stopthresh
dimstr = sequence of letters containing *x* or *y* or *z*, each not more than once dimstr = sequence of letters containing *x* or *y* or *z*, each not more than once
Niter = # of times to iterate within each dimension of dimstr sequence Niter = # of times to iterate within each dimension of dimstr sequence
stopthresh = stop balancing when this imbalance threshold is reached stopthresh = stop balancing when this imbalance threshold is reached
*rcb* args = none *rcb* or *rcb/report* args = none
* zero or more keyword/arg pairs may be appended * zero or more keyword/arg pairs may be appended
* keyword = *weight* or *out* * keyword = *weight* or *out*
@ -70,6 +70,13 @@ re-balancing is performed periodically during the simulation. To
perform "static" balancing, before or between runs, see the perform "static" balancing, before or between runs, see the
:doc:`balance <balance>` command. :doc:`balance <balance>` command.
.. versionadded:: TBD
The *shift/report* and *rcb/report* styles only compute the
load imbalance but do not attempt any re-balancing. This way
the load imbalance information can be used otherwise, for
instance for stopping a run with :doc:`fix halt <fix_halt>`.
Load-balancing is typically most useful if the particles in the Load-balancing is typically most useful if the particles in the
simulation box have a spatially-varying density distribution or simulation box have a spatially-varying density distribution or
where the computational cost varies significantly between different where the computational cost varies significantly between different

View File

@ -61,9 +61,18 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
if (nevery < 0) error->all(FLERR,"Illegal fix balance command"); if (nevery < 0) error->all(FLERR,"Illegal fix balance command");
thresh = utils::numeric(FLERR,arg[4],false,lmp); thresh = utils::numeric(FLERR,arg[4],false,lmp);
if (strcmp(arg[5],"shift") == 0) lbstyle = SHIFT; reportonly = 0;
else if (strcmp(arg[5],"rcb") == 0) lbstyle = BISECTION; if (strcmp(arg[5],"shift") == 0) {
else error->all(FLERR,"Illegal fix balance command"); lbstyle = SHIFT;
} else if (strcmp(arg[5],"shift/report") == 0) {
lbstyle = SHIFT;
reportonly = 1;
} else if (strcmp(arg[5],"rcb") == 0) {
lbstyle = BISECTION;
} else if (strcmp(arg[5],"rcb/report") == 0) {
lbstyle = BISECTION;
reportonly = 1;
} else error->all(FLERR,"Unknown fix balance style {}", arg[5]);
int iarg = 5; int iarg = 5;
if (lbstyle == SHIFT) { if (lbstyle == SHIFT) {
@ -75,7 +84,6 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
stopthresh = utils::numeric(FLERR,arg[iarg+3],false,lmp); stopthresh = utils::numeric(FLERR,arg[iarg+3],false,lmp);
if (stopthresh < 1.0) error->all(FLERR,"Illegal fix balance command"); if (stopthresh < 1.0) error->all(FLERR,"Illegal fix balance command");
iarg += 4; iarg += 4;
} else if (lbstyle == BISECTION) { } else if (lbstyle == BISECTION) {
iarg++; iarg++;
} }
@ -175,7 +183,7 @@ void FixBalance::setup(int /*vflag*/)
void FixBalance::setup_pre_exchange() void FixBalance::setup_pre_exchange()
{ {
// do not allow rebalancing twice on same timestep // do not allow rebalancing twice on same timestep
// even if wanted to, can mess up elapsed time in ImbalanceTime // even if you wanted to, it can mess up elapsed time in ImbalanceTime
if (update->ntimestep == lastbalance) return; if (update->ntimestep == lastbalance) return;
lastbalance = update->ntimestep; lastbalance = update->ntimestep;
@ -195,6 +203,7 @@ void FixBalance::setup_pre_exchange()
balance->set_weights(); balance->set_weights();
imbnow = balance->imbalance_factor(maxloadperproc); imbnow = balance->imbalance_factor(maxloadperproc);
if (imbnow > thresh) rebalance(); if (imbnow > thresh) rebalance();
// next timestep to rebalance // next timestep to rebalance
@ -263,6 +272,13 @@ void FixBalance::pre_neighbor()
void FixBalance::rebalance() void FixBalance::rebalance()
{ {
// return immediately if only reporting of the imbalance is requested
if (reportonly) {
imbprev = imbfinal = imbnow;
return;
}
imbprev = imbnow; imbprev = imbnow;
// invoke balancer and reset comm->uniform flag // invoke balancer and reset comm->uniform flag

View File

@ -45,6 +45,7 @@ class FixBalance : public Fix {
std::string bstr; std::string bstr;
int wtflag; // 1 for weighted balancing int wtflag; // 1 for weighted balancing
int sortflag; // 1 for sorting comm messages int sortflag; // 1 for sorting comm messages
int reportonly; // 1 if skipping rebalancing and only computing imbalance
double imbnow; // current imbalance factor double imbnow; // current imbalance factor
double imbprev; // imbalance factor before last rebalancing double imbprev; // imbalance factor before last rebalancing