From 5a455c5e3a48e4a9fc97ab2da5bbd803d2400ef5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Sep 2023 23:56:51 -0400 Subject: [PATCH] remove redundant calls to fmt::format() from calls to error->one/all() and utils::logmesg() --- src/ELECTRODE/electrode_matrix.cpp | 2 +- src/ELECTRODE/electrode_vector.cpp | 8 ++++---- src/ELECTRODE/pppm_electrode.cpp | 8 ++++---- src/INTEL/pppm_electrode_intel.cpp | 6 +++--- src/KOKKOS/pair_reaxff_kokkos.cpp | 3 +-- src/MANYBODY/pair_bop.cpp | 11 ++++------- src/MDI/mdi_engine.cpp | 2 +- src/OPENMP/fix_qeq_reaxff_omp.cpp | 14 ++++++-------- src/OPENMP/msm_cg_omp.cpp | 9 ++++----- src/QEQ/fix_qeq.cpp | 3 +-- src/REAXFF/fix_qeq_reaxff.cpp | 9 ++++----- src/REAXFF/fix_reaxff_bonds.cpp | 4 ++-- src/REAXFF/reaxff_allocate.cpp | 4 ++-- src/REPLICA/neb.cpp | 6 ++++-- src/REPLICA/temper_grem.cpp | 2 +- src/lammps.cpp | 8 +++----- src/read_data.cpp | 2 +- src/special.cpp | 13 ++++++------- src/utils.cpp | 13 +++++-------- 19 files changed, 57 insertions(+), 70 deletions(-) diff --git a/src/ELECTRODE/electrode_matrix.cpp b/src/ELECTRODE/electrode_matrix.cpp index 7be9119c62..86761742d4 100644 --- a/src/ELECTRODE/electrode_matrix.cpp +++ b/src/ELECTRODE/electrode_matrix.cpp @@ -84,7 +84,7 @@ void ElectrodeMatrix::compute_array(double **array, bool timer_flag) electrode_kspace->compute_matrix(&mpos[0], array, timer_flag); MPI_Barrier(world); if (timer_flag && (comm->me == 0)) - utils::logmesg(lmp, fmt::format("KSpace time: {:.4g} s\n", MPI_Wtime() - kspace_time)); + utils::logmesg(lmp, "KSpace time: {:.4g} s\n", MPI_Wtime() - kspace_time); //cout << array[0][0] << ", " << array[0][1] << endl; pair_contribution(array); //cout << array[0][0] << ", " << array[0][1] << endl; diff --git a/src/ELECTRODE/electrode_vector.cpp b/src/ELECTRODE/electrode_vector.cpp index 245ba57727..8511ddc17c 100644 --- a/src/ELECTRODE/electrode_vector.cpp +++ b/src/ELECTRODE/electrode_vector.cpp @@ -60,10 +60,10 @@ ElectrodeVector::~ElectrodeVector() { if (timer_flag && (comm->me == 0)) { try { - utils::logmesg(lmp, fmt::format("B time: {:.4g} s\n", b_time_total)); - utils::logmesg(lmp, fmt::format("B kspace time: {:.4g} s\n", kspace_time_total)); - utils::logmesg(lmp, fmt::format("B pair time: {:.4g} s\n", pair_time_total)); - utils::logmesg(lmp, fmt::format("B boundary time: {:.4g} s\n", boundary_time_total)); + utils::logmesg(lmp, "B time: {:.4g} s\n", b_time_total); + utils::logmesg(lmp, "B kspace time: {:.4g} s\n", kspace_time_total); + utils::logmesg(lmp, "B pair time: {:.4g} s\n", pair_time_total); + utils::logmesg(lmp, "B boundary time: {:.4g} s\n", boundary_time_total); } catch (std::exception &) { } } diff --git a/src/ELECTRODE/pppm_electrode.cpp b/src/ELECTRODE/pppm_electrode.cpp index a2161f18e7..6ede0f1f4d 100644 --- a/src/ELECTRODE/pppm_electrode.cpp +++ b/src/ELECTRODE/pppm_electrode.cpp @@ -136,7 +136,7 @@ void PPPMElectrode::init() } if (order < 2 || order > MAXORDER) - error->all(FLERR, fmt::format("PPPM/electrode order cannot be < 2 or > {}", MAXORDER)); + error->all(FLERR, "PPPM/electrode order cannot be < 2 or > {}", MAXORDER); // compute two charge force @@ -816,7 +816,7 @@ void PPPMElectrode::one_step_multiplication(bigint *imat, double *greens_real, d memory->destroy(rho1d_j); MPI_Barrier(world); if (timer_flag && (comm->me == 0)) - utils::logmesg(lmp, fmt::format("Single step time: {:.4g} s\n", MPI_Wtime() - step1_time)); + utils::logmesg(lmp, "Single step time: {:.4g} s\n", MPI_Wtime() - step1_time); } /* ----------------------------------------------------------------------*/ @@ -917,7 +917,7 @@ void PPPMElectrode::two_step_multiplication(bigint *imat, double *greens_real, d } MPI_Barrier(world); if (timer_flag && (comm->me == 0)) - utils::logmesg(lmp, fmt::format("step 1 time: {:.4g} s\n", MPI_Wtime() - step1_time)); + utils::logmesg(lmp, "step 1 time: {:.4g} s\n", MPI_Wtime() - step1_time); // nested loop over electrode atoms i and j and stencil of i // in theory could reuse make_rho1d_j here -- but this step is already @@ -958,7 +958,7 @@ void PPPMElectrode::two_step_multiplication(bigint *imat, double *greens_real, d MPI_Barrier(world); memory->destroy(gw); if (timer_flag && (comm->me == 0)) - utils::logmesg(lmp, fmt::format("step 2 time: {:.4g} s\n", MPI_Wtime() - step2_time)); + utils::logmesg(lmp, "step 2 time: {:.4g} s\n", MPI_Wtime() - step2_time); } /* ---------------------------------------------------------------------- diff --git a/src/INTEL/pppm_electrode_intel.cpp b/src/INTEL/pppm_electrode_intel.cpp index fcb0c0733a..5cb62dc5d2 100644 --- a/src/INTEL/pppm_electrode_intel.cpp +++ b/src/INTEL/pppm_electrode_intel.cpp @@ -719,7 +719,7 @@ void PPPMElectrodeIntel::one_step_multiplication(bigint *imat, double *greens_re MPI_Barrier(world); memory->destroy(rho1d_j); if (timer_flag && (comm->me == 0)) - utils::logmesg(lmp, fmt::format("Single step time: {:.4g} s\n", MPI_Wtime() - step1_time)); + utils::logmesg(lmp, "Single step time: {:.4g} s\n", MPI_Wtime() - step1_time); } /* ----------------------------------------------------------------------*/ @@ -844,7 +844,7 @@ void PPPMElectrodeIntel::two_step_multiplication(bigint *imat, double *greens_re } MPI_Barrier(world); if (timer_flag && (comm->me == 0)) - utils::logmesg(lmp, fmt::format("step 1 time: {:.4g} s\n", MPI_Wtime() - step1_time)); + utils::logmesg(lmp, "step 1 time: {:.4g} s\n", MPI_Wtime() - step1_time); // nested loop over electrode atoms i and j and stencil of i double step2_time = MPI_Wtime(); @@ -914,7 +914,7 @@ void PPPMElectrodeIntel::two_step_multiplication(bigint *imat, double *greens_re } MPI_Barrier(world); if (timer_flag && (comm->me == 0)) - utils::logmesg(lmp, fmt::format("step 2 time: {:.4g} s\n", MPI_Wtime() - step2_time)); + utils::logmesg(lmp, "step 2 time: {:.4g} s\n", MPI_Wtime() - step2_time); } template diff --git a/src/KOKKOS/pair_reaxff_kokkos.cpp b/src/KOKKOS/pair_reaxff_kokkos.cpp index 8d9e1454ae..c7d54b80cd 100644 --- a/src/KOKKOS/pair_reaxff_kokkos.cpp +++ b/src/KOKKOS/pair_reaxff_kokkos.cpp @@ -382,8 +382,7 @@ void PairReaxFFKokkos::init_md() if (swb < 0) error->one(FLERR,"Negative upper Taper-radius cutoff"); else if (swb < 5) - error->one(FLERR,fmt::format("Warning: very low Taper-radius cutoff: " - "{}\n", swb)); + error->one(FLERR,"Warning: very low Taper-radius cutoff: {}\n", swb); d1 = swb - swa; d7 = powint(d1,7); diff --git a/src/MANYBODY/pair_bop.cpp b/src/MANYBODY/pair_bop.cpp index 518a6dad79..ae50736455 100644 --- a/src/MANYBODY/pair_bop.cpp +++ b/src/MANYBODY/pair_bop.cpp @@ -1873,7 +1873,7 @@ void PairBOP::read_table(char *filename) reader = new PotentialFileReader(lmp, filename, "BOP"); bop_types = reader->next_int(); if (bop_types <= 0) - error->one(FLERR,fmt::format("BOP potential file with {} elements",bop_types)); + error->one(FLERR,"BOP potential file with {} elements",bop_types); bop_elements = new char*[bop_types]; bop_masses = new double[bop_types]; @@ -2221,8 +2221,7 @@ void PairBOP::write_tables(int npts) int param = elem2param[i][j]; PairParameters & pair = pairParameters[param]; - filename = fmt::format("{}{}_Pair_SPR_{}",bop_elements[i], - bop_elements[j],comm->me); + filename = fmt::format("{}{}_Pair_SPR_{}",bop_elements[i],bop_elements[j],comm->me); fp = fopen(filename.c_str(), "w"); xmin = (pair.betaS)->get_xmin(); @@ -2240,8 +2239,7 @@ void PairBOP::write_tables(int npts) fclose(fp); if (pair.cutL != 0) { - filename = fmt::format("{}{}_Pair_L_{}",bop_elements[i], - bop_elements[j],comm->me); + filename = fmt::format("{}{}_Pair_L_{}",bop_elements[i],bop_elements[j],comm->me); fp = fopen(filename.c_str(), "w"); xmin = (pair.cphi)->get_xmin(); xmax = (pair.cphi)->get_xmax(); @@ -2254,8 +2252,7 @@ void PairBOP::write_tables(int npts) } fclose(fp); } - filename = fmt::format("{}{}_Pair_BO_{}", bop_elements[i], - bop_elements[j], comm->me); + filename = fmt::format("{}{}_Pair_BO_{}", bop_elements[i],bop_elements[j], comm->me); fp = fopen(filename.c_str(), "w"); xmin = (pair.bo)->get_xmin(); xmax = (pair.bo)->get_xmax(); diff --git a/src/MDI/mdi_engine.cpp b/src/MDI/mdi_engine.cpp index 42a3e7194b..58f750f62a 100644 --- a/src/MDI/mdi_engine.cpp +++ b/src/MDI/mdi_engine.cpp @@ -240,7 +240,7 @@ MDIEngine::MDIEngine(LAMMPS *_lmp, int narg, char **arg) : Pointers(_lmp) break; } else - error->all(FLERR, fmt::format("MDI engine exited with invalid command: {}", mdicmd)); + error->all(FLERR, "MDI engine exited with invalid command: {}", mdicmd); } // clean up diff --git a/src/OPENMP/fix_qeq_reaxff_omp.cpp b/src/OPENMP/fix_qeq_reaxff_omp.cpp index 094c12b114..c6d92dea6d 100644 --- a/src/OPENMP/fix_qeq_reaxff_omp.cpp +++ b/src/OPENMP/fix_qeq_reaxff_omp.cpp @@ -224,8 +224,8 @@ void FixQEqReaxFFOMP::compute_H() } // omp if (m_fill >= H.m) - error->all(FLERR,fmt::format("Fix qeq/reaxff: H matrix size has been " - "exceeded: m_fill={} H.m={}\n", m_fill, H.m)); + error->all(FLERR,"Fix qeq/reaxff: H matrix size has been exceeded: m_fill={} H.m={}\n", + m_fill, H.m); } /* ---------------------------------------------------------------------- */ @@ -467,9 +467,8 @@ int FixQEqReaxFFOMP::CG(double *b, double *x) } if ((i >= imax) && maxwarn && (comm->me == 0)) - error->warning(FLERR,fmt::format("Fix qeq/reaxff/omp CG convergence failed " - "after {} iterations at step {}", - i,update->ntimestep)); + error->warning(FLERR,"Fix qeq/reaxff/omp CG convergence failed after {} iterations at step {}", + i,update->ntimestep); return i; } @@ -796,9 +795,8 @@ int FixQEqReaxFFOMP::dual_CG(double *b1, double *b2, double *x1, double *x2) } if ((i >= imax) && maxwarn && (comm->me == 0)) - error->warning(FLERR,fmt::format("Fix qeq/reaxff/omp CG convergence failed " - "after {} iterations at step {}", - i,update->ntimestep)); + error->warning(FLERR,"Fix qeq/reaxff/omp CG convergence failed after {} iterations at step {}", + i,update->ntimestep); return matvecs_s + matvecs_t; } diff --git a/src/OPENMP/msm_cg_omp.cpp b/src/OPENMP/msm_cg_omp.cpp index 66cb32fdf5..6904830fed 100644 --- a/src/OPENMP/msm_cg_omp.cpp +++ b/src/OPENMP/msm_cg_omp.cpp @@ -138,11 +138,10 @@ void MSMCGOMP::compute(int eflag, int vflag) / static_cast(atom->natoms); if (me == 0) - utils::logmesg(MSM::lmp,fmt::format(" MSM/cg optimization cutoff: {:.8}\n" - " Total charged atoms: {:.1f}%\n" - " Min/max charged atoms/proc: {:.1f}%" - " {:.1f}%\n",smallq, - charged_frac,charged_fmin,charged_fmax)); + utils::logmesg(MSM::lmp," MSM/cg optimization cutoff: {:.8}\n" + " Total charged atoms: {:.1f}%\n" + " Min/max charged atoms/proc: {:.1f}%" + " {:.1f}%\n",smallq, charged_frac,charged_fmin,charged_fmax); } // only need to rebuild this list after a neighbor list update diff --git a/src/QEQ/fix_qeq.cpp b/src/QEQ/fix_qeq.cpp index 394ce69d22..b60438b7c8 100644 --- a/src/QEQ/fix_qeq.cpp +++ b/src/QEQ/fix_qeq.cpp @@ -810,8 +810,7 @@ void FixQEq::read_file(char *file) for (int n=1; n <= ntypes; ++n) if (setflag[n] == 0) - error->one(FLERR,fmt::format("Parameters for atom type {} missing in " - "qeq parameter file", n)); + error->one(FLERR,"Parameters for atom type {} missing in qeq parameter file", n); delete[] setflag; } diff --git a/src/REAXFF/fix_qeq_reaxff.cpp b/src/REAXFF/fix_qeq_reaxff.cpp index 554b911151..f0fc7fef99 100644 --- a/src/REAXFF/fix_qeq_reaxff.cpp +++ b/src/REAXFF/fix_qeq_reaxff.cpp @@ -697,8 +697,8 @@ void FixQEqReaxFF::compute_H() } if (m_fill >= H.m) - error->all(FLERR,fmt::format("Fix qeq/reaxff H matrix size has been " - "exceeded: m_fill={} H.m={}\n", m_fill, H.m)); + error->all(FLERR,"Fix qeq/reaxff H matrix size has been exceeded: m_fill={} H.m={}\n", + m_fill, H.m); } /* ---------------------------------------------------------------------- */ @@ -772,9 +772,8 @@ int FixQEqReaxFF::CG(double *b, double *x) } if ((i >= imax) && maxwarn && (comm->me == 0)) - error->warning(FLERR,fmt::format("Fix qeq/reaxff CG convergence failed " - "after {} iterations at step {}", - i,update->ntimestep)); + error->warning(FLERR, "Fix qeq/reaxff CG convergence failed after {} iterations at step {}", + i,update->ntimestep); return i; } diff --git a/src/REAXFF/fix_reaxff_bonds.cpp b/src/REAXFF/fix_reaxff_bonds.cpp index 8bd7ed0020..653f207e90 100644 --- a/src/REAXFF/fix_reaxff_bonds.cpp +++ b/src/REAXFF/fix_reaxff_bonds.cpp @@ -56,8 +56,8 @@ FixReaxFFBonds::FixReaxFFBonds(LAMMPS *lmp, int narg, char **arg) : if (!fp) error->one(FLERR,"Cannot open compressed file"); } else fp = fopen(arg[4],"w"); - if (!fp) error->one(FLERR,fmt::format("Cannot open fix reaxff/bonds file {}: {}", - arg[4],utils::getsyserror())); + if (!fp) error->one(FLERR,"Cannot open fix reaxff/bonds file {}: {}", + arg[4],utils::getsyserror()); } if (atom->tag_consecutive() == 0) diff --git a/src/REAXFF/reaxff_allocate.cpp b/src/REAXFF/reaxff_allocate.cpp index 5b0a4e513c..ce56668a01 100644 --- a/src/REAXFF/reaxff_allocate.cpp +++ b/src/REAXFF/reaxff_allocate.cpp @@ -253,8 +253,8 @@ namespace ReaxFF { if (Nflag || wsr->num_far >= far_nbrs->num_intrs * DANGER_ZONE) { if (wsr->num_far > far_nbrs->num_intrs) - error->one(FLERR,fmt::format("step{}: ran out of space on far_nbrs: top={}, max={}", - data->step, wsr->num_far, far_nbrs->num_intrs)); + error->one(FLERR, "step{}: ran out of space on far_nbrs: top={}, max={}", + data->step, wsr->num_far, far_nbrs->num_intrs); newsize = static_cast (MAX(wsr->num_far*safezone, mincap*REAX_MIN_NBRS)); diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index 630427b690..11933164eb 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -129,9 +129,11 @@ void NEB::command(int narg, char **arg) if (nevery <= 0) error->universe_all(FLERR, fmt::format("Illegal NEB command every parameter: {}", nevery)); if (n1steps % nevery) - error->all(FLERR, fmt::format("NEB N1 value {} incompatible with every {}", n1steps, nevery)); + error->universe_all(FLERR, fmt::format("NEB N1 value {} incompatible with every {}", + n1steps, nevery)); if (n2steps % nevery) - error->all(FLERR, fmt::format("NEB N2 value {} incompatible with every {}", n2steps, nevery)); + error->universe_all(FLERR, fmt::format("NEB N2 value {} incompatible with every {}", + n2steps, nevery)); // replica info diff --git a/src/REPLICA/temper_grem.cpp b/src/REPLICA/temper_grem.cpp index 303f502309..c4509791c3 100644 --- a/src/REPLICA/temper_grem.cpp +++ b/src/REPLICA/temper_grem.cpp @@ -97,7 +97,7 @@ void TemperGrem::command(int narg, char **arg) FixNH *nh = dynamic_cast(modify->get_fix_by_id(arg[4])); if (!nh) - error->all(FLERR,fmt::format("Fix {} for Nose-Hoover fix does not exist", arg[4])); + error->universe_all(FLERR,fmt::format("Fix {} for Nose-Hoover fix does not exist", arg[4])); // get result from nvt vs npt check from fix_grem diff --git a/src/lammps.cpp b/src/lammps.cpp index 5de2144146..6fc06521d1 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -530,7 +530,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : if (infile == nullptr) error->one(FLERR,"Cannot open input script {}: {}", arg[inflag], utils::getsyserror()); if (!helpflag) - utils::logmesg(this,fmt::format("LAMMPS ({}{})\n", version, update_string)); + utils::logmesg(this,"LAMMPS ({}{})\n", version, update_string); // warn against using I/O redirection in parallel runs if ((inflag == 0) && (universe->nprocs > 1)) @@ -626,8 +626,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : } if ((me == 0) && (!helpflag)) - utils::logmesg(this,fmt::format("LAMMPS ({})\nProcessor partition = {}\n", - version, universe->iworld)); + utils::logmesg(this,"LAMMPS ({})\nProcessor partition = {}\n", version, universe->iworld); } // check consistency of datatype settings in lmptype.h @@ -762,8 +761,7 @@ LAMMPS::~LAMMPS() noexcept(false) totalclock = (totalclock - seconds) / 60.0; int minutes = fmod(totalclock,60.0); int hours = (totalclock - minutes) / 60.0; - utils::logmesg(this,fmt::format("Total wall time: {}:{:02d}:{:02d}\n", - hours, minutes, seconds)); + utils::logmesg(this, "Total wall time: {}:{:02d}:{:02d}\n", hours, minutes, seconds); } if (universe->nworlds == 1) { diff --git a/src/read_data.cpp b/src/read_data.cpp index 4b4602f1fc..dcc0f7b46c 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -364,7 +364,7 @@ void ReadData::command(int narg, char **arg) // check if data file is available and readable if (!platform::file_is_readable(arg[0])) - error->all(FLERR, fmt::format("Cannot open file {}: {}", arg[0], utils::getsyserror())); + error->all(FLERR, "Cannot open file {}: {}", arg[0], utils::getsyserror()); // reset so we can warn about reset image flags exactly once per data file diff --git a/src/special.cpp b/src/special.cpp index 7e15ec9e80..5d9b2bb09e 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -62,12 +62,11 @@ void Special::build() if (me == 0) { const double * const special_lj = force->special_lj; const double * const special_coul = force->special_coul; - auto mesg = fmt::format("Finding 1-2 1-3 1-4 neighbors ...\n" - " special bond factors lj: {:<8} {:<8} {:<8}\n" - " special bond factors coul: {:<8} {:<8} {:<8}\n", - special_lj[1],special_lj[2],special_lj[3], - special_coul[1],special_coul[2],special_coul[3]); - utils::logmesg(lmp,mesg); + utils::logmesg(lmp, "Finding 1-2 1-3 1-4 neighbors ...\n" + " special bond factors lj: {:<8} {:<8} {:<8}\n" + " special bond factors coul: {:<8} {:<8} {:<8}\n", + special_lj[1],special_lj[2],special_lj[3], + special_coul[1],special_coul[2],special_coul[3]); } // set onefive_flag if special_bonds command set it @@ -162,7 +161,7 @@ void Special::build() if (onefive_flag) { onefive_build(); if (me == 0) - utils::logmesg(lmp,fmt::format("{:>6} = max # of 1-5 neighbors\n",maxall)); + utils::logmesg(lmp,"{:>6} = max # of 1-5 neighbors\n",maxall); } // finish processing the onetwo, onethree, onefour, onefive lists diff --git a/src/utils.cpp b/src/utils.cpp index dd18c4406d..992feb34e8 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -557,7 +557,7 @@ void utils::bounds(const char *file, int line, const std::string &str, // check for illegal charcters size_t found = str.find_first_not_of("*-0123456789"); if (found != std::string::npos) { - if (error) error->all(file, line, fmt::format("Invalid range string: {}", str)); + if (error) error->all(file, line, "Invalid range string: {}", str); return; } @@ -580,17 +580,14 @@ void utils::bounds(const char *file, int line, const std::string &str, if (error) { if ((nlo <= 0) || (nhi <= 0)) - error->all(file, line, fmt::format("Invalid range string: {}", str)); + error->all(file, line, "Invalid range string: {}", str); if (nlo < nmin) - error->all(file, line, fmt::format("Numeric index {} is out of bounds ({}-{})", - nlo, nmin, nmax)); + error->all(file, line, "Numeric index {} is out of bounds ({}-{})", nlo, nmin, nmax); else if (nhi > nmax) - error->all(file, line, fmt::format("Numeric index {} is out of bounds ({}-{})", - nhi, nmin, nmax)); + error->all(file, line, "Numeric index {} is out of bounds ({}-{})", nhi, nmin, nmax); else if (nlo > nhi) - error->all(file, line, fmt::format("Numeric index {} is out of bounds ({}-{})", - nlo, nmin, nhi)); + error->all(file, line, "Numeric index {} is out of bounds ({}-{})", nlo, nmin, nhi); } }