From 742a7727673f8145f4491515f905f4ed1bfa7ba4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 23 Nov 2023 00:24:34 -0500 Subject: [PATCH 01/15] report Kokkos library version and OpenMP standard version --- src/KOKKOS/kokkos.cpp | 3 ++- src/info.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index ab72ff3f8e..57530cc5e7 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -68,7 +68,8 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) int me = 0; MPI_Comm_rank(world,&me); - if (me == 0) error->message(FLERR,"KOKKOS mode is enabled"); + if (me == 0) error->message(FLERR,"KOKKOS mode with Kokkos version {}.{}.{} is enabled", + KOKKOS_VERSION_MAJOR, KOKKOS_VERSION_MINOR, KOKKOS_VERSION_PATCH); // process any command-line args that invoke Kokkos settings diff --git a/src/info.cpp b/src/info.cpp index 491cfc728d..f7b347e883 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -1225,6 +1225,10 @@ std::string Info::get_accelerator_info(const std::string &package) if (has_accelerator_feature("KOKKOS","precision","single")) mesg += " single"; if (has_accelerator_feature("KOKKOS","precision","mixed")) mesg += " mixed"; if (has_accelerator_feature("KOKKOS","precision","double")) mesg += " double"; +#if LMP_KOKKOS + mesg += "\nKokkos library version: " + std::to_string(KOKKOS_VERSION_MAJOR) + "." + + std::to_string(KOKKOS_VERSION_MINOR) + "." + std::to_string(KOKKOS_VERSION_PATCH); +#endif mesg += "\n"; } if ((package.empty() || (package == "OPENMP")) && has_package("OPENMP")) { @@ -1235,6 +1239,9 @@ std::string Info::get_accelerator_info(const std::string &package) if (has_accelerator_feature("OPENMP","precision","single")) mesg += " single"; if (has_accelerator_feature("OPENMP","precision","mixed")) mesg += " mixed"; if (has_accelerator_feature("OPENMP","precision","double")) mesg += " double"; +#if defined(_OPENMP) + mesg += "\nOpenMP standard: " + platform::openmp_standard(); +#endif mesg += "\n"; } if ((package.empty() || (package == "INTEL")) && has_package("INTEL")) { From 9c19495392423de0ef1b73950e7f0946f4a14358 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 23 Nov 2023 00:37:26 -0500 Subject: [PATCH 02/15] detect newer OpenMP standard versions --- src/platform.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/platform.cpp b/src/platform.cpp index b06090094b..a53318958d 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -391,8 +391,16 @@ std::string platform::openmp_standard() // Supported OpenMP version corresponds to the release date of the // specifications as posted at https://www.openmp.org/specifications/ -#if _OPENMP > 202011 - return "OpenMP newer than version 5.1"; +#if _OPENMP > 202411 + return "OpenMP newer than version 6.0"; +#elif _OPENMP == 202411 + return "OpenMP 6.0"; +#elif _OPENMP == 202311 + return "OpenMP 6.0 preview 2"; +#elif _OPENMP == 202211 + return "OpenMP 6.0 preview 1"; +#elif _OPENMP == 202111 + return "OpenMP 5.2"; #elif _OPENMP == 202011 return "OpenMP 5.1"; #elif _OPENMP == 201811 From 4cf8045f8199faa5a7ef6bb9fe413c55b4100863 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 23 Nov 2023 12:37:49 -0500 Subject: [PATCH 03/15] add check and document that "scale yes" is not supported for scaling atomic parameters with fix adapt/fep --- doc/src/fix_adapt_fep.rst | 4 +++- src/FEP/fix_adapt_fep.cpp | 18 ++++++++++-------- src/fix_adapt.cpp | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/doc/src/fix_adapt_fep.rst b/doc/src/fix_adapt_fep.rst index c35986de49..1b2298cd96 100644 --- a/doc/src/fix_adapt_fep.rst +++ b/doc/src/fix_adapt_fep.rst @@ -307,7 +307,9 @@ the :doc:`run ` command. This fix is not invoked during Restrictions """""""""""" - none + +The keyword "scale yes" is not supported for scaling per-atom parameters +diameter and change. You can use :doc:`fix adapt ` for those. Related commands """""""""""""""" diff --git a/src/FEP/fix_adapt_fep.cpp b/src/FEP/fix_adapt_fep.cpp index e050b8cf21..c32b44b081 100644 --- a/src/FEP/fix_adapt_fep.cpp +++ b/src/FEP/fix_adapt_fep.cpp @@ -40,8 +40,8 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{PAIR,KSPACE,ATOM}; -enum{DIAMETER,CHARGE}; +enum{PAIR, KSPACE, ATOM}; +enum{DIAMETER, CHARGE}; /* ---------------------------------------------------------------------- */ @@ -165,21 +165,21 @@ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) : FixAdaptFEP::~FixAdaptFEP() { for (int m = 0; m < nadapt; m++) { - delete [] adapt[m].var; + delete[] adapt[m].var; if (adapt[m].which == PAIR) { - delete [] adapt[m].pstyle; - delete [] adapt[m].pparam; + delete[] adapt[m].pstyle; + delete[] adapt[m].pparam; memory->destroy(adapt[m].array_orig); } } - delete [] adapt; + delete[] adapt; // check nfix in case all fixes have already been deleted if (id_fix_diam && modify->nfix) modify->delete_fix(id_fix_diam); if (id_fix_chg && modify->nfix) modify->delete_fix(id_fix_chg); - delete [] id_fix_diam; - delete [] id_fix_chg; + delete[] id_fix_diam; + delete[] id_fix_chg; } /* ---------------------------------------------------------------------- */ @@ -434,6 +434,8 @@ void FixAdaptFEP::change_settings() } else if (ad->which == ATOM) { + if (scaleflag) + error->all(FLERR, "Keyword 'scale yes' is not supported with fix adapt/fep for 'atom'"); // reset radius from diameter // also scale rmass to new value diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index 660e3f6107..996597ab8b 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -39,8 +39,8 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{PAIR,KSPACE,ATOM,BOND,ANGLE}; -enum{DIAMETER,CHARGE}; +enum{PAIR, KSPACE, ATOM, BOND, ANGLE}; +enum{DIAMETER, CHARGE}; /* ---------------------------------------------------------------------- */ From 35103df86b04c8fb8c95c4e2c2b393da05be27c3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 23 Nov 2023 14:25:05 -0500 Subject: [PATCH 04/15] make compatible with Kokkos 3.7 --- src/KOKKOS/kokkos.cpp | 5 +++-- src/info.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 57530cc5e7..c963cd52d0 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -68,8 +68,9 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) int me = 0; MPI_Comm_rank(world,&me); - if (me == 0) error->message(FLERR,"KOKKOS mode with Kokkos version {}.{}.{} is enabled", - KOKKOS_VERSION_MAJOR, KOKKOS_VERSION_MINOR, KOKKOS_VERSION_PATCH); + if (me == 0) + error->message(FLERR,"KOKKOS mode with Kokkos version {}.{}.{} is enabled", + KOKKOS_VERSION / 10000, (KOKKOS_VERSION % 10000) / 100, KOKKOS_VERSION % 100); // process any command-line args that invoke Kokkos settings diff --git a/src/info.cpp b/src/info.cpp index f7b347e883..ec04a6c46c 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -1226,8 +1226,8 @@ std::string Info::get_accelerator_info(const std::string &package) if (has_accelerator_feature("KOKKOS","precision","mixed")) mesg += " mixed"; if (has_accelerator_feature("KOKKOS","precision","double")) mesg += " double"; #if LMP_KOKKOS - mesg += "\nKokkos library version: " + std::to_string(KOKKOS_VERSION_MAJOR) + "." - + std::to_string(KOKKOS_VERSION_MINOR) + "." + std::to_string(KOKKOS_VERSION_PATCH); + mesg += fmt::format("\nKokkos library version: {}.{}.{}", KOKKOS_VERSION / 10000, + (KOKKOS_VERSION % 10000) / 100, KOKKOS_VERSION % 100); #endif mesg += "\n"; } From 1f6f612bb6649d352520b439841d09e8e7003024 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 24 Nov 2023 01:02:00 -0500 Subject: [PATCH 05/15] remove redundant code and fix memory leaks --- src/dump_image.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dump_image.cpp b/src/dump_image.cpp index a20f33eca3..ba7e36eb0b 100644 --- a/src/dump_image.cpp +++ b/src/dump_image.cpp @@ -134,13 +134,9 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) : } char *fixID = nullptr; - thetastr = phistr = nullptr; cflag = STATIC; cx = cy = cz = 0.5; - cxstr = cystr = czstr = nullptr; - upxstr = upystr = upzstr = nullptr; - zoomstr = nullptr; boxflag = YES; boxdiam = 0.02; axesflag = NO; @@ -487,6 +483,16 @@ DumpImage::~DumpImage() memory->destroy(bufcopy); memory->destroy(gbuf); + delete[] upxstr; + delete[] upystr; + delete[] upzstr; + delete[] zoomstr; + delete[] thetastr; + delete[] phistr; + delete[] cxstr; + delete[] cystr; + delete[] czstr; + delete[] id_grid_compute; delete[] id_grid_fix; } From cea15287657fb8c629d42e3e96651996edf4a668 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 24 Nov 2023 01:08:34 -0500 Subject: [PATCH 06/15] update list of packages included in coverity runs --- .github/workflows/coverity.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index b1c23e1f6a..00a4596cc8 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -59,16 +59,13 @@ jobs: -D BUILD_SHARED_LIBS=on \ -D LAMMPS_SIZES=SMALLBIG \ -D LAMMPS_EXCEPTIONS=off \ - -D PKG_MESSAGE=on \ - -D PKG_MPIIO=on \ -D PKG_ATC=on \ -D PKG_AWPMD=on \ - -D PKG_BOCS=on \ - -D PKG_EFF=on \ -D PKG_H5MD=on \ -D PKG_INTEL=on \ -D PKG_LATBOLTZ=on \ -D PKG_MANIFOLD=on \ + -D PKG_MDI=on \ -D PKG_MGPT=on \ -D PKG_ML-PACE=on \ -D PKG_ML-RANN=on \ @@ -77,7 +74,6 @@ jobs: -D PKG_PTM=on \ -D PKG_QTB=on \ -D PKG_SMTBQ=on \ - -D PKG_TALLY=on \ ../cmake - name: Run Coverity Scan From 351fc63f276a8e0463e6ba54ca3c01139d3997ac Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 24 Nov 2023 01:13:03 -0500 Subject: [PATCH 07/15] use const reference instead of copy --- src/LEPTON/angle_lepton.cpp | 2 +- src/LEPTON/bond_lepton.cpp | 2 +- src/LEPTON/pair_lepton.cpp | 2 +- src/LEPTON/pair_lepton_coul.cpp | 2 +- src/LEPTON/pair_lepton_sphere.cpp | 2 +- src/ML-POD/fitpod_command.cpp | 2 +- src/ML-POD/mlpod.cpp | 2 +- src/platform.cpp | 4 ++-- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/LEPTON/angle_lepton.cpp b/src/LEPTON/angle_lepton.cpp index 20d0feb41a..59310f5637 100644 --- a/src/LEPTON/angle_lepton.cpp +++ b/src/LEPTON/angle_lepton.cpp @@ -360,7 +360,7 @@ double AngleLepton::single(int type, int i1, int i2, int i3) if (c < -1.0) c = -1.0; double dtheta = acos(c) - theta0[type]; - auto expr = expressions[type2expression[type]]; + const auto &expr = expressions[type2expression[type]]; auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp)); auto anglepot = parsed.createCompiledExpression(); anglepot.getVariableReference("theta") = dtheta; diff --git a/src/LEPTON/bond_lepton.cpp b/src/LEPTON/bond_lepton.cpp index ca0c633dc9..773607782d 100644 --- a/src/LEPTON/bond_lepton.cpp +++ b/src/LEPTON/bond_lepton.cpp @@ -298,7 +298,7 @@ double BondLepton::single(int type, double rsq, int /*i*/, int /*j*/, double &ff const double r = sqrt(rsq); const double dr = r - r0[type]; - auto expr = expressions[type2expression[type]]; + const auto &expr = expressions[type2expression[type]]; auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp)); auto bondpot = parsed.createCompiledExpression(); auto bondforce = parsed.differentiate("r").createCompiledExpression(); diff --git a/src/LEPTON/pair_lepton.cpp b/src/LEPTON/pair_lepton.cpp index e9ba3b02bc..a8af0ce576 100644 --- a/src/LEPTON/pair_lepton.cpp +++ b/src/LEPTON/pair_lepton.cpp @@ -423,7 +423,7 @@ void PairLepton::write_data_all(FILE *fp) double PairLepton::single(int /* i */, int /* j */, int itype, int jtype, double rsq, double /* factor_coul */, double factor_lj, double &fforce) { - auto expr = expressions[type2expression[itype][jtype]]; + const auto &expr = expressions[type2expression[itype][jtype]]; auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp), functions); auto pairpot = parsed.createCompiledExpression(); auto pairforce = parsed.differentiate("r").createCompiledExpression(); diff --git a/src/LEPTON/pair_lepton_coul.cpp b/src/LEPTON/pair_lepton_coul.cpp index 2a3f96985b..841565e874 100644 --- a/src/LEPTON/pair_lepton_coul.cpp +++ b/src/LEPTON/pair_lepton_coul.cpp @@ -242,7 +242,7 @@ void PairLeptonCoul::read_restart_settings(FILE *fp) double PairLeptonCoul::single(int i, int j, int itype, int jtype, double rsq, double factor_coul, double /* factor_lj */, double &fforce) { - auto expr = expressions[type2expression[itype][jtype]]; + const auto &expr = expressions[type2expression[itype][jtype]]; auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp), functions); auto pairpot = parsed.createCompiledExpression(); auto pairforce = parsed.differentiate("r").createCompiledExpression(); diff --git a/src/LEPTON/pair_lepton_sphere.cpp b/src/LEPTON/pair_lepton_sphere.cpp index f29fd0b48a..29514aed38 100644 --- a/src/LEPTON/pair_lepton_sphere.cpp +++ b/src/LEPTON/pair_lepton_sphere.cpp @@ -205,7 +205,7 @@ void PairLeptonSphere::read_restart_settings(FILE *fp) double PairLeptonSphere::single(int i, int j, int itype, int jtype, double rsq, double /* factor_coul */, double factor_lj, double &fforce) { - auto expr = expressions[type2expression[itype][jtype]]; + const auto &expr = expressions[type2expression[itype][jtype]]; auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp), functions); auto pairpot = parsed.createCompiledExpression(); auto pairforce = parsed.differentiate("r").createCompiledExpression(); diff --git a/src/ML-POD/fitpod_command.cpp b/src/ML-POD/fitpod_command.cpp index 97ef93ab91..87de65c3e2 100644 --- a/src/ML-POD/fitpod_command.cpp +++ b/src/ML-POD/fitpod_command.cpp @@ -177,7 +177,7 @@ int FitPOD::read_data_file(double *fitting_weights, std::string &file_format, if (words.size() == 0) continue; - auto keywd = words[0]; + const auto &keywd = words[0]; if (words.size() != 2) error->one(FLERR,"Improper POD file.", utils::getsyserror()); diff --git a/src/ML-POD/mlpod.cpp b/src/ML-POD/mlpod.cpp index 019685153f..f20498b50b 100644 --- a/src/ML-POD/mlpod.cpp +++ b/src/ML-POD/mlpod.cpp @@ -328,7 +328,7 @@ void MLPOD::read_pod(const std::string &pod_file) if (words.size() == 0) continue; - auto keywd = words[0]; + const auto &keywd = words[0]; if (keywd == "species") { pod.nelements = words.size()-1; diff --git a/src/platform.cpp b/src/platform.cpp index a53318958d..064f142425 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -1066,7 +1066,7 @@ FILE *platform::compressed_read(const std::string &file) FILE *fp = nullptr; #if defined(LAMMPS_GZIP) - auto compress = find_compress_type(file); + const auto &compress = find_compress_type(file); if (compress.style == ::compress_info::NONE) return nullptr; if (find_exe_path(compress.command).size()) @@ -1085,7 +1085,7 @@ FILE *platform::compressed_write(const std::string &file) FILE *fp = nullptr; #if defined(LAMMPS_GZIP) - auto compress = find_compress_type(file); + const auto &compress = find_compress_type(file); if (compress.style == ::compress_info::NONE) return nullptr; if (find_exe_path(compress.command).size()) From ea7f0deb42d181af73852ee19ea3985ba4c3c838 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 24 Nov 2023 14:46:49 -0500 Subject: [PATCH 08/15] some compilers require a code block to follow OpenMP pragmas, even if empty. --- src/OPENMP/reaxff_forces_omp.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OPENMP/reaxff_forces_omp.cpp b/src/OPENMP/reaxff_forces_omp.cpp index 50157da594..26922add1e 100644 --- a/src/OPENMP/reaxff_forces_omp.cpp +++ b/src/OPENMP/reaxff_forces_omp.cpp @@ -354,6 +354,9 @@ namespace ReaxFF { // Need to wait for all indices and tmp arrays accumulated. #if defined(_OPENMP) #pragma omp barrier + { + ; + } #endif #if defined(_OPENMP) From e4149035faa311a934abddc0b945f9fc4c73488f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 25 Nov 2023 05:58:05 -0500 Subject: [PATCH 09/15] restore using nvcc_wrapper with kokkos-cude.cmake preset --- cmake/presets/kokkos-cuda.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/presets/kokkos-cuda.cmake b/cmake/presets/kokkos-cuda.cmake index ace8ff0879..c3ee081898 100644 --- a/cmake/presets/kokkos-cuda.cmake +++ b/cmake/presets/kokkos-cuda.cmake @@ -6,6 +6,8 @@ set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_CUDA ON CACHE BOOL "" FORCE) set(Kokkos_ARCH_PASCAL60 ON CACHE BOOL "" FORCE) set(BUILD_OMP ON CACHE BOOL "" FORCE) +get_filename_component(NVCC_WRAPPER_CMD ${CMAKE_CURRENT_SOURCE_DIR}/../lib/kokkos/bin/nvcc_wrapper ABSOLUTE) +set(CMAKE_CXX_COMPILER ${NVCC_WRAPPER_CMD} CACHE FILEPATH "" FORCE) # hide deprecation warnings temporarily for stable release set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE) From 088c5d72a8fc8319f40d59a6c3bddc533109252b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 26 Nov 2023 10:31:24 -0500 Subject: [PATCH 10/15] correct fix mvv/* compatibility checks in DPD-MESO package --- src/DPD-MESO/fix_mvv_dpd.cpp | 15 +++++++++++---- src/DPD-MESO/fix_mvv_edpd.cpp | 15 ++++++++++++--- src/DPD-MESO/fix_mvv_tdpd.cpp | 14 ++++++++++++-- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/DPD-MESO/fix_mvv_dpd.cpp b/src/DPD-MESO/fix_mvv_dpd.cpp index 18c88bd293..d51000b15b 100644 --- a/src/DPD-MESO/fix_mvv_dpd.cpp +++ b/src/DPD-MESO/fix_mvv_dpd.cpp @@ -63,13 +63,20 @@ int FixMvvDPD::setmask() void FixMvvDPD::init() { if (!atom->vest_flag) - error->all(FLERR,"Fix mvv/dpd requires atom attribute vest"); + error->all(FLERR,"Fix mvv/dpd requires atom attribute vest e.g. from atom style mdpd"); + + if (!force->pair_match("^mdpd",0) && !force->pair_match("^dpd",0)) { + if (force->pair_match("^hybrid",0)) { + if (!(force->pair_match("^mdpd",0,1) || force->pair_match("^dpd",0),1)) { + error->all(FLERR, "Must use a dpd or mdpd pair style with fix mvv/dpd"); + } + } else { + error->all(FLERR, "Must use a dpd or mdpd pair style with fix mvv/dpd"); + } + } dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - - if (!force->pair_match("^edpd",0) && !force->pair_match("^dpd",0)) - error->all(FLERR, "Must use a dpd or edpd pair style with fix mvv/edpd"); } /* ---------------------------------------------------------------------- diff --git a/src/DPD-MESO/fix_mvv_edpd.cpp b/src/DPD-MESO/fix_mvv_edpd.cpp index 03dd048119..7ac0dc3de7 100644 --- a/src/DPD-MESO/fix_mvv_edpd.cpp +++ b/src/DPD-MESO/fix_mvv_edpd.cpp @@ -71,11 +71,20 @@ int FixMvvEDPD::setmask() void FixMvvEDPD::init() { + if (!atom->edpd_flag) error->all(FLERR,"Fix mvv/edpd requires atom style edpd"); + + if (!force->pair_match("^edpd",0)) { + if (force->pair_match("^hybrid",0)) { + if (!force->pair_match("^edpd",0,1)) { + error->all(FLERR, "Must use pair style edpd with fix mvv/edpd"); + } + } else { + error->all(FLERR, "Must use pair style edpd with fix mvv/edpd"); + } + } + dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - - if (!force->pair_match("^edpd",0)) - error->all(FLERR, "Must use pair style edpd with fix mvv/edpd"); } /* ---------------------------------------------------------------------- diff --git a/src/DPD-MESO/fix_mvv_tdpd.cpp b/src/DPD-MESO/fix_mvv_tdpd.cpp index f3894da214..122fd56365 100644 --- a/src/DPD-MESO/fix_mvv_tdpd.cpp +++ b/src/DPD-MESO/fix_mvv_tdpd.cpp @@ -69,10 +69,20 @@ int FixMvvTDPD::setmask() void FixMvvTDPD::init() { + if (!atom->tdpd_flag) error->all(FLERR,"Fix mvv/tdpd requires atom style tdpd"); + + if (!force->pair_match("^tdpd",0)) { + if (force->pair_match("^hybrid",0)) { + if (!force->pair_match("^tdpd",0,1)) { + error->all(FLERR, "Must use pair style tdpd with fix mvv/tdpd"); + } + } else { + error->all(FLERR, "Must use pair style tdpd with fix mvv/tdpd"); + } + } + dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - if (!force->pair_match("^tdpd",0)) - error->all(FLERR, "Must use pair style tdpd with fix mvv/tdpd"); } /* ---------------------------------------------------------------------- From b90d63a1922b69fc0f938d973ce2870513c33108 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 26 Nov 2023 11:00:02 -0500 Subject: [PATCH 11/15] add versionaddded tag for new feature --- doc/src/variable.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/src/variable.rst b/doc/src/variable.rst index ac2a7adc75..cf136c7d89 100644 --- a/doc/src/variable.rst +++ b/doc/src/variable.rst @@ -706,6 +706,8 @@ library. Ceil() is the smallest integer not less than its argument. Floor() if the largest integer not greater than its argument. Round() is the nearest integer to its argument. +.. versionadded:: TBD + The ternary(x,y,z) function is the equivalent of the ternary operator (? and :) in C or C++. It takes 3 arguments. The first argument is a conditional. The result of the function is y if x evaluates to true From 1d2586214652cadde6cd11acaddf84076b799afa Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 26 Nov 2023 13:11:18 -0500 Subject: [PATCH 12/15] update documentation for the fact that exceptions in LAMMPS are always used --- doc/src/Developer_unittest.rst | 18 +++++------------- doc/src/Fortran.rst | 15 --------------- doc/src/Library.rst | 16 +++++++++------- doc/src/Python_error.rst | 4 +--- doc/src/Python_install.rst | 3 +-- doc/src/variable.rst | 7 +++---- src/library.cpp | 15 +-------------- 7 files changed, 20 insertions(+), 58 deletions(-) diff --git a/doc/src/Developer_unittest.rst b/doc/src/Developer_unittest.rst index 9886e9e4b4..67c5ce365a 100644 --- a/doc/src/Developer_unittest.rst +++ b/doc/src/Developer_unittest.rst @@ -180,19 +180,11 @@ discarded but by setting the verbose flag (via setting the ``TEST_ARGS`` environment variable, ``TEST_ARGS=-v``) it can be printed and used to understand why tests fail unexpectedly. -Another complexity of these tests stems from the need to capture -situations where LAMMPS will stop with an error, i.e. handle so-called -"death tests". Here the LAMMPS code will operate differently depending -on whether it was configured to throw C++ exceptions on errors or call -either ``exit()`` or ``MPI_Abort()``. In the latter case, the test code -also needs to detect whether LAMMPS was compiled with the OpenMPI -library, as OpenMPI is **only** compatible the death test options of the -GoogleTest library when C++ exceptions are enabled; otherwise those -"death tests" must be skipped to avoid reporting bogus failures. The -specifics of this step are implemented in the ``TEST_FAILURE()`` -macro. These tests operate by capturing the screen output when executing -the failing command and then comparing that with a provided regular -expression string pattern. Example: +The specifics of so-called "death tests", i.e. conditions where LAMMPS +should fail and throw an exception, are implemented in the +``TEST_FAILURE()`` macro. These tests operate by capturing the screen +output when executing the failing command and then comparing that with a +provided regular expression string pattern. Example: .. code-block:: c++ diff --git a/doc/src/Fortran.rst b/doc/src/Fortran.rst index 913c31842e..76fdff753a 100644 --- a/doc/src/Fortran.rst +++ b/doc/src/Fortran.rst @@ -3038,14 +3038,6 @@ Procedures Bound to the :f:type:`lammps` Derived Type This function can be used to query if an error inside of LAMMPS has thrown a :ref:`C++ exception `. - .. note:: - - This function will always report "no error" when the LAMMPS library - has been compiled without ``-DLAMMPS_EXCEPTIONS``, which turns fatal - errors aborting LAMMPS into C++ exceptions. You can use the library - function :cpp:func:`lammps_config_has_exceptions` to check if this is - the case. - :to: :cpp:func:`lammps_has_error` :r has_error: ``.TRUE.`` if there is an error. :rtype has_error: logical @@ -3068,13 +3060,6 @@ Procedures Bound to the :f:type:`lammps` Derived Type would happen only in a single MPI rank and thus may not be recoverable, as other MPI ranks may be waiting on the failing MPI rank(s) to send messages. - .. note:: - - This function will do nothing when the LAMMPS library has been - compiled without ``-DLAMMPS_EXCEPTIONS``, which turns errors aborting - LAMMPS into C++ exceptions. You can use the function - :f:func:`config_has_exceptions` to check whether this is the case. - :p character(len=\*) buffer: string buffer to copy the error message into :o integer(c_int) status [optional]: 1 when all ranks had the error, 2 on a single-rank error. diff --git a/doc/src/Library.rst b/doc/src/Library.rst index 09561cda82..50c28b7fcd 100644 --- a/doc/src/Library.rst +++ b/doc/src/Library.rst @@ -80,13 +80,15 @@ run LAMMPS in serial mode. :class: note If the LAMMPS executable encounters an error condition, it will abort - after printing an error message. For a library interface this is - usually not desirable. Thus LAMMPS can be compiled to to :ref:`throw - a C++ exception ` instead. If enabled, the library - functions will catch those exceptions and return. The error status - :cpp:func:`can be queried ` and an :cpp:func:`error - message retrieved `. We thus - recommend enabling C++ exceptions when using the library interface, + after printing an error message. It does so by catching the + exceptions that LAMMPS could throw. For a C library interface this + is usually not desirable since the calling code might lack the + ability to catch such exceptions. Thus, the library functions will + catch those exceptions and return from the affected functions. The + error status :cpp:func:`can be queried ` and an + :cpp:func:`error message retrieved `. + This is, for example used by the :doc:`LAMMPS python module + ` and then a suitable Python exception is thrown. .. admonition:: Using the C library interface as a plugin :class: note diff --git a/doc/src/Python_error.rst b/doc/src/Python_error.rst index f6a94c0e82..6aec8df391 100644 --- a/doc/src/Python_error.rst +++ b/doc/src/Python_error.rst @@ -15,9 +15,7 @@ Python exception handling mechanism. try: # LAMMPS will normally terminate itself and the running process if an error - # occurs. This would kill the Python interpreter. To avoid this, make sure to - # compile with LAMMPS_EXCEPTIONS enabled. This ensures the library API calls - # will not terminate the parent process. Instead, the library wrapper will + # occurs. This would kill the Python interpreter. The library wrapper will # detect that an error has occured and throw a Python exception lmp.command('unknown') diff --git a/doc/src/Python_install.rst b/doc/src/Python_install.rst index c4fbec0be4..01610b84f0 100644 --- a/doc/src/Python_install.rst +++ b/doc/src/Python_install.rst @@ -5,8 +5,7 @@ The LAMMPS Python module enables calling the :ref:`LAMMPS C library API ` from Python by dynamically loading functions in the LAMMPS shared library through the Python `ctypes `_ module. Because of the dynamic loading, it is required that LAMMPS is -compiled in :ref:`"shared" mode `. It is also recommended to -compile LAMMPS with :ref:`C++ exceptions ` enabled. +compiled in :ref:`"shared" mode `. Two components are necessary for Python to be able to invoke LAMMPS code: diff --git a/doc/src/variable.rst b/doc/src/variable.rst index cf136c7d89..a70ac25836 100644 --- a/doc/src/variable.rst +++ b/doc/src/variable.rst @@ -1044,10 +1044,9 @@ to built-in commands. For all of these styles except *command*, appending of active suffixes is also tried before reporting failure. The *feature* category checks the availability of the following -compile-time enabled features: GZIP support, PNG support, JPEG -support, FFMPEG support, and C++ exceptions for error -handling. Corresponding names are *gzip*, *png*, *jpeg*, *ffmpeg* and -*exceptions*\ . +compile-time enabled features: GZIP support, PNG support, JPEG support, +FFMPEG support, and C++ exceptions for error handling. Corresponding +names are *gzip*, *png*, *jpeg*, *ffmpeg* and *exceptions*\ . Example: Only dump in a given format if the compiled binary supports it. diff --git a/src/library.cpp b/src/library.cpp index 363110e5f5..1acdfc4787 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -481,7 +481,7 @@ void lammps_error(void *handle, int error_type, const char *error_text) } END_CAPTURE - // with enabled exceptions the above code will simply throw an + // in case of an error the above code will simply throw an // exception and record the error message. So we have to explicitly // stop here like we do in main.cpp if (lammps_has_error(handle)) { @@ -6608,13 +6608,6 @@ has thrown a :ref:`C++ exception `. instance, but instead would check the global error buffer of the library interface. -.. note:: - - This function will always report "no error" when the LAMMPS library - has been compiled without ``-DLAMMPS_EXCEPTIONS``, which turns fatal - errors aborting LAMMPS into C++ exceptions. You can use the library - function :cpp:func:`lammps_config_has_exceptions` to check whether this is - the case. \endverbatim * * \param handle pointer to a previously created LAMMPS instance cast to ``void *`` or NULL @@ -6663,12 +6656,6 @@ the failing MPI ranks to send messages. The *buffer* pointer may be ``NULL``. This will clear any error status without copying the error message. -.. note:: - - This function will do nothing when the LAMMPS library has been - compiled without ``-DLAMMPS_EXCEPTIONS``, which turns errors aborting - LAMMPS into C++ exceptions. You can use the library function - :cpp:func:`lammps_config_has_exceptions` to check whether this is the case. \endverbatim * * \param handle pointer to a previously created LAMMPS instance cast to ``void *`` or NULL. From 9e1f85518c1de2bdb48929f14dcd363b77ab6a0d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Nov 2023 05:31:12 -0500 Subject: [PATCH 13/15] avoid segfault with immediate variables --- src/variable.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index b4a1ddd291..fe6eba39d9 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -1505,7 +1505,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) // equal-style or immediate variable is being evaluated - if ((style[ivar] == EQUAL) || (ivar < 0)) { + if ((ivar < 0) || (style[ivar] == EQUAL)) { // c_ID = scalar from global scalar @@ -1773,7 +1773,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) // equal-style or immediate variable is being evaluated - if ((style[ivar] == EQUAL) || (ivar < 0)) { + if ((ivar < 0) || (style[ivar] == EQUAL)) { // f_ID = scalar from global scalar From 7dbd6496838f7c4d7311826c3da1d9e962f3e6f7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Nov 2023 05:31:30 -0500 Subject: [PATCH 14/15] fix cut-n-paste bug --- src/compute_reduce.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compute_reduce.cpp b/src/compute_reduce.cpp index 3feabf2ec3..b296804248 100644 --- a/src/compute_reduce.cpp +++ b/src/compute_reduce.cpp @@ -260,7 +260,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR, "Compute {} compute {} array is accessed out-of-range", style, val.id); } else if (input_mode == LOCAL) { - if (!val.val.c->peratom_flag) + if (!val.val.c->local_flag) error->all(FLERR, "Compute {} compute {} does not calculate local values", style, val.id); if (val.argindex == 0 && val.val.c->size_local_cols != 0) error->all(FLERR, "Compute {} compute {} does not calculate a local vector", style, val.id); From 7249aea5e5a58fb73924c8d0240aecbf7f3881e2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Nov 2023 07:32:47 -0500 Subject: [PATCH 15/15] error out when no per-type masses are set. warn if both per-type and per-atom masses are used. --- doc/src/fix_atom_swap.rst | 6 ++++++ src/MC/fix_atom_swap.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/doc/src/fix_atom_swap.rst b/doc/src/fix_atom_swap.rst index ffd14ebb0f..aa8127561c 100644 --- a/doc/src/fix_atom_swap.rst +++ b/doc/src/fix_atom_swap.rst @@ -181,6 +181,12 @@ This fix is part of the MC package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` doc page for more info. +This fix cannot be used with systems that do not have per-type masses +(e.g. atom style sphere) since the implemented algorithm pre-computes +velocity rescaling factors from per-type masses and ignores any per-atom +masses, if present. In case both, per-type and per-atom masses are +present, a warning is printed. + Related commands """""""""""""""" diff --git a/src/MC/fix_atom_swap.cpp b/src/MC/fix_atom_swap.cpp index fa69773d82..6fe0ac98b7 100644 --- a/src/MC/fix_atom_swap.cpp +++ b/src/MC/fix_atom_swap.cpp @@ -203,6 +203,10 @@ int FixAtomSwap::setmask() void FixAtomSwap::init() { + if (!atom->mass) error->all(FLERR, "Fix atom/swap requires per atom type masses"); + if (atom->rmass_flag && (comm->me == 0)) + error->warning(FLERR, "Fix atom/swap will use per-type masses for velocity rescaling"); + c_pe = modify->get_compute_by_id("thermo_pe"); int *type = atom->type;