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

This commit is contained in:
Axel Kohlmeyer
2020-06-03 21:21:58 -04:00
parent 9e8ce240a0
commit c0fb794848
13 changed files with 67 additions and 88 deletions

View File

@ -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);
}
}

View File

@ -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));
}

View File

@ -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:

View File

@ -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;
}

View File

@ -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

View File

@ -20,6 +20,7 @@
#include "neigh_request.h"
#include "neigh_list.h"
#include "error.h"
#include "fmt/format.h"
using namespace LAMMPS_NS;
@ -106,7 +107,7 @@ void ImbalanceNeigh::compute(double *weight)
/* -------------------------------------------------------------------- */
void ImbalanceNeigh::info(FILE *fp)
std::string ImbalanceNeigh::info()
{
fprintf(fp," neigh weight factor: %g\n",factor);
return fmt::format(" neighbor weight factor: {}\n",factor);
}

View File

@ -25,11 +25,11 @@ class ImbalanceNeigh : public Imbalance {
public:
// 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:
double factor; // weight factor for neighbor imbalance

View File

@ -15,6 +15,7 @@
#include <cstring>
#include "atom.h"
#include "error.h"
#include "fmt/format.h"
using namespace LAMMPS_NS;
@ -62,7 +63,7 @@ void ImbalanceStore::compute(double *weight)
/* -------------------------------------------------------------------- */
void ImbalanceStore::info(FILE *fp)
std::string ImbalanceStore::info()
{
fprintf(fp," storing weight in atom property d_%s\n",name);
return fmt::format(" storing weight in atom property d_{}\n",name);
}

View File

@ -25,11 +25,11 @@ class ImbalanceStore : public Imbalance {
public:
// parse options, return number of arguments consumed
virtual int options(int, char **);
virtual int options(int, char **) override;
// compute per-atom imbalance and apply to weight array
virtual void compute(double *);
virtual void compute(double *) override;
// print information about the state of this imbalance compute (required)
virtual void info(FILE *);
virtual std::string info() override;
private:
char *name; // property name

View File

@ -17,6 +17,7 @@
#include "force.h"
#include "timer.h"
#include "error.h"
#include "fmt/format.h"
using namespace LAMMPS_NS;
@ -104,7 +105,7 @@ void ImbalanceTime::compute(double *weight)
/* -------------------------------------------------------------------- */
void ImbalanceTime::info(FILE *fp)
std::string ImbalanceTime::info()
{
fprintf(fp," time weight factor: %g\n",factor);
return fmt::format(" time weight factor: {}\n",factor);
}

View File

@ -25,13 +25,13 @@ class ImbalanceTime : public Imbalance {
public:
// parse options, return number of arguments consumed
virtual int options(int, char **);
virtual int options(int, char **) override;
// reinitialize internal data
virtual void init(int);
virtual void init(int) 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:
double factor; // weight factor for time imbalance

View File

@ -20,6 +20,7 @@
#include "variable.h"
#include "memory.h"
#include "error.h"
#include "fmt/format.h"
using namespace LAMMPS_NS;
@ -88,7 +89,7 @@ void ImbalanceVar::compute(double *weight)
/* -------------------------------------------------------------------- */
void ImbalanceVar::info(FILE *fp)
std::string ImbalanceVar::info()
{
fprintf(fp," weight variable: %s\n",name);
return fmt::format(" weight variable: {}\n",name);
}

View File

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