Merge pull request #2190 from akohlmey/more-fmtlib-uses

Reduce use of local print buffers, simplify output handling with std::string and fmtlib
This commit is contained in:
Axel Kohlmeyer
2020-06-26 12:08:46 -04:00
committed by GitHub
39 changed files with 520 additions and 936 deletions

View File

@ -88,6 +88,7 @@ melt: rapid melt of 3d LJ system
message: client/server coupling of 2 codes message: client/server coupling of 2 codes
micelle: self-assembly of small lipid-like molecules into 2d bilayers micelle: self-assembly of small lipid-like molecules into 2d bilayers
min: energy minimization of 2d LJ melt min: energy minimization of 2d LJ melt
mliap: examples for using several bundled MLIAP potentials
mscg: parameterize a multi-scale coarse-graining (MSCG) model mscg: parameterize a multi-scale coarse-graining (MSCG) model
msst: MSST shock dynamics msst: MSST shock dynamics
nb3b: use of nonbonded 3-body harmonic pair style nb3b: use of nonbonded 3-body harmonic pair style

View File

@ -125,9 +125,6 @@
*/ */
/*r @file pairhash.h @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
# include "refobj.h" # include "refobj.h"

View File

@ -1,4 +1,4 @@
# DATE: 2016-09-26 CONTRIBUTOR: Robert Latour, latourr@clemson.edu CITATION: TBA # DATE: 2016-09-26 UNITS: real CONTRIBUTOR: Robert Latour, latourr@clemson.edu CITATION: TBA
# Title: charmm22/charmm27 dihedral correction map # Title: charmm22/charmm27 dihedral correction map
# alanine map, type 1 # alanine map, type 1

View File

@ -1,4 +1,4 @@
# DATE: 2016-09-26 CONTRIBUTOR: Robert Latour, latourr@clemson.edu CITATION: TBA # DATE: 2016-09-26 UNITS:real CONTRIBUTOR: Robert Latour, latourr@clemson.edu CITATION: TBA
# Title: charmm36 dihedral correction map # Title: charmm36 dihedral correction map
# alanine map, type 1 # alanine map, type 1

View File

@ -669,6 +669,7 @@ void PairEAM::file2array()
// create a z2r array for each file against other files, only for I >= J // create a z2r array for each file against other files, only for I >= J
// interpolate zri and zrj to a single grid and cutoff // interpolate zri and zrj to a single grid and cutoff
// final z2r includes unit conversion of 27.2 eV/Hartree and 0.529 Ang/Bohr
double zri,zrj; double zri,zrj;

View File

@ -83,7 +83,6 @@ void BondFENE::compute(int eflag, int vflag)
// if r -> r0, then rlogarg < 0.0 which is an error // if r -> r0, then rlogarg < 0.0 which is an error
// issue a warning and reset rlogarg = epsilon // issue a warning and reset rlogarg = epsilon
// if r > 2*r0 something serious is wrong, abort // if r > 2*r0 something serious is wrong, abort
printf("r = %g r0 = %g rlogarg = %g\n",sqrt(rsq),sqrt(r0sq),rlogarg);
if (rlogarg < 0.1) { if (rlogarg < 0.1) {
error->warning(FLERR,fmt::format("FENE bond too long: {} {} {} {}", error->warning(FLERR,fmt::format("FENE bond too long: {} {} {} {}",

View File

@ -18,6 +18,7 @@
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "tokenizer.h" #include "tokenizer.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -215,12 +216,9 @@ void AtomVecHybrid::process_args(int narg, char **arg)
for (int idup = 0; idup < ndupfield; idup++) { for (int idup = 0; idup < ndupfield; idup++) {
char *dup = (char *) dupfield[idup]; char *dup = (char *) dupfield[idup];
ptr = strstr(concat_grow,dup); ptr = strstr(concat_grow,dup);
if (ptr && strstr(ptr+1,dup)) { if ((ptr && strstr(ptr+1,dup)) && (comm->me == 0))
char str[128]; error->warning(FLERR,fmt::format("Peratom {} is in multiple sub-styles "
sprintf(str,"Peratom %s is in multiple sub-styles - " "- must be used consistently",dup));
"must be used consistently",dup);
if (comm->me == 0) error->warning(FLERR,str);
}
} }
delete [] concat_grow; delete [] concat_grow;

View File

@ -30,6 +30,7 @@
#include "comm.h" #include "comm.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -184,11 +185,9 @@ void ComputeCNAAtom::compute_peratom()
int nerrorall; int nerrorall;
MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world); MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world);
if (nerrorall && comm->me == 0) { if (nerrorall && comm->me == 0)
char str[128]; error->warning(FLERR,fmt::format("Too many neighbors in CNA for {} "
sprintf(str,"Too many neighbors in CNA for %d atoms",nerrorall); "atoms",nerrorall),0);
error->warning(FLERR,str,0);
}
// compute CNA for each atom in group // compute CNA for each atom in group
// only performed if # of nearest neighbors = 12 or 14 (fcc,hcp) // only performed if # of nearest neighbors = 12 or 14 (fcc,hcp)
@ -345,11 +344,9 @@ void ComputeCNAAtom::compute_peratom()
// warning message // warning message
MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world); MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world);
if (nerrorall && comm->me == 0) { if (nerrorall && comm->me == 0)
char str[128]; error->warning(FLERR,fmt::format("Too many common neighbors in CNA {} "
sprintf(str,"Too many common neighbors in CNA %d times",nerrorall); "times", nerrorall));
error->warning(FLERR,str);
}
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

View File

@ -147,12 +147,9 @@ void ComputeGroupGroup::init()
if (kspaceflag) { if (kspaceflag) {
kspace_correction(); kspace_correction();
if (fabs(e_correction) > SMALL && comm->me == 0) { if ((fabs(e_correction) > SMALL) && (comm->me == 0))
char str[128]; error->warning(FLERR,"Both groups in compute group/group have a net charge; "
sprintf(str,"Both groups in compute group/group have a net charge; "
"the Kspace boundary correction to energy will be non-zero"); "the Kspace boundary correction to energy will be non-zero");
error->warning(FLERR,str);
}
} }
// recheck that group 2 has not been deleted // recheck that group 2 has not been deleted

View File

@ -32,6 +32,7 @@
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "math_const.h" #include "math_const.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using namespace MathConst;
@ -715,11 +716,8 @@ void ComputeOrientOrderAtom::init_clebsch_gordan()
double ComputeOrientOrderAtom::factorial(int n) double ComputeOrientOrderAtom::factorial(int n)
{ {
if (n < 0 || n > nmaxfactorial) { if (n < 0 || n > nmaxfactorial)
char str[128]; error->all(FLERR,fmt::format("Invalid argument to factorial {}", n));
sprintf(str, "Invalid argument to factorial %d", n);
error->all(FLERR, str);
}
return nfac_table[n]; return nfac_table[n];
} }

View File

@ -126,9 +126,7 @@ void DumpCFG::write_header(bigint n)
if (atom->peri_flag) scale = atom->pdscale; if (atom->peri_flag) scale = atom->pdscale;
else if (unwrapflag == 1) scale = UNWRAPEXPAND; else if (unwrapflag == 1) scale = UNWRAPEXPAND;
char str[64]; fprintf(fp,"Number of particles = " BIGINT_FORMAT "\n", n);
sprintf(str,"Number of particles = %s\n",BIGINT_FORMAT);
fprintf(fp,str,n);
fprintf(fp,"A = %g Angstrom (basic length-scale)\n",scale); fprintf(fp,"A = %g Angstrom (basic length-scale)\n",scale);
fprintf(fp,"H0(1,1) = %g A\n",domain->xprd); fprintf(fp,"H0(1,1) = %g A\n",domain->xprd);
fprintf(fp,"H0(1,2) = 0 A \n"); fprintf(fp,"H0(1,2) = 0 A \n");

View File

@ -20,6 +20,7 @@
#include "comm.h" #include "comm.h"
#include "force.h" #include "force.h"
#include "error.h" #include "error.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -58,11 +59,9 @@ void DumpMovie::openfile()
fp = popen(moviecmd,"w"); fp = popen(moviecmd,"w");
#endif #endif
if (fp == NULL) { if (fp == NULL)
char str[128]; error->one(FLERR,fmt::format("Failed to open FFmpeg pipeline to "
sprintf(str,"Failed to open FFmpeg pipeline to file %s",filename); "file {}",filename));
error->one(FLERR,str);
}
} }
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -32,6 +32,8 @@
#include "error.h" #include "error.h"
#include "timer.h" #include "timer.h"
#include "universe.h" #include "universe.h"
#include "utils.h"
#include "fmt/format.h"
#ifdef LMP_USER_OMP #ifdef LMP_USER_OMP
#include "modify.h" #include "modify.h"
@ -121,12 +123,9 @@ void Finish::end(int flag)
if (me == 0) { if (me == 0) {
int ntasks = nprocs * nthreads; int ntasks = nprocs * nthreads;
const char fmt1[] = "Loop time of %g on %d procs " utils::logmesg(lmp,fmt::format("Loop time of {:.6g} on {} procs for "
"for %d steps with " BIGINT_FORMAT " atoms\n\n"; "{} steps with {} atoms\n\n",time_loop,
if (screen) fprintf(screen,fmt1,time_loop,ntasks,update->nsteps, ntasks,update->nsteps,atom->natoms));
atom->natoms);
if (logfile) fprintf(logfile,fmt1,time_loop,ntasks,update->nsteps,
atom->natoms);
// Gromacs/NAMD-style performance metric for suitable unit settings // Gromacs/NAMD-style performance metric for suitable unit settings
@ -144,24 +143,20 @@ void Finish::end(int flag)
if (strcmp(update->unit_style,"lj") == 0) { if (strcmp(update->unit_style,"lj") == 0) {
double tau_day = 24.0*3600.0 / t_step * update->dt / one_fs; double tau_day = 24.0*3600.0 / t_step * update->dt / one_fs;
const char perf[] = "Performance: %.3f tau/day, %.3f timesteps/s\n"; utils::logmesg(lmp,fmt::format("Performance: {:.3f} tau/day, {:.3f} "
if (screen) fprintf(screen,perf,tau_day,step_t); "timesteps/s\n",tau_day,step_t));
if (logfile) fprintf(logfile,perf,tau_day,step_t);
} else if (strcmp(update->unit_style,"electron") == 0) { } else if (strcmp(update->unit_style,"electron") == 0) {
double hrs_fs = t_step / update->dt * one_fs / 3600.0; double hrs_fs = t_step / update->dt * one_fs / 3600.0;
double fs_day = 24.0*3600.0 / t_step * update->dt / one_fs; double fs_day = 24.0*3600.0 / t_step * update->dt / one_fs;
const char perf[] = utils::logmesg(lmp,fmt::format("Performance: {:.3f} fs/day, {:.3f} "
"Performance: %.3f fs/day, %.3f hours/fs, %.3f timesteps/s\n"; "hours/fs, {:.3f} timesteps/s\n",
if (screen) fprintf(screen,perf,fs_day,hrs_fs,step_t); fs_day,hrs_fs,step_t));
if (logfile) fprintf(logfile,perf,fs_day,hrs_fs,step_t);
} else { } else {
double hrs_ns = t_step / update->dt * 1000000.0 * one_fs / 3600.0; double hrs_ns = t_step / update->dt * 1000000.0 * one_fs / 3600.0;
double ns_day = 24.0*3600.0 / t_step * update->dt / one_fs/1000000.0; double ns_day = 24.0*3600.0 / t_step * update->dt / one_fs/1000000.0;
const char perf[] = utils::logmesg(lmp,fmt::format("Performance: {:.3f} ns/day, {:.3f} "
"Performance: %.3f ns/day, %.3f hours/ns, %.3f timesteps/s\n"; "hours/ns, {:.3f} timesteps/s\n",
if (screen) fprintf(screen,perf,ns_day,hrs_ns,step_t); ns_day,hrs_ns,step_t));
if (logfile) fprintf(logfile,perf,ns_day,hrs_ns,step_t);
} }
} }
@ -169,23 +164,17 @@ void Finish::end(int flag)
if (timeflag) { if (timeflag) {
if (lmp->kokkos) { if (lmp->kokkos) {
const char fmt2[] = utils::logmesg(lmp,fmt::format("{:.1f}% CPU use with {} MPI tasks "
"%.1f%% CPU use with %d MPI tasks x %d OpenMP threads\n"; "x {} OpenMP threads\n",cpu_loop,nprocs,
if (screen) fprintf(screen,fmt2,cpu_loop,nprocs, lmp->kokkos->nthreads));
lmp->kokkos->nthreads);
if (logfile) fprintf(logfile,fmt2,cpu_loop,nprocs,
lmp->kokkos->nthreads);
} else { } else {
#if defined(_OPENMP) #if defined(_OPENMP)
const char fmt2[] = utils::logmesg(lmp,fmt::format("{:.1f}% CPU use with {} MPI tasks "
"%.1f%% CPU use with %d MPI tasks x %d OpenMP threads\n"; "x {} OpenMP threads\n",
if (screen) fprintf(screen,fmt2,cpu_loop,nprocs,nthreads); cpu_loop,nprocs,nthreads));
if (logfile) fprintf(logfile,fmt2,cpu_loop,nprocs,nthreads);
#else #else
const char fmt2[] = utils::logmesg(lmp,fmt::format("{:.1f}% CPU use with {} MPI tasks "
"%.1f%% CPU use with %d MPI tasks x no OpenMP threads\n"; "x no OpenMP threads\n",cpu_loop,nprocs));
if (screen) fprintf(screen,fmt2,cpu_loop,nprocs);
if (logfile) fprintf(logfile,fmt2,cpu_loop,nprocs);
#endif #endif
} }
} }
@ -206,289 +195,140 @@ void Finish::end(int flag)
if (minflag) { if (minflag) {
if (me == 0) { if (me == 0) {
if (screen) fprintf(screen,"\n"); std::string mesg = "\nMinimization stats:\n";
if (logfile) fprintf(logfile,"\n");
}
if (me == 0) { mesg += fmt::format(" Stopping criterion = {}\n",
if (screen) {
fprintf(screen,"Minimization stats:\n");
fprintf(screen," Stopping criterion = %s\n",
update->minimize->stopstr); update->minimize->stopstr);
fprintf(screen," Energy initial, next-to-last, final = \n" mesg += fmt::format(" Energy initial, next-to-last, final = \n"
" %18.12g %18.12g %18.12g\n", " {:18.15g} {:18.15g} {:18.15g}\n",
update->minimize->einitial,update->minimize->eprevious, update->minimize->einitial,
update->minimize->eprevious,
update->minimize->efinal); update->minimize->efinal);
fprintf(screen," Force two-norm initial, final = %g %g\n", mesg += fmt::format(" Force two-norm initial, final = {} {}\n",
update->minimize->fnorm2_init,update->minimize->fnorm2_final); update->minimize->fnorm2_init,update->minimize->fnorm2_final);
fprintf(screen," Force max component initial, final = %g %g\n", mesg += fmt::format(" Force max component initial, final = {} {}\n",
update->minimize->fnorminf_init, update->minimize->fnorminf_init,
update->minimize->fnorminf_final); update->minimize->fnorminf_final);
fprintf(screen," Final line search alpha, max atom move = %g %g\n", mesg += fmt::format(" Final line search alpha, max atom move = {} {}\n",
update->minimize->alpha_final, update->minimize->alpha_final,
update->minimize->alpha_final* update->minimize->alpha_final*
update->minimize->fnorminf_final); update->minimize->fnorminf_final);
fprintf(screen," Iterations, force evaluations = %d %d\n", mesg += fmt::format(" Iterations, force evaluations = {} {}\n",
update->minimize->niter,update->minimize->neval); update->minimize->niter,update->minimize->neval);
} utils::logmesg(lmp,mesg);
if (logfile) {
fprintf(logfile,"Minimization stats:\n");
fprintf(logfile," Stopping criterion = %s\n",
update->minimize->stopstr);
fprintf(logfile," Energy initial, next-to-last, final = \n"
" %18.12g %18.12g %18.12g\n",
update->minimize->einitial,update->minimize->eprevious,
update->minimize->efinal);
fprintf(logfile," Force two-norm initial, final = %g %g\n",
update->minimize->fnorm2_init,update->minimize->fnorm2_final);
fprintf(logfile," Force max component initial, final = %g %g\n",
update->minimize->fnorminf_init,
update->minimize->fnorminf_final);
fprintf(logfile," Final line search alpha, max atom move = %g %g\n",
update->minimize->alpha_final,
update->minimize->alpha_final*
update->minimize->fnorminf_final);
fprintf(logfile," Iterations, force evaluations = %d %d\n",
update->minimize->niter,update->minimize->neval);
}
} }
} }
// PRD stats // PRD stats
if (prdflag) { if (prdflag) {
if (me == 0) { if (me == 0) utils::logmesg(lmp,"\nPRD stats:\n");
if (screen) fprintf(screen,"\nPRD stats:\n");
if (logfile) fprintf(logfile,"\nPRD stats:\n");
}
time = timer->get_wall(Timer::DEPHASE); time = timer->get_wall(Timer::DEPHASE);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Dephase time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Dephase time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Dephase time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = timer->get_wall(Timer::DYNAMICS); time = timer->get_wall(Timer::DYNAMICS);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Dynamics time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Dynamics time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Dynamics time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = timer->get_wall(Timer::QUENCH); time = timer->get_wall(Timer::QUENCH);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Quench time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Quench time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Quench time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = timer->get_wall(Timer::REPCOMM); time = timer->get_wall(Timer::REPCOMM);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Comm time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Comm time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Comm time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = timer->get_wall(Timer::REPOUT); time = timer->get_wall(Timer::REPOUT);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Output time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Output time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Output time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = time_other; time = time_other;
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { // XXXX: replica comm, replica output if (me == 0) utils::logmesg(lmp,fmt::format(" Other time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Other time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Other time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
} }
// TAD stats // TAD stats
if (tadflag) { if (tadflag) {
if (me == 0) { if (me == 0) utils::logmesg(lmp,"\nTAD stats:\n");
if (screen) fprintf(screen,"\n");
if (logfile) fprintf(logfile,"\n");
}
if (screen) fprintf(screen,"TAD stats:\n");
if (logfile) fprintf(logfile,"TAD stats:\n");
time = timer->get_wall(Timer::NEB); time = timer->get_wall(Timer::NEB);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" NEB time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," NEB time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," NEB time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = timer->get_wall(Timer::DYNAMICS); time = timer->get_wall(Timer::DYNAMICS);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Dynamics time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Dynamics time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Dynamics time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = timer->get_wall(Timer::QUENCH); time = timer->get_wall(Timer::QUENCH);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Quench time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Quench time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Quench time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = timer->get_wall(Timer::REPCOMM); time = timer->get_wall(Timer::REPCOMM);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Comm time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Comm time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Comm time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = timer->get_wall(Timer::REPOUT); time = timer->get_wall(Timer::REPOUT);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Output time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Output time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Output time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = time_other; time = time_other;
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Other time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Other time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Other time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
} }
// HYPER stats // HYPER stats
if (hyperflag) { if (hyperflag) {
if (me == 0) { if (me == 0) utils::logmesg(lmp,"\nHyper stats:\n");
if (screen) fprintf(screen,"\nHyper stats:\n");
if (logfile) fprintf(logfile,"\nHyper stats:\n");
}
time = timer->get_wall(Timer::DYNAMICS); time = timer->get_wall(Timer::DYNAMICS);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Dynamics time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Dynamics time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Dynamics time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = timer->get_wall(Timer::QUENCH); time = timer->get_wall(Timer::QUENCH);
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Quench time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Quench time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Quench time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
time = time_other; time = time_other;
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
if (me == 0) { if (me == 0) utils::logmesg(lmp,fmt::format(" Other time (%) = {} ({})\n",
if (screen) time,time/time_loop*100.0));
fprintf(screen," Other time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
if (logfile)
fprintf(logfile," Other time (%%) = %g (%g)\n",
time,time/time_loop*100.0);
}
} }
// further timing breakdowns // further timing breakdowns
if (timeflag && timer->has_normal()) { if (timeflag && timer->has_normal()) {
if (timer->has_full()) {
const char hdr[] = "\nMPI task timing breakdown:\n"
"Section | min time | avg time | max time "
"|%varavg| %CPU | %total\n"
"-----------------------------------------------"
"------------------------\n";
if (me == 0) { if (me == 0) {
if (screen) fputs(hdr,screen); if (timer->has_full())
if (logfile) fputs(hdr,logfile); utils::logmesg(lmp,"\nMPI task timing breakdown:\nSection | min time "
} " | avg time | max time |%varavg| %CPU | %total\n"
} else { "-----------------------------------------------------"
const char hdr[] = "\nMPI task timing breakdown:\n" "------------------\n");
"Section | min time | avg time | max time |%varavg| %total\n" else
"---------------------------------------------------------------\n"; utils::logmesg(lmp,"\nMPI task timing breakdown:\nSection | min time "
if (me == 0) { " | avg time | max time |%varavg| %total\n---------"
if (screen) fputs(hdr,screen); "------------------------------------------------------\n");
if (logfile) fputs(hdr,logfile);
}
} }
mpi_timings("Pair",timer,Timer::PAIR, world,nprocs, mpi_timings("Pair",timer,Timer::PAIR, world,nprocs,
@ -518,25 +358,19 @@ void Finish::end(int flag)
MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world);
time = tmp/nprocs; time = tmp/nprocs;
const char *fmt;
if (timer->has_full())
fmt = "Other | |%- 12.4g| | | |%6.2f\n";
else
fmt = "Other | |%- 12.4g| | |%6.2f\n";
if (me == 0) { if (me == 0) {
if (screen) fprintf(screen,fmt,time,time/time_loop*100.0); if (timer->has_full())
if (logfile) fprintf(logfile,fmt,time,time/time_loop*100.0); utils::logmesg(lmp,fmt::format("Other | | {:<10.4g} | "
" | | |{:6.2f}\n",
time,time/time_loop*100.0));
else
utils::logmesg(lmp,fmt::format("Other | | {:<10.4g} | "
" | |{:6.2f}\n",
time,time/time_loop*100.0));
} }
} }
#ifdef LMP_USER_OMP #ifdef LMP_USER_OMP
const char thr_hdr_fmt[] =
"\nThread timing breakdown (MPI rank %d):\nTotal threaded time %.4g / %.1f%%\n";
const char thr_header[] =
"Section | min time | avg time | max time |%varavg| %total\n"
"---------------------------------------------------------------\n";
int ifix = modify->find_fix("package_omp"); int ifix = modify->find_fix("package_omp");
// print thread breakdown only with full timer detail // print thread breakdown only with full timer detail
@ -552,23 +386,17 @@ void Finish::end(int flag)
thr_total /= (double) nthreads; thr_total /= (double) nthreads;
if (thr_total > 0.0) { if (thr_total > 0.0) {
if (screen) { const std::string thr_fmt =
fprintf(screen,thr_hdr_fmt,me,thr_total,thr_total/time_loop*100.0); "\nThread timing breakdown (MPI rank {}):\nTotal threaded time {:.4g} / {:.1f}%\n"
fputs(thr_header,screen); "Section | min time | avg time | max time |%varavg| %total\n"
} "---------------------------------------------------------------\n";
if (logfile) { utils::logmesg(lmp,fmt::format(thr_fmt,me,thr_total,thr_total/time_loop*100.0));
fprintf(logfile,thr_hdr_fmt,me,thr_total,thr_total/time_loop*100.0);
fputs(thr_header,logfile);
}
omp_times(fixomp,"Pair",Timer::PAIR,nthreads,screen,logfile); omp_times(fixomp,"Pair",Timer::PAIR,nthreads,screen,logfile);
if (atom->molecular) if (atom->molecular)
omp_times(fixomp,"Bond",Timer::BOND,nthreads,screen,logfile); omp_times(fixomp,"Bond",Timer::BOND,nthreads,screen,logfile);
if (force->kspace) if (force->kspace)
omp_times(fixomp,"Kspace",Timer::KSPACE,nthreads,screen,logfile); omp_times(fixomp,"Kspace",Timer::KSPACE,nthreads,screen,logfile);
omp_times(fixomp,"Neigh",Timer::NEIGH,nthreads,screen,logfile); omp_times(fixomp,"Neigh",Timer::NEIGH,nthreads,screen,logfile);
omp_times(fixomp,"Reduce",Timer::COMM,nthreads,screen,logfile); omp_times(fixomp,"Reduce",Timer::COMM,nthreads,screen,logfile);
} }
@ -590,11 +418,7 @@ void Finish::end(int flag)
// time_kspace may be 0.0 if another partition is doing Kspace // time_kspace may be 0.0 if another partition is doing Kspace
if (fftflag) { if (fftflag) {
if (me == 0) { if (me == 0) utils::logmesg(lmp,"\n");
if (screen) fprintf(screen,"\n");
if (logfile) fprintf(logfile,"\n");
}
int nsteps = update->nsteps; int nsteps = update->nsteps;
double time3d; double time3d;
@ -637,56 +461,30 @@ void Finish::end(int flag)
flop1 = nfft*nflops/1.0e9/(time1d/nsteps); flop1 = nfft*nflops/1.0e9/(time1d/nsteps);
} else fraction = flop3 = flop1 = 0.0; } else fraction = flop3 = flop1 = 0.0;
if (me == 0) { if (me == 0)
if (screen) { utils::logmesg(lmp,fmt::format("FFT time (% of Kspce) = {} ({})\n"
fprintf(screen,"FFT time (%% of Kspce) = %g (%g)\n",time3d,fraction); "FFT Gflps 3d (1d only) = {} {}\n",
fprintf(screen,"FFT Gflps 3d (1d only) = %g %g\n",flop3,flop1); time3d,fraction,flop3,flop1));
}
if (logfile) {
fprintf(logfile,"FFT time (%% of Kspce) = %g (%g)\n",time3d,fraction);
fprintf(logfile,"FFT Gflps 3d (1d only) = %g %g\n",flop3,flop1);
}
}
} }
if (histoflag) { if (histoflag) {
if (me == 0) { std::string mesg = "\n";
if (screen) fprintf(screen,"\n");
if (logfile) fprintf(logfile,"\n");
}
tmp = atom->nlocal; tmp = atom->nlocal;
stats(1,&tmp,&ave,&max,&min,10,histo); stats(1,&tmp,&ave,&max,&min,10,histo);
if (me == 0) { if (me == 0) {
if (screen) { mesg += fmt::format("Nlocal: {} ave {} max {} min\n",ave,max,min);
fprintf(screen,"Nlocal: %g ave %g max %g min\n",ave,max,min); mesg += "Histogram:";
fprintf(screen,"Histogram:"); for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]);
for (i = 0; i < 10; i++) fprintf(screen," %d",histo[i]); mesg += "\n";
fprintf(screen,"\n");
}
if (logfile) {
fprintf(logfile,"Nlocal: %g ave %g max %g min\n",ave,max,min);
fprintf(logfile,"Histogram:");
for (i = 0; i < 10; i++) fprintf(logfile," %d",histo[i]);
fprintf(logfile,"\n");
}
} }
tmp = atom->nghost; tmp = atom->nghost;
stats(1,&tmp,&ave,&max,&min,10,histo); stats(1,&tmp,&ave,&max,&min,10,histo);
if (me == 0) { if (me == 0) {
if (screen) { mesg += fmt::format("Nghost: {} ave {} max {} min\n",ave,max,min);
fprintf(screen,"Nghost: %g ave %g max %g min\n",ave,max,min); mesg += "Histogram:";
fprintf(screen,"Histogram:"); for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]);
for (i = 0; i < 10; i++) fprintf(screen," %d",histo[i]); mesg += "\n";
fprintf(screen,"\n");
}
if (logfile) {
fprintf(logfile,"Nghost: %g ave %g max %g min\n",ave,max,min);
fprintf(logfile,"Histogram:");
for (i = 0; i < 10; i++) fprintf(logfile," %d",histo[i]);
fprintf(logfile,"\n");
}
} }
// find a non-skip neighbor list containing half pairwise interactions // find a non-skip neighbor list containing half pairwise interactions
@ -712,18 +510,10 @@ void Finish::end(int flag)
tmp = nneigh; tmp = nneigh;
stats(1,&tmp,&ave,&max,&min,10,histo); stats(1,&tmp,&ave,&max,&min,10,histo);
if (me == 0) { if (me == 0) {
if (screen) { mesg += fmt::format("Neighs: {} ave {} max {} min\n",ave,max,min);
fprintf(screen,"Neighs: %g ave %g max %g min\n",ave,max,min); mesg += "Histogram:";
fprintf(screen,"Histogram:"); for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]);
for (i = 0; i < 10; i++) fprintf(screen," %d",histo[i]); mesg += "\n";
fprintf(screen,"\n");
}
if (logfile) {
fprintf(logfile,"Neighs: %g ave %g max %g min\n",ave,max,min);
fprintf(logfile,"Histogram:");
for (i = 0; i < 10; i++) fprintf(logfile," %d",histo[i]);
fprintf(logfile,"\n");
}
} }
// find a non-skip neighbor list containing full pairwise interactions // find a non-skip neighbor list containing full pairwise interactions
@ -748,27 +538,18 @@ void Finish::end(int flag)
tmp = nneighfull; tmp = nneighfull;
stats(1,&tmp,&ave,&max,&min,10,histo); stats(1,&tmp,&ave,&max,&min,10,histo);
if (me == 0) { if (me == 0) {
if (screen) { mesg += fmt::format("FullNghs: {} ave {} max {} min\n",ave,max,min);
fprintf(screen,"FullNghs: %g ave %g max %g min\n",ave,max,min); mesg += "Histogram:";
fprintf(screen,"Histogram:"); for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]);
for (i = 0; i < 10; i++) fprintf(screen," %d",histo[i]); mesg += "\n";
fprintf(screen,"\n");
}
if (logfile) {
fprintf(logfile,"FullNghs: %g ave %g max %g min\n",ave,max,min);
fprintf(logfile,"Histogram:");
for (i = 0; i < 10; i++) fprintf(logfile," %d",histo[i]);
fprintf(logfile,"\n");
}
} }
} }
if (me == 0) utils::logmesg(lmp,mesg);
} }
if (neighflag) { if (neighflag) {
if (me == 0) { if (me == 0) utils::logmesg(lmp,"\n");
if (screen) fprintf(screen,"\n");
if (logfile) fprintf(logfile,"\n");
}
tmp = MAX(nneigh,nneighfull); tmp = MAX(nneigh,nneighfull);
double nall; double nall;
@ -801,40 +582,19 @@ void Finish::end(int flag)
} }
if (me == 0) { if (me == 0) {
if (screen) { std::string mesg;
if (nall < 2.0e9)
fprintf(screen, mesg += fmt::format("Total # of neighbors = {}\n",static_cast<bigint>(nall));
"Total # of neighbors = %d\n",static_cast<int> (nall));
else fprintf(screen,"Total # of neighbors = %g\n",nall);
if (atom->natoms > 0) if (atom->natoms > 0)
fprintf(screen,"Ave neighs/atom = %g\n",nall/atom->natoms); mesg += fmt::format("Ave neighs/atom = {}\n",nall/atom->natoms);
if (atom->molecular && atom->natoms > 0) if (atom->molecular && atom->natoms > 0)
fprintf(screen,"Ave special neighs/atom = %g\n", mesg += fmt::format("Ave special neighs/atom = {}\n",
nspec_all/atom->natoms); nspec_all/atom->natoms);
fprintf(screen,"Neighbor list builds = " BIGINT_FORMAT "\n", mesg += fmt::format("Neighbor list builds = {}\n",neighbor->ncalls);
neighbor->ncalls);
if (neighbor->dist_check) if (neighbor->dist_check)
fprintf(screen,"Dangerous builds = " BIGINT_FORMAT "\n", mesg += fmt::format("Dangerous builds = {}\n",neighbor->ndanger);
neighbor->ndanger); else mesg += "Dangerous builds not checked\n";
else fprintf(screen,"Dangerous builds not checked\n"); utils::logmesg(lmp,mesg);
}
if (logfile) {
if (nall < 2.0e9)
fprintf(logfile,
"Total # of neighbors = %d\n",static_cast<int> (nall));
else fprintf(logfile,"Total # of neighbors = %g\n",nall);
if (atom->natoms > 0)
fprintf(logfile,"Ave neighs/atom = %g\n",nall/atom->natoms);
if (atom->molecular && atom->natoms > 0)
fprintf(logfile,"Ave special neighs/atom = %g\n",
nspec_all/atom->natoms);
fprintf(logfile,"Neighbor list builds = " BIGINT_FORMAT "\n",
neighbor->ncalls);
if (neighbor->dist_check)
fprintf(logfile,"Dangerous builds = " BIGINT_FORMAT "\n",
neighbor->ndanger);
else fprintf(logfile,"Dangerous builds not checked\n");
}
} }
} }
@ -921,23 +681,18 @@ void mpi_timings(const char *label, Timer *t, enum Timer::ttype tt,
else else
time_sq = 0.0; time_sq = 0.0;
if (me == 0) { if (me == 0) {
tmp = time/time_loop*100.0; tmp = time/time_loop*100.0;
if (t->has_full()) { std::string mesg;
const char fmt[] = "%-8s|%- 12.5g|%- 12.5g|%- 12.5g|%6.1f |%6.1f |%6.2f\n"; if (t->has_full())
if (scr) mesg = fmt::format("{:<8s}| {:<10.5g} | {:<10.5g} | {:<10.5g} |{:6.1f} |"
fprintf(scr,fmt,label,time_min,time,time_max,time_sq,time_cpu,tmp); "{:6.1f} |{:6.2f}\n",
if (log) label,time_min,time,time_max,time_sq,time_cpu,tmp);
fprintf(log,fmt,label,time_min,time,time_max,time_sq,time_cpu,tmp); else
time_loop = 100.0/time_loop; mesg = fmt::format("{:<8s}| {:<10.5g} | {:<10.5g} | {:<10.5g} |{:6.1f} |"
} else { "{:6.2f}\n",label,time_min,time,time_max,time_sq,tmp);
const char fmt[] = "%-8s|%- 12.5g|%- 12.5g|%- 12.5g|%6.1f |%6.2f\n"; if (scr) fputs(mesg.c_str(),scr);
if (scr) if (log) fputs(mesg.c_str(),log);
fprintf(scr,fmt,label,time_min,time,time_max,time_sq,tmp);
if (log)
fprintf(log,fmt,label,time_min,time,time_max,time_sq,tmp);
}
} }
} }
@ -947,7 +702,6 @@ void mpi_timings(const char *label, Timer *t, enum Timer::ttype tt,
void omp_times(FixOMP *fix, const char *label, enum Timer::ttype which, void omp_times(FixOMP *fix, const char *label, enum Timer::ttype which,
const int nthreads,FILE *scr, FILE *log) const int nthreads,FILE *scr, FILE *log)
{ {
const char fmt[] = "%-8s|%- 12.5g|%- 12.5g|%- 12.5g|%6.1f |%6.2f\n";
double time_min, time_max, time_avg, time_total, time_std; double time_min, time_max, time_avg, time_total, time_std;
time_min = 1.0e100; time_min = 1.0e100;
@ -973,10 +727,11 @@ void omp_times(FixOMP *fix, const char *label, enum Timer::ttype which,
else else
time_std = 0.0; time_std = 0.0;
if (scr) fprintf(scr,fmt,label,time_min,time_avg,time_max,time_std, std::string mesg = fmt::format("{:<8s}| {:10.5g} | {:10.5g} | {:10.5g} |"
time_avg/time_total*100.0); "{:6.1f} |{:6.2f}\n",label,time_min,time_avg,
if (log) fprintf(log,fmt,label,time_min,time_avg,time_max,time_std, time_max,time_std,time_avg/time_total*100.0);
time_avg/time_total*100.0); if (scr) fputs(mesg.c_str(),scr);
if (log) fputs(mesg.c_str(),log);
} }
#endif #endif

View File

@ -15,6 +15,7 @@
#include <mpi.h> #include <mpi.h>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <string>
#include "update.h" #include "update.h"
#include "force.h" #include "force.h"
#include "input.h" #include "input.h"
@ -25,6 +26,7 @@
#include "comm.h" #include "comm.h"
#include "timer.h" #include "timer.h"
#include "error.h" #include "error.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
@ -224,15 +226,13 @@ void FixHalt::end_of_step()
// soft/continue halt -> trigger timer to break from run loop // soft/continue halt -> trigger timer to break from run loop
// print message with ID of fix halt in case multiple instances // print message with ID of fix halt in case multiple instances
char str[128]; std::string message = fmt::format("Fix halt condition for fix-id {} met on "
sprintf(str,"Fix halt condition for fix-id %s met on step " "step {} with value {}",
BIGINT_FORMAT " with value %g",
id, update->ntimestep, attvalue); id, update->ntimestep, attvalue);
if (eflag == HARD) { if (eflag == HARD) {
error->all(FLERR,str); error->all(FLERR,message);
} else if (eflag == SOFT || eflag == CONTINUE) { } else if (eflag == SOFT || eflag == CONTINUE) {
if (comm->me == 0 && msgflag == YESMSG) error->message(FLERR,str); if (comm->me == 0 && msgflag == YESMSG) error->message(FLERR,message);
timer->force_timeout(); timer->force_timeout();
} }
} }

View File

@ -1026,7 +1026,7 @@ FILE *Force::open_potential(const char *name, int *auto_convert)
} }
if (auto_convert == nullptr) { if (auto_convert == nullptr) {
if (units != unit_style) { if (!units.empty() && (units != unit_style)) {
error->one(FLERR, fmt::format("Potential file {} requires {} units " error->one(FLERR, fmt::format("Potential file {} requires {} units "
"but {} units are in use", name, units, "but {} units are in use", name, units,
unit_style)); unit_style));

View File

@ -15,6 +15,7 @@
#include <mpi.h> #include <mpi.h>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <string>
#include <utility> #include <utility>
#include "domain.h" #include "domain.h"
#include "atom.h" #include "atom.h"
@ -32,6 +33,7 @@
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "utils.h" #include "utils.h"
#include "fmt/format.h"
#include <map> #include <map>
@ -123,11 +125,9 @@ void Group::assign(int narg, char **arg)
for (i = 0; i < nlocal; i++) mask[i] &= bits; for (i = 0; i < nlocal; i++) mask[i] &= bits;
if (dynamic[igroup]) { if (dynamic[igroup]) {
int n = strlen("GROUP_") + strlen(names[igroup]) + 1; std::string fixID = "GROUP_";
char *fixID = new char[n]; fixID += names[igroup];
sprintf(fixID,"GROUP_%s",names[igroup]); modify->delete_fix(fixID.c_str());
modify->delete_fix(fixID);
delete [] fixID;
} }
delete [] names[igroup]; delete [] names[igroup];
@ -492,27 +492,23 @@ void Group::assign(int narg, char **arg)
// if group is already dynamic, delete existing FixGroup // if group is already dynamic, delete existing FixGroup
if (dynamic[igroup]) { if (dynamic[igroup]) {
int n = strlen("GROUP_") + strlen(names[igroup]) + 1; std::string fixID = "GROUP_";
char *fixID = new char[n]; fixID += names[igroup];
sprintf(fixID,"GROUP_%s",names[igroup]); modify->delete_fix(fixID.c_str());
modify->delete_fix(fixID);
delete [] fixID;
} }
dynamic[igroup] = 1; dynamic[igroup] = 1;
int n = strlen("GROUP_") + strlen(names[igroup]) + 1; std::string fixID = "GROUP_";
char *fixID = new char[n]; fixID += names[igroup];
sprintf(fixID,"GROUP_%s",names[igroup]);
char **newarg = new char*[narg]; char **newarg = new char*[narg];
newarg[0] = fixID; newarg[0] = (char *)fixID.c_str();
newarg[1] = arg[2]; newarg[1] = arg[2];
newarg[2] = (char *) "GROUP"; newarg[2] = (char *) "GROUP";
for (int i = 3; i < narg; i++) newarg[i] = arg[i]; for (int i = 3; i < narg; i++) newarg[i] = arg[i];
modify->add_fix(narg,newarg); modify->add_fix(narg,newarg);
delete [] newarg; delete [] newarg;
delete [] fixID;
// style = static // style = static
// remove dynamic FixGroup if necessary // remove dynamic FixGroup if necessary
@ -522,11 +518,9 @@ void Group::assign(int narg, char **arg)
if (narg != 2) error->all(FLERR,"Illegal group command"); if (narg != 2) error->all(FLERR,"Illegal group command");
if (dynamic[igroup]) { if (dynamic[igroup]) {
int n = strlen("GROUP_") + strlen(names[igroup]) + 1; std::string fixID = "GROUP_";
char *fixID = new char[n]; fixID += names[igroup];
sprintf(fixID,"GROUP_%s",names[igroup]); modify->delete_fix(fixID.c_str());
modify->delete_fix(fixID);
delete [] fixID;
} }
dynamic[igroup] = 0; dynamic[igroup] = 0;
@ -546,15 +540,10 @@ void Group::assign(int narg, char **arg)
MPI_Allreduce(&rlocal,&all,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&rlocal,&all,1,MPI_DOUBLE,MPI_SUM,world);
if (me == 0) { if (me == 0) {
if (dynamic[igroup]) { if (dynamic[igroup])
if (screen) fprintf(screen,"dynamic group %s defined\n",names[igroup]); utils::logmesg(lmp,fmt::format("dynamic group {} defined\n",names[igroup]));
if (logfile) fprintf(logfile,"dynamic group %s defined\n",names[igroup]); else
} else { utils::logmesg(lmp,fmt::format("{:.15g} atoms in group {}\n",all,names[igroup]));
if (screen)
fprintf(screen,"%.15g atoms in group %s\n",all,names[igroup]);
if (logfile)
fprintf(logfile,"%.15g atoms in group %s\n",all,names[igroup]);
}
} }
} }

View File

@ -848,16 +848,12 @@ bool Info::is_active(const char *category, const char *name)
if (!match && lmp->suffix_enable) { if (!match && lmp->suffix_enable) {
if (lmp->suffix) { if (lmp->suffix) {
char *name_w_suffix = new char [len + 2 + strlen(lmp->suffix)]; std::string name_w_suffix = name + std::string("/") + lmp->suffix;
sprintf(name_w_suffix,"%s/%s",name,lmp->suffix); if (name_w_suffix == style) match = 1;
if (strcmp(style,name_w_suffix) == 0) match = 1;
delete[] name_w_suffix;
} }
if (!match && lmp->suffix2) { if (!match && lmp->suffix2) {
char *name_w_suffix = new char [len + 2 + strlen(lmp->suffix2)]; std::string name_w_suffix = name + std::string("/") + lmp->suffix2;
sprintf(name_w_suffix,"%s/%s",name,lmp->suffix2); if (name_w_suffix == style) match = 1;
if (strcmp(style,name_w_suffix) == 0) match = 1;
delete[] name_w_suffix;
} }
} }
return match ? true : false; return match ? true : false;

View File

@ -227,11 +227,8 @@ void Input::file()
// execute the command // execute the command
if (execute_command()) { if (execute_command())
char *str = new char[maxline+32]; error->all(FLERR,fmt::format("Unknown command: {}",line));
sprintf(str,"Unknown command: %s",line);
error->all(FLERR,str);
}
} }
} }
@ -1246,10 +1243,10 @@ void Input::quit()
char *shell_failed_message(const char* cmd, int errnum) char *shell_failed_message(const char* cmd, int errnum)
{ {
const char *errmsg = strerror(errnum); std::string errmsg = fmt::format("Shell command '{}' failed with error '{}'",
int len = strlen(cmd)+strlen(errmsg)+64; cmd, strerror(errnum));
char *msg = new char[len]; char *msg = new char[errmsg.size()+1];
sprintf(msg,"Shell command '%s' failed with error '%s'", cmd, errmsg); strcpy(msg, errmsg.c_str());
return msg; return msg;
} }

View File

@ -16,6 +16,7 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <string>
#include "atom.h" #include "atom.h"
#include "comm.h" #include "comm.h"
#include "force.h" #include "force.h"
@ -25,6 +26,7 @@
#include "error.h" #include "error.h"
#include "suffix.h" #include "suffix.h"
#include "domain.h" #include "domain.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -307,10 +309,10 @@ void KSpace::qsum_qsq(int warning_flag)
// so issue warning or error // so issue warning or error
if (fabs(qsum) > SMALL) { if (fabs(qsum) > SMALL) {
char str[128]; std::string message = fmt::format("System is not charge neutral, net "
sprintf(str,"System is not charge neutral, net charge = %g",qsum); "charge = {}",qsum);
if (!warn_nonneutral) error->all(FLERR,str); if (!warn_nonneutral) error->all(FLERR,message);
if (warn_nonneutral == 1 && comm->me == 0) error->warning(FLERR,str); if (warn_nonneutral == 1 && comm->me == 0) error->warning(FLERR,message);
warn_nonneutral = 2; warn_nonneutral = 2;
} }
} }
@ -324,12 +326,10 @@ double KSpace::estimate_table_accuracy(double q2_over_sqrt, double spr)
double table_accuracy = 0.0; double table_accuracy = 0.0;
int nctb = force->pair->ncoultablebits; int nctb = force->pair->ncoultablebits;
if (comm->me == 0) { if (comm->me == 0) {
char str[128];
if (nctb) if (nctb)
sprintf(str," using %d-bit tables for long-range coulomb",nctb); error->message(FLERR,fmt::format(" using {}-bit tables for long-range coulomb",nctb));
else else
sprintf(str," using polynomial approximation for long-range coulomb"); error->message(FLERR," using polynomial approximation for long-range coulomb");
error->message(FLERR,str);
} }
if (nctb) { if (nctb) {

View File

@ -667,15 +667,12 @@ LAMMPS::~LAMMPS()
double totalclock = MPI_Wtime() - initclock; double totalclock = MPI_Wtime() - initclock;
if ((me == 0) && (screen || logfile)) { if ((me == 0) && (screen || logfile)) {
char outtime[128];
int seconds = fmod(totalclock,60.0); int seconds = fmod(totalclock,60.0);
totalclock = (totalclock - seconds) / 60.0; totalclock = (totalclock - seconds) / 60.0;
int minutes = fmod(totalclock,60.0); int minutes = fmod(totalclock,60.0);
int hours = (totalclock - minutes) / 60.0; int hours = (totalclock - minutes) / 60.0;
sprintf(outtime,"Total wall time: " utils::logmesg(this,fmt::format("Total wall time: {}:{:02d}:{:02d}\n",
"%d:%02d:%02d\n", hours, minutes, seconds); hours, minutes, seconds));
if (screen) fputs(outtime,screen);
if (logfile) fputs(outtime,logfile);
} }
if (universe->nworlds == 1) { if (universe->nworlds == 1) {

View File

@ -21,6 +21,8 @@
#include "force.h" #include "force.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "utils.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -301,14 +303,9 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
// print lattice spacings // print lattice spacings
if (comm->me == 0) { if (comm->me == 0)
if (screen) utils::logmesg(lmp,fmt::format("Lattice spacing in x,y,z = {} {} {}\n",
fprintf(screen,"Lattice spacing in x,y,z = %g %g %g\n", xlattice,ylattice,zlattice));
xlattice,ylattice,zlattice);
if (logfile)
fprintf(logfile,"Lattice spacing in x,y,z = %g %g %g\n",
xlattice,ylattice,zlattice);
}
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

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

View File

@ -13,6 +13,7 @@
#include "modify.h" #include "modify.h"
#include <cstring> #include <cstring>
#include <string>
#include "style_compute.h" #include "style_compute.h"
#include "style_fix.h" #include "style_fix.h"
#include "atom.h" #include "atom.h"
@ -836,18 +837,17 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
int match = 0; int match = 0;
if (strcmp(arg[2],fix[ifix]->style) == 0) match = 1; if (strcmp(arg[2],fix[ifix]->style) == 0) match = 1;
if (!match && trysuffix && lmp->suffix_enable) { if (!match && trysuffix && lmp->suffix_enable) {
char estyle[256];
if (lmp->suffix) { if (lmp->suffix) {
sprintf(estyle,"%s/%s",arg[2],lmp->suffix); std::string estyle = arg[2] + std::string("/") + lmp->suffix;
if (strcmp(estyle,fix[ifix]->style) == 0) match = 1; if (estyle == fix[ifix]->style) match = 1;
} }
if (lmp->suffix2) { if (lmp->suffix2) {
sprintf(estyle,"%s/%s",arg[2],lmp->suffix2); std::string estyle = arg[2] + std::string("/") + lmp->suffix2;
if (strcmp(estyle,fix[ifix]->style) == 0) match = 1; if (estyle == fix[ifix]->style) match = 1;
} }
} }
if (!match) error->all(FLERR, if (!match)
"Replacing a fix, but new style != old style"); error->all(FLERR,"Replacing a fix, but new style != old style");
if (fix[ifix]->igroup != igroup && comm->me == 0) if (fix[ifix]->igroup != igroup && comm->me == 0)
error->warning(FLERR,"Replacing a fix, but new group != old group"); error->warning(FLERR,"Replacing a fix, but new group != old group");
@ -870,26 +870,24 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
if (trysuffix && lmp->suffix_enable) { if (trysuffix && lmp->suffix_enable) {
if (lmp->suffix) { if (lmp->suffix) {
int n = strlen(arg[2])+strlen(lmp->suffix)+2; std::string estyle = arg[2] + std::string("/") + lmp->suffix;
char *estyle = new char[n];
sprintf(estyle,"%s/%s",arg[2],lmp->suffix);
if (fix_map->find(estyle) != fix_map->end()) { if (fix_map->find(estyle) != fix_map->end()) {
FixCreator fix_creator = (*fix_map)[estyle]; FixCreator fix_creator = (*fix_map)[estyle];
fix[ifix] = fix_creator(lmp,narg,arg); fix[ifix] = fix_creator(lmp,narg,arg);
delete[] fix[ifix]->style; delete[] fix[ifix]->style;
fix[ifix]->style = estyle; fix[ifix]->style = new char[estyle.size()+1];
} else delete[] estyle; strcpy(fix[ifix]->style,estyle.c_str());
}
} }
if (fix[ifix] == NULL && lmp->suffix2) { if (fix[ifix] == NULL && lmp->suffix2) {
int n = strlen(arg[2])+strlen(lmp->suffix2)+2; std::string estyle = arg[2] + std::string("/") + lmp->suffix2;
char *estyle = new char[n];
sprintf(estyle,"%s/%s",arg[2],lmp->suffix2);
if (fix_map->find(estyle) != fix_map->end()) { if (fix_map->find(estyle) != fix_map->end()) {
FixCreator fix_creator = (*fix_map)[estyle]; FixCreator fix_creator = (*fix_map)[estyle];
fix[ifix] = fix_creator(lmp,narg,arg); fix[ifix] = fix_creator(lmp,narg,arg);
delete[] fix[ifix]->style; delete[] fix[ifix]->style;
fix[ifix]->style = estyle; fix[ifix]->style = new char[estyle.size()+1];
} else delete[] estyle; strcpy(fix[ifix]->style,estyle.c_str());
}
} }
} }
@ -910,16 +908,10 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
fix[ifix]->restart(state_restart_global[i]); fix[ifix]->restart(state_restart_global[i]);
used_restart_global[i] = 1; used_restart_global[i] = 1;
fix[ifix]->restart_reset = 1; fix[ifix]->restart_reset = 1;
if (comm->me == 0) { if (comm->me == 0)
if (screen) utils::logmesg(lmp,fmt::format("Resetting global fix info from restart file:\n"
fprintf(screen,"Resetting global fix info from restart file:\n"); " fix style: {}, fix ID: {}\n",
if (logfile) fix[ifix]->style,fix[ifix]->id));
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);
}
} }
// check if Fix is in restart_peratom list // check if Fix is in restart_peratom list
@ -932,16 +924,10 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
for (int j = 0; j < atom->nlocal; j++) for (int j = 0; j < atom->nlocal; j++)
fix[ifix]->unpack_restart(j,index_restart_peratom[i]); fix[ifix]->unpack_restart(j,index_restart_peratom[i]);
fix[ifix]->restart_reset = 1; fix[ifix]->restart_reset = 1;
if (comm->me == 0) { if (comm->me == 0)
if (screen) utils::logmesg(lmp,fmt::format("Resetting peratom fix info from restart file:\n"
fprintf(screen,"Resetting peratom fix info from restart file:\n"); " fix style: {}, fix ID: {}\n",
if (logfile) fix[ifix]->style,fix[ifix]->id));
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);
}
} }
// increment nfix (if new) // increment nfix (if new)
@ -1164,7 +1150,7 @@ int Modify::check_rigid_list_overlap(int *select)
int n = 0; int n = 0;
for (int ifix = 0; ifix < nfix; ifix++) { for (int ifix = 0; ifix < nfix; ifix++) {
if (strncmp("rigid",fix[ifix]->style,5) == 0) { if (utils::strmatch(fix[ifix]->style,"^rigid")) {
const int * const body = (const int *)fix[ifix]->extract("body",dim); const int * const body = (const int *)fix[ifix]->extract("body",dim);
if ((body == NULL) || (dim != 1)) break; if ((body == NULL) || (dim != 1)) break;
@ -1209,26 +1195,24 @@ void Modify::add_compute(int narg, char **arg, int trysuffix)
if (trysuffix && lmp->suffix_enable) { if (trysuffix && lmp->suffix_enable) {
if (lmp->suffix) { if (lmp->suffix) {
int n = strlen(arg[2])+strlen(lmp->suffix)+2; std::string estyle = arg[2] + std::string("/") + lmp->suffix;
char *estyle = new char[n];
sprintf(estyle,"%s/%s",arg[2],lmp->suffix);
if (compute_map->find(estyle) != compute_map->end()) { if (compute_map->find(estyle) != compute_map->end()) {
ComputeCreator compute_creator = (*compute_map)[estyle]; ComputeCreator compute_creator = (*compute_map)[estyle];
compute[ncompute] = compute_creator(lmp,narg,arg); compute[ncompute] = compute_creator(lmp,narg,arg);
delete[] compute[ncompute]->style; delete[] compute[ncompute]->style;
compute[ncompute]->style = estyle; compute[ncompute]->style = new char[estyle.size()+1];
} else delete[] estyle; strcpy(compute[ncompute]->style,estyle.c_str());
}
} }
if (compute[ncompute] == NULL && lmp->suffix2) { if (compute[ncompute] == NULL && lmp->suffix2) {
int n = strlen(arg[2])+strlen(lmp->suffix2)+2; std::string estyle = arg[2] + std::string("/") + lmp->suffix2;
char *estyle = new char[n];
sprintf(estyle,"%s/%s",arg[2],lmp->suffix2);
if (compute_map->find(estyle) != compute_map->end()) { if (compute_map->find(estyle) != compute_map->end()) {
ComputeCreator compute_creator = (*compute_map)[estyle]; ComputeCreator compute_creator = (*compute_map)[estyle];
compute[ncompute] = compute_creator(lmp,narg,arg); compute[ncompute] = compute_creator(lmp,narg,arg);
delete[] compute[ncompute]->style; delete[] compute[ncompute]->style;
compute[ncompute]->style = estyle; compute[ncompute]->style = new char[estyle.size()+1];
} else delete[] estyle; strcpy(compute[ncompute]->style,estyle.c_str());
}
} }
} }
@ -1509,21 +1493,13 @@ void Modify::restart_deallocate(int flag)
for (i = 0; i < nfix_restart_global; i++) for (i = 0; i < nfix_restart_global; i++)
if (used_restart_global[i] == 0) break; if (used_restart_global[i] == 0) break;
if (i == nfix_restart_global) { if (i == nfix_restart_global) {
if (screen) utils::logmesg(lmp,"All restart file global fix info was re-assigned\n");
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");
} else { } else {
if (screen) fprintf(screen,"Unused restart file global fix info:\n"); utils::logmesg(lmp,"Unused restart file global fix info:\n");
if (logfile) fprintf(logfile,"Unused restart file global fix info:\n");
for (i = 0; i < nfix_restart_global; i++) { for (i = 0; i < nfix_restart_global; i++) {
if (used_restart_global[i]) continue; if (used_restart_global[i]) continue;
if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", utils::logmesg(lmp,fmt::format(" fix style: {}, fix ID: {}\n",
style_restart_global[i],id_restart_global[i]); 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]);
} }
} }
} }
@ -1545,21 +1521,13 @@ void Modify::restart_deallocate(int flag)
for (i = 0; i < nfix_restart_peratom; i++) for (i = 0; i < nfix_restart_peratom; i++)
if (used_restart_peratom[i] == 0) break; if (used_restart_peratom[i] == 0) break;
if (i == nfix_restart_peratom) { if (i == nfix_restart_peratom) {
if (screen) utils::logmesg(lmp,"All restart file peratom fix info was re-assigned\n");
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");
} else { } else {
if (screen) fprintf(screen,"Unused restart file peratom fix info:\n"); utils::logmesg(lmp,"Unused restart file peratom fix info:\n");
if (logfile) fprintf(logfile,"Unused restart file peratom fix info:\n");
for (i = 0; i < nfix_restart_peratom; i++) { for (i = 0; i < nfix_restart_peratom; i++) {
if (used_restart_peratom[i]) continue; if (used_restart_peratom[i]) continue;
if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", utils::logmesg(lmp,fmt::format(" fix style: {}, fix ID: {}\n",
style_restart_peratom[i],id_restart_peratom[i]); 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]);
} }
} }
} }

View File

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

View File

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

View File

@ -97,10 +97,7 @@ void NTopoImproperPartial::build()
int all; int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world); MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all) { if (all && me == 0)
char str[128]; error->warning(FLERR,fmt::format("Improper atoms missing at step {}",
sprintf(str, update->ntimestep));
"Improper atoms missing at step " BIGINT_FORMAT,update->ntimestep);
if (me == 0) error->warning(FLERR,str);
}
} }

View File

@ -116,37 +116,28 @@ void PairTable::compute(int eflag, int vflag)
if (rsq < cutsq[itype][jtype]) { if (rsq < cutsq[itype][jtype]) {
tb = &tables[tabindex[itype][jtype]]; tb = &tables[tabindex[itype][jtype]];
if (rsq < tb->innersq) { if (rsq < tb->innersq)
sprintf(estr,"Pair distance < table inner cutoff: " error->one(FLERR,fmt::format("Pair distance < table inner cutoff: "
"ijtype %d %d dist %g",itype,jtype,sqrt(rsq)); "ijtype {} {} dist {}",itype,jtype,sqrt(rsq)));
error->one(FLERR,estr);
}
if (tabstyle == LOOKUP) { if (tabstyle == LOOKUP) {
itable = static_cast<int> ((rsq - tb->innersq) * tb->invdelta); itable = static_cast<int> ((rsq - tb->innersq) * tb->invdelta);
if (itable >= tlm1) { if (itable >= tlm1)
sprintf(estr,"Pair distance > table outer cutoff: " error->one(FLERR,fmt::format("Pair distance > table outer cutoff: "
"ijtype %d %d dist %g",itype,jtype,sqrt(rsq)); "ijtype {} {} dist {}",itype,jtype,sqrt(rsq)));
error->one(FLERR,estr);
}
fpair = factor_lj * tb->f[itable]; fpair = factor_lj * tb->f[itable];
} else if (tabstyle == LINEAR) { } else if (tabstyle == LINEAR) {
itable = static_cast<int> ((rsq - tb->innersq) * tb->invdelta); itable = static_cast<int> ((rsq - tb->innersq) * tb->invdelta);
if (itable >= tlm1) { if (itable >= tlm1)
sprintf(estr,"Pair distance > table outer cutoff: " error->one(FLERR,fmt::format("Pair distance > table outer cutoff: "
"ijtype %d %d dist %g",itype,jtype,sqrt(rsq)); "ijtype {} {} dist {}",itype,jtype,sqrt(rsq)));
error->one(FLERR,estr);
}
fraction = (rsq - tb->rsq[itable]) * tb->invdelta; fraction = (rsq - tb->rsq[itable]) * tb->invdelta;
value = tb->f[itable] + fraction*tb->df[itable]; value = tb->f[itable] + fraction*tb->df[itable];
fpair = factor_lj * value; fpair = factor_lj * value;
} else if (tabstyle == SPLINE) { } else if (tabstyle == SPLINE) {
itable = static_cast<int> ((rsq - tb->innersq) * tb->invdelta); itable = static_cast<int> ((rsq - tb->innersq) * tb->invdelta);
if (itable >= tlm1) { if (itable >= tlm1)
sprintf(estr,"Pair distance > table outer cutoff: " error->one(FLERR,fmt::format("Pair distance > table outer cutoff: "
"ijtype %d %d dist %g",itype,jtype,sqrt(rsq)); "ijtype {} {} dist {}",itype,jtype,sqrt(rsq)));
error->one(FLERR,estr);
}
b = (rsq - tb->rsq[itable]) * tb->invdelta; b = (rsq - tb->rsq[itable]) * tb->invdelta;
a = 1.0 - b; a = 1.0 - b;
value = a * tb->f[itable] + b * tb->f[itable+1] + value = a * tb->f[itable] + b * tb->f[itable+1] +

View File

@ -1157,11 +1157,8 @@ void ReadData::header(int firstpass)
parse_keyword(1); parse_keyword(1);
for (n = 0; n < NSECTIONS; n++) for (n = 0; n < NSECTIONS; n++)
if (strcmp(keyword,section_keywords[n]) == 0) break; if (strcmp(keyword,section_keywords[n]) == 0) break;
if (n == NSECTIONS) { if (n == NSECTIONS)
char str[128]; error->all(FLERR,fmt::format("Unknown identifier in data file: {}",keyword));
sprintf(str,"Unknown identifier in data file: %s",keyword);
error->all(FLERR,str);
}
// error checks on header values // error checks on header values
// must be consistent with atom style and other header values // must be consistent with atom style and other header values

View File

@ -289,13 +289,9 @@ bigint ReadDump::seek(bigint nrequest, int exact)
for (ifile = 0; ifile < nfile; ifile++) { for (ifile = 0; ifile < nfile; ifile++) {
ntimestep = -1; ntimestep = -1;
if (multiproc) { if (multiproc) {
char *ptr = strchr(files[ifile],'%'); std::string multiname = files[ifile];
char *multiname = new char[strlen(files[ifile]) + 16]; multiname.replace(multiname.find("%"),1,"0");
*ptr = '\0'; readers[0]->open_file(multiname.c_str());
sprintf(multiname,"%s%d%s",files[ifile],0,ptr+1);
*ptr = '%';
readers[0]->open_file(multiname);
delete [] multiname;
} else readers[0]->open_file(files[ifile]); } else readers[0]->open_file(files[ifile]);
while (1) { while (1) {
@ -337,13 +333,9 @@ bigint ReadDump::seek(bigint nrequest, int exact)
if (multiproc && filereader) { if (multiproc && filereader) {
for (int i = 0; i < nreader; i++) { for (int i = 0; i < nreader; i++) {
if (me == 0 && i == 0) continue; // proc 0, reader 0 already found it if (me == 0 && i == 0) continue; // proc 0, reader 0 already found it
char *ptr = strchr(files[currentfile],'%'); std::string multiname = files[currentfile];
char *multiname = new char[strlen(files[currentfile]) + 16]; multiname.replace(multiname.find("%"),1,fmt::format("{}",firstfile+i));
*ptr = '\0'; readers[i]->open_file(multiname.c_str());
sprintf(multiname,"%s%d%s",files[currentfile],firstfile+i,ptr+1);
*ptr = '%';
readers[i]->open_file(multiname);
delete [] multiname;
bigint step; bigint step;
while (1) { while (1) {
@ -389,13 +381,9 @@ bigint ReadDump::next(bigint ncurrent, bigint nlast, int nevery, int nskip)
ntimestep = -1; ntimestep = -1;
if (ifile != currentfile) { if (ifile != currentfile) {
if (multiproc) { if (multiproc) {
char *ptr = strchr(files[ifile],'%'); std::string multiname = files[ifile];
char *multiname = new char[strlen(files[ifile]) + 16]; multiname.replace(multiname.find("%"),1,"0");
*ptr = '\0'; readers[0]->open_file(multiname.c_str());
sprintf(multiname,"%s%d%s",files[ifile],0,ptr+1);
*ptr = '%';
readers[0]->open_file(multiname);
delete [] multiname;
} else readers[0]->open_file(files[ifile]); } else readers[0]->open_file(files[ifile]);
} }
@ -447,13 +435,9 @@ bigint ReadDump::next(bigint ncurrent, bigint nlast, int nevery, int nskip)
if (multiproc && filereader) { if (multiproc && filereader) {
for (int i = 0; i < nreader; i++) { for (int i = 0; i < nreader; i++) {
if (me == 0 && i == 0) continue; if (me == 0 && i == 0) continue;
char *ptr = strchr(files[currentfile],'%'); std::string multiname = files[currentfile];
char *multiname = new char[strlen(files[currentfile]) + 16]; multiname.replace(multiname.find("%"),1,fmt::format("{}",firstfile+i));
*ptr = '\0'; readers[i]->open_file(multiname.c_str());
sprintf(multiname,"%s%d%s",files[currentfile],firstfile+i,ptr+1);
*ptr = '%';
readers[i]->open_file(multiname);
delete [] multiname;
bigint step; bigint step;
while (1) { while (1) {

View File

@ -104,19 +104,14 @@ void ReadRestart::command(int narg, char **arg)
if (me == 0) { if (me == 0) {
if (screen) fprintf(screen,"Reading restart file ...\n"); if (screen) fprintf(screen,"Reading restart file ...\n");
char *hfile; std::string hfile = file;
if (multiproc) { if (multiproc) {
hfile = new char[strlen(file) + 16]; hfile.replace(hfile.find("%"),1,"base");
char *ptr = strchr(file,'%'); }
*ptr = '\0'; fp = fopen(hfile.c_str(),"rb");
sprintf(hfile,"%s%s%s",file,"base",ptr+1);
*ptr = '%';
} else hfile = file;
fp = fopen(hfile,"rb");
if (fp == NULL) if (fp == NULL)
error->one(FLERR,fmt::format("Cannot open restart file {}: {}", error->one(FLERR,fmt::format("Cannot open restart file {}: {}",
hfile, utils::getsyserror())); hfile, utils::getsyserror()));
if (multiproc) delete [] hfile;
} }
// read magic string, endian flag, format revision // read magic string, endian flag, format revision
@ -272,14 +267,10 @@ void ReadRestart::command(int narg, char **arg)
else if (nprocs <= multiproc_file) { else if (nprocs <= multiproc_file) {
char *procfile = new char[strlen(file) + 16];
char *ptr = strchr(file,'%');
for (int iproc = me; iproc < multiproc_file; iproc += nprocs) { for (int iproc = me; iproc < multiproc_file; iproc += nprocs) {
*ptr = '\0'; std::string procfile = file;
sprintf(procfile,"%s%d%s",file,iproc,ptr+1); procfile.replace(procfile.find("%"),1,fmt::format("{}",iproc));
*ptr = '%'; fp = fopen(procfile.c_str(),"rb");
fp = fopen(procfile,"rb");
if (fp == NULL) if (fp == NULL)
error->one(FLERR,fmt::format("Cannot open restart file {}: {}", error->one(FLERR,fmt::format("Cannot open restart file {}: {}",
procfile, utils::getsyserror())); procfile, utils::getsyserror()));
@ -309,8 +300,6 @@ void ReadRestart::command(int narg, char **arg)
fclose(fp); fclose(fp);
fp = NULL; fp = NULL;
} }
delete [] procfile;
} }
// input of multiple native files with procs > files // input of multiple native files with procs > files
@ -343,16 +332,12 @@ void ReadRestart::command(int narg, char **arg)
MPI_Comm_split(world,icluster,0,&clustercomm); MPI_Comm_split(world,icluster,0,&clustercomm);
if (filereader) { if (filereader) {
char *procfile = new char[strlen(file) + 16]; std::string procfile = file;
char *ptr = strchr(file,'%'); procfile.replace(procfile.find("%"),1,fmt::format("{}",icluster));
*ptr = '\0'; fp = fopen(procfile.c_str(),"rb");
sprintf(procfile,"%s%d%s",file,icluster,ptr+1);
*ptr = '%';
fp = fopen(procfile,"rb");
if (fp == NULL) if (fp == NULL)
error->one(FLERR,fmt::format("Cannot open restart file {}: {}", error->one(FLERR,fmt::format("Cannot open restart file {}: {}",
procfile, utils::getsyserror())); procfile, utils::getsyserror()));
delete [] procfile;
} }
int flag,procsperfile; int flag,procsperfile;
@ -534,14 +519,10 @@ void ReadRestart::command(int narg, char **arg)
// total time // total time
MPI_Barrier(world); MPI_Barrier(world);
double time2 = MPI_Wtime();
if (comm->me == 0) { if (comm->me == 0)
if (screen) utils::logmesg(lmp,fmt::format(" read_restart CPU = {:.3f} secs\n",
fprintf(screen," read_restart CPU = %g secs\n",time2-time1); MPI_Wtime()-time1));
if (logfile)
fprintf(logfile," read_restart CPU = %g secs\n",time2-time1);
}
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -618,10 +599,9 @@ void ReadRestart::file_search(char *inpfile, char *outfile)
// create outfile with maxint substituted for "*" // create outfile with maxint substituted for "*"
// use original inpfile, not pattern, since need to retain "%" in filename // use original inpfile, not pattern, since need to retain "%" in filename
ptr = strchr(inpfile,'*'); std::string newoutfile = inpfile;
*ptr = '\0'; newoutfile.replace(newoutfile.find("*"),1,fmt::format("{}",maxnum));
sprintf(outfile,"%s" BIGINT_FORMAT "%s",inpfile,maxnum,ptr+1); strcpy(outfile,newoutfile.c_str());
*ptr = '*';
// clean up // clean up
@ -826,12 +806,8 @@ void ReadRestart::header()
for (int i = 0; i < nargcopy; i++) for (int i = 0; i < nargcopy; i++)
argcopy[i] = read_string(); argcopy[i] = read_string();
atom->create_avec(style,nargcopy,argcopy,1); atom->create_avec(style,nargcopy,argcopy,1);
if (comm->me ==0) { if (comm->me ==0)
if (screen) fprintf(screen," restoring atom style %s from " utils::logmesg(lmp,fmt::format(" restoring atom style {} from restart\n",style));
"restart\n", style);
if (logfile) fprintf(logfile," restoring atom style %s from "
"restart\n", style);
}
for (int i = 0; i < nargcopy; i++) delete [] argcopy[i]; for (int i = 0; i < nargcopy; i++) delete [] argcopy[i];
delete [] argcopy; delete [] argcopy;
delete [] style; delete [] style;
@ -963,22 +939,16 @@ void ReadRestart::force_fields()
style = read_string(); style = read_string();
force->create_pair(style,1); force->create_pair(style,1);
delete [] style; delete [] style;
if (comm->me ==0) { if (comm->me ==0)
if (screen) fprintf(screen," restoring pair style %s from " utils::logmesg(lmp,fmt::format(" restoring pair style {} from "
"restart\n", force->pair_style); "restart\n", force->pair_style));
if (logfile) fprintf(logfile," restoring pair style %s from "
"restart\n", force->pair_style);
}
force->pair->read_restart(fp); force->pair->read_restart(fp);
} else if (flag == NO_PAIR) { } else if (flag == NO_PAIR) {
style = read_string(); style = read_string();
if (comm->me ==0) { if (comm->me ==0)
if (screen) fprintf(screen," pair style %s stores no " utils::logmesg(lmp,fmt::format(" pair style {} stores no "
"restart info\n", style); "restart info\n", style));
if (logfile) fprintf(logfile," pair style %s stores no "
"restart info\n", style);
}
force->create_pair("none",0); force->create_pair("none",0);
force->pair_restart = style; force->pair_restart = style;
@ -986,48 +956,36 @@ void ReadRestart::force_fields()
style = read_string(); style = read_string();
force->create_bond(style,1); force->create_bond(style,1);
delete [] style; delete [] style;
if (comm->me ==0) { if (comm->me ==0)
if (screen) fprintf(screen," restoring bond style %s from " utils::logmesg(lmp,fmt::format(" restoring bond style {} from "
"restart\n", force->bond_style); "restart\n", force->bond_style));
if (logfile) fprintf(logfile," restoring bond style %s from "
"restart\n", force->bond_style);
}
force->bond->read_restart(fp); force->bond->read_restart(fp);
} else if (flag == ANGLE) { } else if (flag == ANGLE) {
style = read_string(); style = read_string();
force->create_angle(style,1); force->create_angle(style,1);
delete [] style; delete [] style;
if (comm->me ==0) { if (comm->me ==0)
if (screen) fprintf(screen," restoring angle style %s from " utils::logmesg(lmp,fmt::format(" restoring angle style {} from "
"restart\n", force->angle_style); "restart\n", force->angle_style));
if (logfile) fprintf(logfile," restoring angle style %s from "
"restart\n", force->angle_style);
}
force->angle->read_restart(fp); force->angle->read_restart(fp);
} else if (flag == DIHEDRAL) { } else if (flag == DIHEDRAL) {
style = read_string(); style = read_string();
force->create_dihedral(style,1); force->create_dihedral(style,1);
delete [] style; delete [] style;
if (comm->me ==0) { if (comm->me ==0)
if (screen) fprintf(screen," restoring dihedral style %s from " utils::logmesg(lmp,fmt::format(" restoring dihedral style {} from "
"restart\n", force->dihedral_style); "restart\n", force->dihedral_style));
if (logfile) fprintf(logfile," restoring dihedral style %s from "
"restart\n", force->dihedral_style);
}
force->dihedral->read_restart(fp); force->dihedral->read_restart(fp);
} else if (flag == IMPROPER) { } else if (flag == IMPROPER) {
style = read_string(); style = read_string();
force->create_improper(style,1); force->create_improper(style,1);
delete [] style; delete [] style;
if (comm->me ==0) { if (comm->me ==0)
if (screen) fprintf(screen," restoring improper style %s from " utils::logmesg(lmp,fmt::format(" restoring improper style {} from "
"restart\n", force->improper_style); "restart\n", force->improper_style));
if (logfile) fprintf(logfile," restoring improper style %s from "
"restart\n", force->improper_style);
}
force->improper->read_restart(fp); force->improper->read_restart(fp);
} else error->all(FLERR, } else error->all(FLERR,

View File

@ -777,12 +777,8 @@ void Replicate::command(int narg, char **arg)
// total time // total time
MPI_Barrier(world); MPI_Barrier(world);
double time2 = MPI_Wtime();
if (me == 0) { if (me == 0)
if (screen) utils::logmesg(lmp,fmt::format(" replicate CPU = {:.3f} secs\n",
fprintf(screen," replicate CPU = %g secs\n",time2-time1); MPI_Wtime()-time1));
if (logfile)
fprintf(logfile," replicate CPU = %g secs\n",time2-time1);
}
} }

View File

@ -24,6 +24,7 @@
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "utils.h" #include "utils.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -252,12 +253,9 @@ void ResetIDs::command(int narg, char **arg)
int all; int all;
MPI_Allreduce(&badcount,&all,1,MPI_INT,MPI_SUM,world); MPI_Allreduce(&badcount,&all,1,MPI_INT,MPI_SUM,world);
if (all) { if (all)
char str[128]; error->all(FLERR,fmt::format("Reset_ids missing {} bond topology atom IDs - "
sprintf(str,"Reset_ids missing %d bond topology atom IDs - " "use comm_modify cutoff",all));
"use comm_modify cutoff",all);
error->all(FLERR,str);
}
// reset IDs and atom map for owned atoms // reset IDs and atom map for owned atoms

View File

@ -1314,6 +1314,6 @@ void Special::fix_alteration()
void Special::timer_output(double time1) void Special::timer_output(double time1)
{ {
if (comm->me == 0) if (comm->me == 0)
utils::logmesg(lmp,fmt::format(" special bonds CPU = {:<.3g} secs\n", utils::logmesg(lmp,fmt::format(" special bonds CPU = {:.3f} secs\n",
MPI_Wtime()-time1)); MPI_Wtime()-time1));
} }

View File

@ -45,6 +45,7 @@
#include "error.h" #include "error.h"
#include "math_const.h" #include "math_const.h"
#include "utils.h" #include "utils.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using namespace MathConst;
@ -423,21 +424,15 @@ bigint Thermo::lost_check()
// error message // error message
if (lostflag == Thermo::ERROR) { if (lostflag == Thermo::ERROR)
char str[64]; error->all(FLERR,fmt::format("Lost atoms: original {} current {}",
sprintf(str, atom->natoms,ntotal));
"Lost atoms: original " BIGINT_FORMAT " current " BIGINT_FORMAT,
atom->natoms,ntotal);
error->all(FLERR,str);
}
// warning message // warning message
char str[64]; if (me == 0)
sprintf(str, error->warning(FLERR,fmt::format("Lost atoms: original {} current {}",
"Lost atoms: original " BIGINT_FORMAT " current " BIGINT_FORMAT, atom->natoms,ntotal),0);
atom->natoms,ntotal);
if (me == 0) error->warning(FLERR,str,0);
// reset total atom count // reset total atom count

View File

@ -309,18 +309,14 @@ void Update::create_integrate(int narg, char **arg, int trysuffix)
int sflag; int sflag;
new_integrate(arg[0],narg-1,&arg[1],trysuffix,sflag); new_integrate(arg[0],narg-1,&arg[1],trysuffix,sflag);
std::string estyle = arg[0];
if (sflag) { if (sflag) {
char estyle[256]; estyle += "/";
if (sflag == 1) snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix); if (sflag == 1) estyle += lmp->suffix;
else snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix2); else estyle += lmp->suffix2;
int n = strlen(estyle) + 1;
integrate_style = new char[n];
strcpy(integrate_style,estyle);
} else {
int n = strlen(arg[0]) + 1;
integrate_style = new char[n];
strcpy(integrate_style,arg[0]);
} }
integrate_style = new char[estyle.size()+1];
strcpy(integrate_style,estyle.c_str());
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -333,8 +329,7 @@ void Update::new_integrate(char *style, int narg, char **arg,
if (trysuffix && lmp->suffix_enable) { if (trysuffix && lmp->suffix_enable) {
if (lmp->suffix) { if (lmp->suffix) {
sflag = 1; sflag = 1;
char estyle[256]; std::string estyle = style + std::string("/") + lmp->suffix;
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
if (integrate_map->find(estyle) != integrate_map->end()) { if (integrate_map->find(estyle) != integrate_map->end()) {
IntegrateCreator integrate_creator = (*integrate_map)[estyle]; IntegrateCreator integrate_creator = (*integrate_map)[estyle];
integrate = integrate_creator(lmp, narg, arg); integrate = integrate_creator(lmp, narg, arg);
@ -344,8 +339,7 @@ void Update::new_integrate(char *style, int narg, char **arg,
if (lmp->suffix2) { if (lmp->suffix2) {
sflag = 2; sflag = 2;
char estyle[256]; std::string estyle = style + std::string("/") + lmp->suffix2;
snprintf(estyle,256,"%s/%s",style,lmp->suffix2);
if (integrate_map->find(estyle) != integrate_map->end()) { if (integrate_map->find(estyle) != integrate_map->end()) {
IntegrateCreator integrate_creator = (*integrate_map)[estyle]; IntegrateCreator integrate_creator = (*integrate_map)[estyle];
integrate = integrate_creator(lmp, narg, arg); integrate = integrate_creator(lmp, narg, arg);
@ -386,18 +380,14 @@ void Update::create_minimize(int narg, char **arg, int trysuffix)
int sflag; int sflag;
new_minimize(arg[0],narg-1,&arg[1],trysuffix,sflag); new_minimize(arg[0],narg-1,&arg[1],trysuffix,sflag);
std::string estyle = arg[0];
if (sflag) { if (sflag) {
char estyle[256]; estyle += "/";
if (sflag == 1) snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix); if (sflag == 1) estyle += lmp->suffix;
else snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix2); else estyle += lmp->suffix2;
int n = strlen(estyle) + 1;
minimize_style = new char[n];
strcpy(minimize_style,estyle);
} else {
int n = strlen(arg[0]) + 1;
minimize_style = new char[n];
strcpy(minimize_style,arg[0]);
} }
minimize_style = new char[estyle.size()+1];
strcpy(minimize_style,estyle.c_str());
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -410,8 +400,7 @@ void Update::new_minimize(char *style, int /* narg */, char ** /* arg */,
if (trysuffix && lmp->suffix_enable) { if (trysuffix && lmp->suffix_enable) {
if (lmp->suffix) { if (lmp->suffix) {
sflag = 1; sflag = 1;
char estyle[256]; std::string estyle = style + std::string("/") + lmp->suffix;
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
if (minimize_map->find(estyle) != minimize_map->end()) { if (minimize_map->find(estyle) != minimize_map->end()) {
MinimizeCreator minimize_creator = (*minimize_map)[estyle]; MinimizeCreator minimize_creator = (*minimize_map)[estyle];
minimize = minimize_creator(lmp); minimize = minimize_creator(lmp);
@ -421,8 +410,7 @@ void Update::new_minimize(char *style, int /* narg */, char ** /* arg */,
if (lmp->suffix2) { if (lmp->suffix2) {
sflag = 2; sflag = 2;
char estyle[256]; std::string estyle = style + std::string("/") + lmp->suffix2;
snprintf(estyle,256,"%s/%s",style,lmp->suffix2);
if (minimize_map->find(estyle) != minimize_map->end()) { if (minimize_map->find(estyle) != minimize_map->end()) {
MinimizeCreator minimize_creator = (*minimize_map)[estyle]; MinimizeCreator minimize_creator = (*minimize_map)[estyle];
minimize = minimize_creator(lmp); minimize = minimize_creator(lmp);

View File

@ -121,11 +121,10 @@ static const char *guesspath(char *buf, int len, FILE *fp)
memset(buf,0,len); memset(buf,0,len);
#if defined(__linux__) #if defined(__linux__)
char procpath[32];
int fd = fileno(fp); int fd = fileno(fp);
snprintf(procpath,32,"/proc/self/fd/%d",fd);
// get pathname from /proc or copy (unknown) // get pathname from /proc or copy (unknown)
if (readlink(procpath,buf,len-1) <= 0) strcpy(buf,"(unknown)"); if (readlink(fmt::format("/proc/self/fd/{}",fd).c_str(),buf,len-1) <= 0)
strcpy(buf,"(unknown)");
#else #else
strcpy(buf,"(unknown)"); strcpy(buf,"(unknown)");
#endif #endif

View File

@ -17,6 +17,7 @@ binary2txt convert a LAMMPS dump file from binary to ASCII text
ch2lmp convert CHARMM files to LAMMPS input ch2lmp convert CHARMM files to LAMMPS input
chain create a data file of bead-spring chains chain create a data file of bead-spring chains
cmake tools and scripts for use with CMake cmake tools and scripts for use with CMake
coding_standard python scripts to detect and fix some LAMMPS conventions
colvars post-process output of the fix colvars command colvars post-process output of the fix colvars command
createatoms generate lattices of atoms within a geometry createatoms generate lattices of atoms within a geometry
drude create Drude core/electron atom pairs in a data file drude create Drude core/electron atom pairs in a data file
@ -31,6 +32,7 @@ kate add-ons to Kate editor for editing LAMMPS input scripts
lmp2arc convert LAMMPS output to Accelrys Insight format lmp2arc convert LAMMPS output to Accelrys Insight format
lmp2cfg convert LAMMPS output to CFG files for AtomEye viz lmp2cfg convert LAMMPS output to CFG files for AtomEye viz
matlab MatLab scripts for post-processing LAMMPS output matlab MatLab scripts for post-processing LAMMPS output
mesont Tools for use with the USER-MESONT package
micelle2d create a data file of small lipid chains in solvent micelle2d create a data file of small lipid chains in solvent
moltemplate Instructions for installing the Moltemplate builder program moltemplate Instructions for installing the Moltemplate builder program
msi2lmp use Accelrys Insight code to setup LAMMPS input msi2lmp use Accelrys Insight code to setup LAMMPS input
@ -40,8 +42,10 @@ pymol_asphere convert LAMMPS output of ellipsoids to PyMol format
python Python scripts for post-processing LAMMPS output python Python scripts for post-processing LAMMPS output
reax Tools for analyzing output of ReaxFF simulations reax Tools for analyzing output of ReaxFF simulations
replica tool to reorder LAMMPS replica trajectories according to temperature replica tool to reorder LAMMPS replica trajectories according to temperature
singularity Singularity container descriptions suitable for LAMMPS development
smd convert Smooth Mach Dynamics triangles to VTK smd convert Smooth Mach Dynamics triangles to VTK
spin perform a cubic polynomial interpolation of a GNEB MEP spin perform a cubic polynomial interpolation of a GNEB MEP
valgrind suppression files for use with valgrind's memcheck tool
vim add-ons to VIM editor for editing LAMMPS input scripts vim add-ons to VIM editor for editing LAMMPS input scripts
xmgrace a collection of scripts to generate xmgrace plots xmgrace a collection of scripts to generate xmgrace plots

View File

@ -0,0 +1,5 @@
These Python scripts help to detect whether files in the repository
conform to LAMMPS coding conventions or not, and can fix those issues, too.
permissions.py detects if sources have executable permissions and scripts have not
whitespace.py (currently) detects trailing whitespace

15
tools/valgrind/README Normal file
View File

@ -0,0 +1,15 @@
These files contain additional suppressions for LAMMPS when using valgrind's
memcheck tool to search for memory access violations and memory leaks.
These will suppress known false positives and thus help to focus finding
and fixing real issues. When using CMake, these are automatically included
when running "ctest -T memcheck". To manually add them to do a memory check
on running LAMMPS, use a command line like following:
valgrind --show-leak-kinds=all --track-origins=yes \
--suppressions=/path/to/lammps/tools/valgrind/OpenMP.supp \
--suppressions=/path/to/lammps/tools/valgrind/OpenMPI.supp \
--suppressions=/path/to/lammps/tools/valgrind/Python3.supp \
lmp -in in.melt
Last update: 2020-06-24