Unverified Commit c0fb7948 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

update load balancing output to use utils::logmesg() and {fmt}

parent 9e8ce240
Loading
Loading
Loading
Loading
+26 −57
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@
#include "imbalance_var.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;

@@ -366,12 +368,10 @@ void Balance::command(int narg, char **arg)
  bigint natoms;
  bigint nblocal = atom->nlocal;
  MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world);
  if (natoms != atom->natoms) {
    char str[128];
    sprintf(str,"Lost atoms via balance: original " BIGINT_FORMAT
            " current " BIGINT_FORMAT,atom->natoms,natoms);
    error->all(FLERR,str);
  }
  if (natoms != atom->natoms)
    error->all(FLERR,fmt::format("Lost atoms via balance: "
                                 "original {}  current {}",
                                 atom->natoms,natoms).c_str());

  // imbfinal = final imbalance
  // set disable = 1, so weights no longer migrate with atoms
@@ -382,60 +382,29 @@ void Balance::command(int narg, char **arg)

  // stats output

  double stop_time = MPI_Wtime();

  if (me == 0) {
    if (screen) {
      fprintf(screen,"  rebalancing time: %g seconds\n",stop_time-start_time);
      fprintf(screen,"  iteration count = %d\n",niter);
      for (int i = 0; i < nimbalance; ++i) imbalances[i]->info(screen);
      fprintf(screen,"  initial/final max load/proc = %g %g\n",
              maxinit,maxfinal);
      fprintf(screen,"  initial/final imbalance factor = %g %g\n",
              imbinit,imbfinal);
    }
    if (logfile) {
      fprintf(logfile,"  rebalancing time: %g seconds\n",stop_time-start_time);
      fprintf(logfile,"  iteration count = %d\n",niter);
      for (int i = 0; i < nimbalance; ++i) imbalances[i]->info(logfile);
      fprintf(logfile,"  initial/final max load/proc = %g %g\n",
              maxinit,maxfinal);
      fprintf(logfile,"  initial/final imbalance factor = %g %g\n",
              imbinit,imbfinal);
    }
  }
    std::string mesg = fmt::format(" rebalancing time: {:.3f} seconds\n",
                                   MPI_Wtime()-start_time);
    mesg += fmt::format("  iteration count = {}\n",niter);
    for (int i = 0; i < nimbalance; ++i) mesg += imbalances[i]->info();
    mesg += fmt::format("  initial/final maximal load/proc = {} {}\n"
                        "  initial/final imbalance factor  = {:.6g} {:.6g}\n",
                        maxinit,maxfinal,imbinit,imbfinal);

    if (style != BISECTION) {
    if (me == 0) {
      if (screen) {
        fprintf(screen,"  x cuts:");
      mesg += "  x cuts:";
      for (int i = 0; i <= comm->procgrid[0]; i++)
          fprintf(screen," %g",comm->xsplit[i]);
        fprintf(screen,"\n");
        fprintf(screen,"  y cuts:");
        mesg += fmt::format(" {}",comm->xsplit[i]);
      mesg += "\n  y cuts:";
      for (int i = 0; i <= comm->procgrid[1]; i++)
          fprintf(screen," %g",comm->ysplit[i]);
        fprintf(screen,"\n");
        fprintf(screen,"  z cuts:");
        mesg += fmt::format(" {}",comm->ysplit[i]);
      mesg += "\n  z cuts:";
      for (int i = 0; i <= comm->procgrid[2]; i++)
          fprintf(screen," %g",comm->zsplit[i]);
        fprintf(screen,"\n");
      }
      if (logfile) {
        fprintf(logfile,"  x cuts:");
        for (int i = 0; i <= comm->procgrid[0]; i++)
          fprintf(logfile," %g",comm->xsplit[i]);
        fprintf(logfile,"\n");
        fprintf(logfile,"  y cuts:");
        for (int i = 0; i <= comm->procgrid[1]; i++)
          fprintf(logfile," %g",comm->ysplit[i]);
        fprintf(logfile,"\n");
        fprintf(logfile,"  z cuts:");
        for (int i = 0; i <= comm->procgrid[2]; i++)
          fprintf(logfile," %g",comm->zsplit[i]);
        fprintf(logfile,"\n");
      }
        mesg += fmt::format(" {}",comm->zsplit[i]);
      mesg += "\n";
    }

    utils::logmesg(lmp,mesg);
  }
}

+1 −1
Original line number Diff line number Diff line
@@ -587,7 +587,7 @@ void CreateAtoms::command(int narg, char **arg)
  MPI_Barrier(world);
  if (me == 0)
    utils::logmesg(lmp, fmt::format("Created {} atoms\n"
                        "  create_atoms CPU = {:.3g} seconds\n",
                        "  create_atoms CPU = {:.3f} seconds\n",
                        atom->natoms - natoms_previous,
                        MPI_Wtime() - time1));
}
+2 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#define LMP_IMBALANCE_H

#include "pointers.h"  // IWYU pragma: export
#include <string>

namespace LAMMPS_NS {

@@ -30,7 +31,7 @@ class Imbalance : protected Pointers {
  // compute and apply weight factors to local atom array (required)
  virtual void compute(double *) = 0;
  // print information about the state of this imbalance compute (required)
  virtual void info(FILE *) = 0;
  virtual std::string info() = 0;

  // disallow default and copy constructor, assignment operator
  // private:
+9 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@
#include "force.h"
#include "group.h"
#include "error.h"
#include <string>
#include "fmt/format.h"

using namespace LAMMPS_NS;

@@ -75,14 +77,17 @@ void ImbalanceGroup::compute(double *weight)

/* -------------------------------------------------------------------- */

void ImbalanceGroup::info(FILE *fp)
std::string ImbalanceGroup::info()
{
  std::string mesg = "";

  if (num > 0) {
    const char * const * const names = group->names;

    fprintf(fp,"  group weights:");
    mesg += "  group weights:";
    for (int i = 0; i < num; ++i)
      fprintf(fp," %s=%g",names[id[i]],factor[i]);
    fputs("\n",fp);
      mesg += fmt::format(" {}={}",names[id[i]],factor[i]);
    mesg += "\n";
  }
  return mesg;
}
+3 −3
Original line number Diff line number Diff line
@@ -24,11 +24,11 @@ class ImbalanceGroup : public Imbalance {
  virtual ~ImbalanceGroup();

  // parse options, return number of arguments consumed
  virtual int options(int, char **);
  virtual int options(int, char **) override;
  // compute and apply weight factors to local atom array
  virtual void compute(double *);
  virtual void compute(double *) override;
  // print information about the state of this imbalance compute
  virtual void info(FILE *);
  virtual std::string info() override;

 private:
  int num;                     // number of groups with weights
Loading