adjustments to balancing weights and factors, also XOR op for formulas, if, dump_modify thresh

This commit is contained in:
Steve Plimpton 2016-10-05 15:46:20 -06:00
parent 030df745bc
commit 02bfa898ee
11 changed files with 40 additions and 31 deletions

View File

@ -43,7 +43,7 @@ fix 2 all wall/lj93 xlo 0.0 1 1 2.5 xhi $x 1 1 2.5
fix 3 all wall/lj93 ylo 0.0 1 1 2.5 yhi $y 1 1 2.5
comm_style tiled
comm_modify cutoff 7.5
comm_modify cutoff 10.0 # because bonds stretch a long ways
fix 10 all balance 50 0.9 rcb
#compute 1 all property/atom proc

View File

@ -52,4 +52,3 @@ fix 0 all balance 50 1.0 shift x 5 1.0 &
weight neigh 0.5 weight time 0.66 weight store WEIGHT
run 500
run 500

View File

@ -272,7 +272,7 @@ void Balance::command(int narg, char **arg)
// imbinit = initial imbalance
double maxinit;
init_imbalance();
init_imbalance(0);
set_weights();
double imbinit = imbalance_factor(maxinit);
@ -543,12 +543,13 @@ void Balance::weight_storage(char *prefix)
/* ----------------------------------------------------------------------
invoke init() for each Imbalance class
flag = 0 for call from Balance, 1 for call from FixBalance
------------------------------------------------------------------------- */
void Balance::init_imbalance()
void Balance::init_imbalance(int flag)
{
if (!wtflag) return;
for (int n = 0; n < nimbalance; n++) imbalances[n]->init();
for (int n = 0; n < nimbalance; n++) imbalances[n]->init(flag);
}
/* ----------------------------------------------------------------------

View File

@ -38,7 +38,7 @@ class Balance : protected Pointers {
void command(int, char **);
void options(int, int, char **);
void weight_storage(char *);
void init_imbalance();
void init_imbalance(int);
void set_weights();
double imbalance_factor(double &);
void shift_setup(char *, int, double);

View File

@ -26,6 +26,7 @@
#include "modify.h"
#include "fix_store.h"
#include "rcb.h"
#include "timer.h"
#include "error.h"
using namespace LAMMPS_NS;
@ -113,7 +114,8 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
// only force reneighboring if nevery > 0
if (nevery) force_reneighbor = 1;
lastbalance = -1;
// compute initial outputs
itercount = 0;
@ -153,7 +155,7 @@ void FixBalance::init()
if (force->kspace) kspace_flag = 1;
else kspace_flag = 0;
balance->init_imbalance();
balance->init_imbalance(1);
}
/* ---------------------------------------------------------------------- */
@ -170,6 +172,12 @@ void FixBalance::setup(int vflag)
void FixBalance::setup_pre_exchange()
{
// do not allow rebalancing twice on same timestep
// even if wanted to, can mess up elapsed time in ImbalanceTime
if (update->ntimestep == lastbalance) return;
lastbalance = update->ntimestep;
// insure atoms are in current box & update box via shrink-wrap
// has to be be done before rebalance() invokes Irregular::migrate_atoms()
// since it requires atoms be inside simulation box
@ -202,6 +210,12 @@ void FixBalance::pre_exchange()
if (nevery && update->ntimestep < next_reneighbor) return;
// do not allow rebalancing twice on same timestep
// even if wanted to, can mess up elapsed time in ImbalanceTime
if (update->ntimestep == lastbalance) return;
lastbalance = update->ntimestep;
// insure atoms are in current box & update box via shrink-wrap
// no exchange() since doesn't matter if atoms are assigned to correct procs
@ -284,7 +298,7 @@ void FixBalance::rebalance()
if (kspace_flag) force->kspace->setup_grid();
// pending triggers pre_neighbor() to compute final imbalance factor
// can only be done after atoms migrate in caller's comm->exchange()
// can only be done after atoms migrate in comm->exchange()
pending = 1;
}

View File

@ -53,6 +53,7 @@ class FixBalance : public Fix {
int itercount; // iteration count of last call to Balance
int kspace_flag; // 1 if KSpace solver defined
int pending;
bigint lastbalance; // last timestep balancing was attempted
class Balance *balance;
class Irregular *irregular;

View File

@ -25,13 +25,13 @@ class Imbalance : protected Pointers {
virtual ~Imbalance() {};
// parse options. return number of arguments consumed (required)
virtual int options(int narg, char **arg) = 0;
virtual int options(int, char **) = 0;
// reinitialize internal data (needed for fix balance) (optional)
virtual void init() {};
virtual void init(int) {};
// compute and apply weight factors to local atom array (required)
virtual void compute(double *weights) = 0;
virtual void compute(double *) = 0;
// print information about the state of this imbalance compute (required)
virtual void info(FILE *fp) = 0;
virtual void info(FILE *) = 0;
// disallow default and copy constructor, assignment operator
// private:

View File

@ -19,9 +19,6 @@
#include "timer.h"
#include "error.h"
// DEBUG
#include "update.h"
using namespace LAMMPS_NS;
#define BIG 1.0e20
@ -41,12 +38,18 @@ int ImbalanceTime::options(int narg, char **arg)
}
/* ----------------------------------------------------------------------
reset last, needed for fix balance caller
reset last and timers if necessary
------------------------------------------------------------------------- */
void ImbalanceTime::init()
void ImbalanceTime::init(int flag)
{
last = 0.0;
// flag = 1 if called from FixBalance at start of run
// init Timer, so accumulated time not carried over from previous run
// should NOT init Timer if called from Balance, it uses time from last run
if (flag) timer->init();
}
/* -------------------------------------------------------------------- */
@ -65,15 +68,6 @@ void ImbalanceTime::compute(double *weight)
cost += timer->get_wall(Timer::BOND);
cost += timer->get_wall(Timer::KSPACE);
/*
printf("TIME %ld %d %g %g: %g %g %g %g\n",
update->ntimestep,atom->nlocal,last,cost,
timer->get_wall(Timer::PAIR),
timer->get_wall(Timer::NEIGH),
timer->get_wall(Timer::BOND),
timer->get_wall(Timer::KSPACE));
*/
double maxcost;
MPI_Allreduce(&cost,&maxcost,1,MPI_DOUBLE,MPI_MAX,world);
if (maxcost <= 0.0) return;

View File

@ -27,7 +27,7 @@ class ImbalanceTime : public Imbalance {
// parse options, return number of arguments consumed
virtual int options(int, char **);
// reinitialize internal data
virtual void init();
virtual void init(int);
// compute and apply weight factors to local atom array
virtual void compute(double *);
// print information about the state of this imbalance compute

View File

@ -45,14 +45,14 @@ int ImbalanceVar::options(int narg, char **arg)
int len = strlen(arg[0]) + 1;
name = new char[len];
memcpy(name,arg[0],len);
init();
init(0);
return 1;
}
/* -------------------------------------------------------------------- */
void ImbalanceVar::init()
void ImbalanceVar::init(int flag)
{
id = input->variable->find(name);
if (id < 0) {

View File

@ -27,7 +27,7 @@ class ImbalanceVar : public Imbalance {
// parse options. return number of arguments consumed.
virtual int options(int, char **);
// re-initialize internal data, e.g. variable ID
virtual void init();
virtual void init(int);
// compute per-atom imbalance and apply to weight array
virtual void compute(double *);
// print information about the state of this imbalance compute (required)