Commit b954283e authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

properly handle the case of neighbor lists never been computed before

(cherry picked from commit fcba14a0aa976af3a7a177115f4e506df3d37b53)
parent ecc136b6
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -55,9 +55,11 @@ void ImbalanceNeigh::compute(double *weight)
        neighbor->lists[req] && neighbor->lists[req]->numneigh) break;
  }

  if (req >= neighbor->old_nrequest) {
    if (_lmp->comm->me == 0)
      error->warning(FLERR,"No suitable neighbor list for balancing found");
  if (req >= neighbor->old_nrequest || neighbor->ago < 0) {
    if (_lmp->comm->me == 0 && !did_warn)
      error->warning(FLERR,"No suitable neighbor list found. "
                     "Neighbor weighted balancing skipped");
    did_warn = 1;
    return;
  }

@@ -74,11 +76,14 @@ void ImbalanceNeigh::compute(double *weight)
    // first pass: get local number of neighbors.
    for (int i = 0; i < inum; ++i) neighsum += numneigh[ilist[i]];

    double allavg, myavg = ((double) neighsum)/((double) _lmp->atom->natoms);
    double allatoms = static_cast <double>(_lmp->atom->natoms);
    if (allatoms == 0.0) allatoms = 1.0;
    double allavg;
    double myavg = static_cast<double>(neighsum)/allatoms;
    MPI_Allreduce(&myavg,&allavg,1,MPI_DOUBLE,MPI_SUM,world);
    double scale = 1.0/allavg;

    // second pass: compute and apply weights
    double scale = 1.0/allavg;
    for (int ii = 0; ii < inum; ++ii) {
      const int i = ilist[ii];
      weight[i] *= (1.0-_factor) + _factor*scale*numneigh[i];
+2 −1
Original line number Diff line number Diff line
@@ -20,12 +20,13 @@ namespace LAMMPS_NS {

class ImbalanceNeigh : public Imbalance {
 public:
  ImbalanceNeigh(LAMMPS *lmp) : Imbalance(lmp), _factor(0.0) {};
  ImbalanceNeigh(LAMMPS *lmp) : Imbalance(lmp), _factor(0.0), did_warn(0) {};
  virtual ~ImbalanceNeigh() {};

  // internal data members
 private:
  double _factor;               // weight factor for neighbor imbalance
  int did_warn;                 // 1 if warned about no suitable neighbor list

 public:
  // parse options. return number of arguments consumed
+2 −0
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ Neighbor::Neighbor(LAMMPS *lmp) : Pointers(lmp)
  binatomflag = 1;
  ago = -1;

  ago = -1;

  cutneighmax = 0.0;
  cutneighsq = NULL;
  cutneighghostsq = NULL;