more output simplification with fmtlib, std::string, and utils::logmesg()

This commit is contained in:
Axel Kohlmeyer
2020-06-25 23:48:17 -04:00
parent 84ec2cc39b
commit f2a4d12f7e
4 changed files with 111 additions and 166 deletions

View File

@ -210,8 +210,8 @@ void Min::init()
void Min::setup(int flag)
{
if (comm->me == 0 && screen) {
fprintf(screen,"Setting up %s style minimization ...\n",
update->minimize_style);
fmt::print(screen,"Setting up {} style minimization ...\n",
update->minimize_style);
if (flag) {
fmt::print(screen," Unit style : {}\n", update->unit_style);
fmt::print(screen," Current step : {}\n", update->ntimestep);

View File

@ -908,16 +908,10 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
fix[ifix]->restart(state_restart_global[i]);
used_restart_global[i] = 1;
fix[ifix]->restart_reset = 1;
if (comm->me == 0) {
if (screen)
fprintf(screen,"Resetting global fix info from restart file:\n");
if (logfile)
fprintf(logfile,"Resetting global fix info from restart file:\n");
if (screen) fprintf(screen," fix style: %s, fix ID: %s\n",
fix[ifix]->style,fix[ifix]->id);
if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n",
fix[ifix]->style,fix[ifix]->id);
}
if (comm->me == 0)
utils::logmesg(lmp,fmt::format("Resetting global fix info from restart file:\n"
" fix style: {}, fix ID: {}\n",
fix[ifix]->style,fix[ifix]->id));
}
// check if Fix is in restart_peratom list
@ -930,16 +924,10 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
for (int j = 0; j < atom->nlocal; j++)
fix[ifix]->unpack_restart(j,index_restart_peratom[i]);
fix[ifix]->restart_reset = 1;
if (comm->me == 0) {
if (screen)
fprintf(screen,"Resetting peratom fix info from restart file:\n");
if (logfile)
fprintf(logfile,"Resetting peratom fix info from restart file:\n");
if (screen) fprintf(screen," fix style: %s, fix ID: %s\n",
fix[ifix]->style,fix[ifix]->id);
if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n",
fix[ifix]->style,fix[ifix]->id);
}
if (comm->me == 0)
utils::logmesg(lmp,fmt::format("Resetting peratom fix info from restart file:\n"
" fix style: {}, fix ID: {}\n",
fix[ifix]->style,fix[ifix]->id));
}
// increment nfix (if new)
@ -1505,21 +1493,13 @@ void Modify::restart_deallocate(int flag)
for (i = 0; i < nfix_restart_global; i++)
if (used_restart_global[i] == 0) break;
if (i == nfix_restart_global) {
if (screen)
fprintf(screen,"All restart file global fix info "
"was re-assigned\n");
if (logfile)
fprintf(logfile,"All restart file global fix info "
"was re-assigned\n");
utils::logmesg(lmp,"All restart file global fix info was re-assigned\n");
} else {
if (screen) fprintf(screen,"Unused restart file global fix info:\n");
if (logfile) fprintf(logfile,"Unused restart file global fix info:\n");
utils::logmesg(lmp,"Unused restart file global fix info:\n");
for (i = 0; i < nfix_restart_global; i++) {
if (used_restart_global[i]) continue;
if (screen) fprintf(screen," fix style: %s, fix ID: %s\n",
style_restart_global[i],id_restart_global[i]);
if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n",
style_restart_global[i],id_restart_global[i]);
utils::logmesg(lmp,fmt::format(" fix style: {}, fix ID: {}\n",
style_restart_global[i],id_restart_global[i]));
}
}
}
@ -1541,21 +1521,13 @@ void Modify::restart_deallocate(int flag)
for (i = 0; i < nfix_restart_peratom; i++)
if (used_restart_peratom[i] == 0) break;
if (i == nfix_restart_peratom) {
if (screen)
fprintf(screen,"All restart file peratom fix info "
"was re-assigned\n");
if (logfile)
fprintf(logfile,"All restart file peratom fix info "
"was re-assigned\n");
utils::logmesg(lmp,"All restart file peratom fix info was re-assigned\n");
} else {
if (screen) fprintf(screen,"Unused restart file peratom fix info:\n");
if (logfile) fprintf(logfile,"Unused restart file peratom fix info:\n");
utils::logmesg(lmp,"Unused restart file peratom fix info:\n");
for (i = 0; i < nfix_restart_peratom; i++) {
if (used_restart_peratom[i]) continue;
if (screen) fprintf(screen," fix style: %s, fix ID: %s\n",
style_restart_peratom[i],id_restart_peratom[i]);
if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n",
style_restart_peratom[i],id_restart_peratom[i]);
utils::logmesg(lmp,fmt::format(" fix style: {}, fix ID: {}\n",
style_restart_peratom[i],id_restart_peratom[i]));
}
}
}

View File

@ -146,24 +146,17 @@ Molecule::Molecule(LAMMPS *lmp, int narg, char **arg, int &index) :
// stats
if (me == 0) {
if (screen)
fprintf(screen,"Read molecule template %s:\n %d molecules\n"
" %d atoms with max type %d\n %d bonds with max type %d\n"
" %d angles with max type %d\n %d dihedrals with max type %d\n"
" %d impropers with max type %d\n",
id,nmolecules,natoms,ntypes,
nbonds,nbondtypes,nangles,nangletypes,
ndihedrals,ndihedraltypes,nimpropers,nimpropertypes);
if (logfile)
fprintf(logfile,"Read molecule template %s:\n %d molecules\n"
" %d atoms with max type %d\n %d bonds with max type %d\n"
" %d angles with max type %d\n %d dihedrals with max type %d\n"
" %d impropers with max type %d\n",
id,nmolecules,natoms,ntypes,
nbonds,nbondtypes,nangles,nangletypes,
ndihedrals,ndihedraltypes,nimpropers,nimpropertypes);
}
if (me == 0)
utils::logmesg(lmp,fmt::format("Read molecule template {}:\n"
" {} molecules\n"
" {} atoms with max type {}\n"
" {} bonds with max type {}\n"
" {} angles with max type {}\n"
" {} dihedrals with max type {}\n"
" {} impropers with max type {}\n",
id,nmolecules,natoms,ntypes,
nbonds,nbondtypes,nangles,nangletypes,
ndihedrals,ndihedraltypes,nimpropers,nimpropertypes));
}
/* ---------------------------------------------------------------------- */

View File

@ -47,6 +47,7 @@
#include "memory.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"
using namespace LAMMPS_NS;
using namespace NeighConst;
@ -1439,7 +1440,6 @@ void Neighbor::print_pairwise_info()
{
int i,m;
NeighRequest *rq;
FILE *out;
const double cutghost = MAX(cutneighmax,comm->cutghostuser);
@ -1461,110 +1461,90 @@ void Neighbor::print_pairwise_info()
else nperpetual++;
}
for (m = 0; m < 2; m++) {
if (m == 0) out = screen;
else out = logfile;
std::string out = "Neighbor list info ...\n";
out += fmt::format(" update every {} steps, delay {} steps, check {}\n",
every,delay,dist_check ? "yes" : "no");
out += fmt::format(" max neighbors/atom: {}, page size: {}\n",
oneatom, pgsize);
out += fmt::format(" master list distance cutoff = {}\n",cutneighmax);
out += fmt::format(" ghost atom cutoff = {}\n",cutghost);
if (style != Neighbor::NSQ)
out += fmt::format(" binsize = {}, bins = {} {} {}\n",binsize,
ceil(bbox[0]/binsize), ceil(bbox[1]/binsize),
ceil(bbox[2]/binsize));
if (out) {
fprintf(out,"Neighbor list info ...\n");
fprintf(out," update every %d steps, delay %d steps, check %s\n",
every,delay,dist_check ? "yes" : "no");
fprintf(out," max neighbors/atom: %d, page size: %d\n",
oneatom, pgsize);
fprintf(out," master list distance cutoff = %g\n",cutneighmax);
fprintf(out," ghost atom cutoff = %g\n",cutghost);
if (style != Neighbor::NSQ)
fprintf(out," binsize = %g, bins = %g %g %g\n",binsize,
ceil(bbox[0]/binsize), ceil(bbox[1]/binsize),
ceil(bbox[2]/binsize));
out += fmt::format(" {} neighbor lists, perpetual/occasional/extra = {} {} {}\n",
nlist,nperpetual,noccasional,nextra);
fprintf(out," %d neighbor lists, "
"perpetual/occasional/extra = %d %d %d\n",
nlist,nperpetual,noccasional,nextra);
for (i = 0; i < nlist; i++) {
rq = requests[i];
if (rq->pair) {
char *pname = force->pair_match_ptr((Pair *) rq->requestor);
fprintf(out," (%d) pair %s",i+1,pname);
} else if (rq->fix) {
fprintf(out," (%d) fix %s",i+1,((Fix *) rq->requestor)->style);
} else if (rq->compute) {
fprintf(out," (%d) compute %s",i+1,
((Compute *) rq->requestor)->style);
} else if (rq->command) {
fprintf(out," (%d) command %s",i+1,rq->command_style);
} else if (rq->neigh) {
fprintf(out," (%d) neighbor class addition",i+1);
}
if (rq->occasional) fprintf(out,", occasional");
else fprintf(out,", perpetual");
// order these to get single output of most relevant
if (rq->copy)
fprintf(out,", copy from (%d)",rq->copylist+1);
else if (rq->halffull)
fprintf(out,", half/full from (%d)",rq->halffulllist+1);
else if (rq->skip)
fprintf(out,", skip from (%d)",rq->skiplist+1);
fprintf(out,"\n");
// list of neigh list attributes
fprintf(out," attributes: ");
if (rq->half) fprintf(out,"half");
else if (rq->full) fprintf(out,"full");
if (rq->newton == 0) {
if (force->newton_pair) fprintf(out,", newton on");
else fprintf(out,", newton off");
} else if (rq->newton == 1) fprintf(out,", newton on");
else if (rq->newton == 2) fprintf(out,", newton off");
if (rq->ghost) fprintf(out,", ghost");
if (rq->size) fprintf(out,", size");
if (rq->history) fprintf(out,", history");
if (rq->granonesided) fprintf(out,", onesided");
if (rq->respamiddle) fprintf(out,", respa outer/middle/inner");
else if (rq->respainner) fprintf(out,", respa outer/inner");
if (rq->bond) fprintf(out,", bond");
if (rq->omp) fprintf(out,", omp");
if (rq->intel) fprintf(out,", intel");
if (rq->kokkos_device) fprintf(out,", kokkos_device");
if (rq->kokkos_host) fprintf(out,", kokkos_host");
if (rq->ssa) fprintf(out,", ssa");
if (rq->cut) fprintf(out,", cut %g",rq->cutoff);
if (rq->off2on) fprintf(out,", off2on");
fprintf(out,"\n");
fprintf(out," ");
if (lists[i]->pair_method == 0) fprintf(out,"pair build: none\n");
else fprintf(out,"pair build: %s\n",pairnames[lists[i]->pair_method-1]);
fprintf(out," ");
if (lists[i]->stencil_method == 0) fprintf(out,"stencil: none\n");
else fprintf(out,"stencil: %s\n",
stencilnames[lists[i]->stencil_method-1]);
fprintf(out," ");
if (lists[i]->bin_method == 0) fprintf(out,"bin: none\n");
else fprintf(out,"bin: %s\n",binnames[lists[i]->bin_method-1]);
}
/*
fprintf(out," %d stencil methods\n",nstencil);
for (i = 0; i < nstencil; i++)
fprintf(out," (%d) %s\n",
i+1,stencilnames[neigh_stencil[i]->istyle-1]);
fprintf(out," %d bin methods\n",nbin);
for (i = 0; i < nbin; i++)
fprintf(out," (%d) %s\n",i+1,binnames[neigh_bin[i]->istyle-1]);
*/
for (i = 0; i < nlist; i++) {
rq = requests[i];
if (rq->pair) {
char *pname = force->pair_match_ptr((Pair *) rq->requestor);
out += fmt::format(" ({}) pair {}",i+1,pname);
} else if (rq->fix) {
out += fmt::format(" ({}) fix {}",i+1,((Fix *) rq->requestor)->style);
} else if (rq->compute) {
out += fmt::format(" ({}) compute {}",i+1,((Compute *) rq->requestor)->style);
} else if (rq->command) {
out += fmt::format(" ({}) command {}",i+1,rq->command_style);
} else if (rq->neigh) {
out += fmt::format(" ({}) neighbor class addition",i+1);
}
if (rq->occasional) out += ", occasional";
else out += ", perpetual";
// order these to get single output of most relevant
if (rq->copy)
out += fmt::format(", copy from ({})",rq->copylist+1);
else if (rq->halffull)
out += fmt::format(", half/full from ({})",rq->halffulllist+1);
else if (rq->skip)
out += fmt::format(", skip from ({})",rq->skiplist+1);
out += "\n";
// list of neigh list attributes
out += " attributes: ";
if (rq->half) out += "half";
else if (rq->full) out += "full";
if (rq->newton == 0) {
if (force->newton_pair) out += ", newton on";
else out += ", newton off";
} else if (rq->newton == 1) out += ", newton on";
else if (rq->newton == 2) out += ", newton off";
if (rq->ghost) out += ", ghost";
if (rq->size) out += ", size";
if (rq->history) out += ", history";
if (rq->granonesided) out += ", onesided";
if (rq->respamiddle) out += ", respa outer/middle/inner";
else if (rq->respainner) out += ", respa outer/inner";
if (rq->bond) out += ", bond";
if (rq->omp) out += ", omp";
if (rq->intel) out += ", intel";
if (rq->kokkos_device) out += ", kokkos_device";
if (rq->kokkos_host) out += ", kokkos_host";
if (rq->ssa) out += ", ssa";
if (rq->cut) out += fmt::format(", cut {}",rq->cutoff);
if (rq->off2on) out += ", off2on";
out += "\n";
out += " ";
if (lists[i]->pair_method == 0) out += "pair build: none\n";
else out += fmt::format("pair build: {}\n",pairnames[lists[i]->pair_method-1]);
out += " ";
if (lists[i]->stencil_method == 0) out += "stencil: none\n";
else out += fmt::format("stencil: {}\n",stencilnames[lists[i]->stencil_method-1]);
out += " ";
if (lists[i]->bin_method == 0) out += "bin: none\n";
else out += fmt::format("bin: {}\n",binnames[lists[i]->bin_method-1]);
utils::logmesg(lmp,out);
}
}