Commit 0b0db201 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

make it so that dynamic load balancing only uses the timing since the last balancing

(cherry picked from commit f758a4f4d06f363aad4c817d94d7054757f9f8b1)
parent f76f2c88
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ Balance::Balance(LAMMPS *lmp) : Pointers(lmp)
  group_id = NULL;
  group_weight = NULL;

  last_clock = 0.0;
  clock_imbalance = NULL;
}

@@ -219,7 +218,7 @@ void Balance::command(int narg, char **arg)
      double factor = force->numeric(FLERR,arg[iarg+1]);
      if (factor < 0.0 || factor > 1.0)
        error->all(FLERR,"Illegal balance command");
      imbalance_clock(factor);
      imbalance_clock(factor,0.0);
      iarg += 2;
    } else if (strcmp(arg[iarg],"group") == 0) {
      group_setup(narg-iarg-1,arg+iarg+1);
@@ -464,29 +463,30 @@ double Balance::getcost(int i)
}

/* ----------------------------------------------------------------------
   calculate imbalance based on timer for Pair+Neighbor
   calculate imbalance based on timers for Pair+Bond+Kspace+Neighbor time.
------------------------------------------------------------------------- */

void Balance::imbalance_clock(double factor)
double Balance::imbalance_clock(double factor, double last_cost)
{

  // Compute the cost function of based on relevant timers
  if (timer->has_normal()) {
    double cost = -last_clock;
    if (!clock_imbalance) clock_imbalance = new double[nprocs+1];
    double *clock_cost = new double[nprocs+1];
    for (int i = 0; i <= nprocs; ++i) clock_cost[i] = 0.0;

    double cost = -last_cost;
    cost += timer->get_wall(Timer::PAIR);
    cost += timer->get_wall(Timer::NEIGH);
    cost += timer->get_wall(Timer::BOND);
    cost += timer->get_wall(Timer::KSPACE);

    double *clock_cost = new double[nprocs+1];
    for (int i = 0; i <= nprocs; ++i) clock_cost[i] = 0.0;
    clock_cost[me] = cost;
    clock_cost[nprocs] = cost;
    MPI_Allreduce(clock_cost,clock_imbalance,nprocs+1,MPI_DOUBLE,MPI_SUM,world);

    const double avg_cost = clock_imbalance[nprocs]/nprocs;
    if (cost > 0.0) {
    if (avg_cost > 0.0) {
      for (int i = 0; i < nprocs; ++i)
        clock_imbalance[i] = (1.0-factor) + factor*clock_imbalance[i]/avg_cost;
    } else {
@@ -504,7 +504,9 @@ void Balance::imbalance_clock(double factor)
#endif

    delete [] clock_cost;
    return cost + last_cost;
  }
  return last_cost;
}

/* ----------------------------------------------------------------------
+2 −3
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ class Balance : protected Pointers {
  int shift();
  int *bisection(int sortflag = 0);
  double imbalance_nlocal(int &);
  void imbalance_clock(double);
  double imbalance_clock(double, double);
  void dumpout(bigint, FILE *);

 private:
@@ -71,8 +71,7 @@ class Balance : protected Pointers {
  int    *group_id;          // group ids for weights
  double *group_weight;      // weights of groups

  double *clock_imbalance;   // computed wall clock imbalance
  double last_clock;         // accumulated clock at previous balancing step
  double *clock_imbalance;   // computed wall clock imbalance, NULL if not available

  int outflag;               // for output of balance results to file
  FILE *fp;
+3 −1
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
  outflag = 0;
  int outarg = 0;
  fp = NULL;
  last_clock = 0.0;

  while (iarg < narg) {
    if (strcmp(arg[iarg],"out") == 0) {
@@ -199,6 +200,7 @@ void FixBalance::setup_pre_exchange()

  // perform a rebalance if threshhold exceeded

  last_clock = 0.0;
  imbnow = balance->imbalance_nlocal(maxperproc);
  if (imbnow > thresh) rebalance();

@@ -227,7 +229,7 @@ void FixBalance::pre_exchange()

  // return if imbalance < threshhold

  balance->imbalance_clock(clock_factor);
  last_clock = balance->imbalance_clock(clock_factor,last_clock);
  imbnow = balance->imbalance_nlocal(maxperproc);
  if (imbnow <= thresh) {
    if (nevery) next_reneighbor = (update->ntimestep/nevery)*nevery + nevery;
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ class FixBalance : public Fix {
  double imbprev;               // imbalance factor before last rebalancing
  double imbfinal;              // imbalance factor after last rebalancing
  double clock_factor;          // weighting factor for timer imbalance
  double last_clock;            // combined clock of previous balancing chunks
  int maxperproc;               // max atoms on any processor
  int itercount;                // iteration count of last call to Balance
  int kspace_flag;              // 1 if KSpace solver defined