From 2d3504ff0f006793e4ac0bbc80b0193b7a612b00 Mon Sep 17 00:00:00 2001 From: chemshift Date: Sun, 7 Aug 2022 22:54:59 -0600 Subject: [PATCH 01/19] Locate correct dynamics library directories in Anaconda Environments --- python/lammps/mliap/__init__.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/python/lammps/mliap/__init__.py b/python/lammps/mliap/__init__.py index 57fe97d803..321594ad6d 100644 --- a/python/lammps/mliap/__init__.py +++ b/python/lammps/mliap/__init__.py @@ -4,17 +4,35 @@ # try to improperly start up a new interpreter. import sysconfig import ctypes -library = sysconfig.get_config_vars('INSTSONAME')[0] +import platform + +library_dir = sysconfig.get_config_vars('LIBDIR')[0] +library_name = sysconfig.get_config_vars('LIBRARY')[0] +library = library_dir + "/" + library_name + +OS_name = platform.system() + +if OS_name == "Linux": + SHLIB_SUFFIX = '.so' +elif OS_name == "Darwin": + SHLIB_SUFFIX = '.dylib' +elif OS_name == "Windows": + SHLIB_SUFFIX = '.dll' +else: + SHLIB_SUFFIX = sysconfig.get_config_vars('SHLIB_SUFFIX') + try: pylib = ctypes.CDLL(library) except OSError as e: - if pylib.endswith(".a"): - pylib.strip(".a") + ".so" + if library.endswith(".a"): + library = library.strip(".a") + ".so" pylib = ctypes.CDLL(library) else: raise e + if not pylib.Py_IsInitialized(): raise RuntimeError("This interpreter is not compatible with python-based mliap for LAMMPS.") + del sysconfig, ctypes, library, pylib from .loader import load_model, activate_mliappy From 2227de32314dc762dc19ec80731ca6d5d0efc0e8 Mon Sep 17 00:00:00 2001 From: chemshift Date: Sun, 7 Aug 2022 23:00:35 -0600 Subject: [PATCH 02/19] Update __init__.py --- python/lammps/mliap/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/lammps/mliap/__init__.py b/python/lammps/mliap/__init__.py index 321594ad6d..bc7dd1d6a2 100644 --- a/python/lammps/mliap/__init__.py +++ b/python/lammps/mliap/__init__.py @@ -25,7 +25,7 @@ try: pylib = ctypes.CDLL(library) except OSError as e: if library.endswith(".a"): - library = library.strip(".a") + ".so" + library = library.strip(".a") + SHLIB_SUFFIX pylib = ctypes.CDLL(library) else: raise e From 953d2c738b6fffafdbaa81b962a1d97e4079b44f Mon Sep 17 00:00:00 2001 From: chemshift Date: Mon, 8 Aug 2022 11:45:43 -0600 Subject: [PATCH 03/19] Update __init__.py --- python/lammps/mliap/__init__.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/python/lammps/mliap/__init__.py b/python/lammps/mliap/__init__.py index bc7dd1d6a2..a9ff2c6a70 100644 --- a/python/lammps/mliap/__init__.py +++ b/python/lammps/mliap/__init__.py @@ -6,29 +6,24 @@ import sysconfig import ctypes import platform -library_dir = sysconfig.get_config_vars('LIBDIR')[0] -library_name = sysconfig.get_config_vars('LIBRARY')[0] -library = library_dir + "/" + library_name - +library_dir = sysconfig.get_config_vars('prefix')[0] +py_ver = sysconfig.get_config_vars('VERSION')[0] OS_name = platform.system() if OS_name == "Linux": SHLIB_SUFFIX = '.so' + library = library_dir + '/lib/' + 'libpython' + py_ver + SHLIB_SUFFIX elif OS_name == "Darwin": SHLIB_SUFFIX = '.dylib' + library = library_dir + '/lib/' + 'libpython' + py_ver + SHLIB_SUFFIX elif OS_name == "Windows": SHLIB_SUFFIX = '.dll' -else: - SHLIB_SUFFIX = sysconfig.get_config_vars('SHLIB_SUFFIX') + library = library_dir + '\\' + 'python' + py_ver + SHLIB_SUFFIX try: pylib = ctypes.CDLL(library) -except OSError as e: - if library.endswith(".a"): - library = library.strip(".a") + SHLIB_SUFFIX - pylib = ctypes.CDLL(library) - else: - raise e +except: + OSError if not pylib.Py_IsInitialized(): raise RuntimeError("This interpreter is not compatible with python-based mliap for LAMMPS.") From fd2ab2a8b9c42c6226f181fd29bf44261e7a0621 Mon Sep 17 00:00:00 2001 From: chemshift Date: Mon, 8 Aug 2022 12:08:46 -0600 Subject: [PATCH 04/19] Update __init__.py --- python/lammps/mliap/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/python/lammps/mliap/__init__.py b/python/lammps/mliap/__init__.py index a9ff2c6a70..02d876bf9d 100644 --- a/python/lammps/mliap/__init__.py +++ b/python/lammps/mliap/__init__.py @@ -6,19 +6,18 @@ import sysconfig import ctypes import platform -library_dir = sysconfig.get_config_vars('prefix')[0] py_ver = sysconfig.get_config_vars('VERSION')[0] OS_name = platform.system() if OS_name == "Linux": SHLIB_SUFFIX = '.so' - library = library_dir + '/lib/' + 'libpython' + py_ver + SHLIB_SUFFIX + library = 'libpython' + py_ver + SHLIB_SUFFIX elif OS_name == "Darwin": SHLIB_SUFFIX = '.dylib' - library = library_dir + '/lib/' + 'libpython' + py_ver + SHLIB_SUFFIX + library = 'libpython' + py_ver + SHLIB_SUFFIX elif OS_name == "Windows": SHLIB_SUFFIX = '.dll' - library = library_dir + '\\' + 'python' + py_ver + SHLIB_SUFFIX + library = 'python' + py_ver + SHLIB_SUFFIX try: pylib = ctypes.CDLL(library) From 92dc854ed48c555b1fc7d382a2ca7acf3c795b66 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 8 Aug 2022 15:27:52 -0400 Subject: [PATCH 05/19] workaround for IBM's XLClang compiler --- src/fmt/format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fmt/format.h b/src/fmt/format.h index 0bd2fdb182..2a43b3d366 100644 --- a/src/fmt/format.h +++ b/src/fmt/format.h @@ -389,7 +389,8 @@ class uint128_fallback { hi_ += (lo_ < n ? 1 : 0); return *this; } -#if FMT_HAS_BUILTIN(__builtin_addcll) +// LAMMPS customization: XLCClang does not support __builtin_addcll() +#if FMT_HAS_BUILTIN(__builtin_addcll) && !(defined(__xlc__) && defined(__clang__)) unsigned long long carry; lo_ = __builtin_addcll(lo_, n, 0, &carry); hi_ += carry; From f7b0cb3bd4006b9536b2022838a42465ba260976 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 8 Aug 2022 15:31:45 -0400 Subject: [PATCH 06/19] AMOEBA induce bugfixes --- src/AMOEBA/amoeba_induce.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/AMOEBA/amoeba_induce.cpp b/src/AMOEBA/amoeba_induce.cpp index c1c2cb1d51..7434c57e27 100644 --- a/src/AMOEBA/amoeba_induce.cpp +++ b/src/AMOEBA/amoeba_induce.cpp @@ -369,7 +369,8 @@ void PairAmoeba::induce() eps = DEBYE * sqrt(eps/atom->natoms); if (eps < poleps) done = true; - if (eps > epsold) done = true; + // also commented out in induce.f of Tinker + // if (eps > epsold) done = true; if (iter >= politer) done = true; // apply a "peek" iteration to the mutual induced dipoles @@ -390,7 +391,7 @@ void PairAmoeba::induce() // terminate the calculation if dipoles failed to converge // NOTE: could make this an error - if (iter >= maxiter || eps > epsold) + if (iter >= politer || eps > epsold) if (comm->me == 0) error->warning(FLERR,"AMOEBA induced dipoles did not converge"); } From 7e0cad7d9e602b6b223b02e1b5ad0954ec3d84db Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 8 Aug 2022 15:40:19 -0400 Subject: [PATCH 07/19] import fix from upstream --- src/fmt/format.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/fmt/format.h b/src/fmt/format.h index 2a43b3d366..5483e00676 100644 --- a/src/fmt/format.h +++ b/src/fmt/format.h @@ -389,12 +389,11 @@ class uint128_fallback { hi_ += (lo_ < n ? 1 : 0); return *this; } -// LAMMPS customization: XLCClang does not support __builtin_addcll() -#if FMT_HAS_BUILTIN(__builtin_addcll) && !(defined(__xlc__) && defined(__clang__)) +#if FMT_HAS_BUILTIN(__builtin_addcll) && !defined(__ibmxl__) unsigned long long carry; lo_ = __builtin_addcll(lo_, n, 0, &carry); hi_ += carry; -#elif FMT_HAS_BUILTIN(__builtin_ia32_addcarryx_u64) +#elif FMT_HAS_BUILTIN(__builtin_ia32_addcarryx_u64) && !defined(__ibmxl__) unsigned long long result; auto carry = __builtin_ia32_addcarryx_u64(0, lo_, n, &result); lo_ = result; From d5170a1703dfa7b664034a738d8d9863fc445ac1 Mon Sep 17 00:00:00 2001 From: cjknight Date: Tue, 9 Aug 2022 17:35:22 +0000 Subject: [PATCH 08/19] one more env var for local rank --- src/KOKKOS/kokkos.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index cc53ff72e6..10e64f0bd6 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -160,6 +160,12 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) if (device >= skip_gpu) device++; set_flag = 1; } + if ((str = getenv("PMI_LOCAL_RANK"))) { + int local_rank = atoi(str); + device = local_rank % ngpus; + if (device >= skip_gpu) device++; + set_flag = 1; + } if (ngpus > 1 && !set_flag) error->all(FLERR,"Could not determine local MPI rank for multiple " From 247a2b12b3b805742043079354523ea7e0bc81ef Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Aug 2022 14:30:44 -0400 Subject: [PATCH 09/19] use utils::inumeric() instead of atoi() (not for parsing environment variables yet) --- src/KOKKOS/kokkos.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 10e64f0bd6..7e637788ec 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -116,7 +116,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) while (iarg < narg) { if (strcmp(arg[iarg],"d") == 0 || strcmp(arg[iarg],"device") == 0) { if (iarg+2 > narg) error->all(FLERR,"Invalid Kokkos command-line args"); - device = atoi(arg[iarg+1]); + device = utils::inumeric(FLERR, arg[iarg+1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg],"g") == 0 || @@ -125,11 +125,11 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) error->all(FLERR,"GPUs are requested but Kokkos has not been compiled using a GPU-enabled backend"); #endif if (iarg+2 > narg) error->all(FLERR,"Invalid Kokkos command-line args"); - ngpus = atoi(arg[iarg+1]); + ngpus = utils::inumeric(FLERR, arg[iarg+1], false, lmp); int skip_gpu = 9999; if (iarg+2 < narg && isdigit(arg[iarg+2][0])) { - skip_gpu = atoi(arg[iarg+2]); + skip_gpu = utils::inumeric(FLERR, arg[iarg+2], false, lmp); iarg++; } iarg += 2; @@ -173,7 +173,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) } else if (strcmp(arg[iarg],"t") == 0 || strcmp(arg[iarg],"threads") == 0) { - nthreads = atoi(arg[iarg+1]); + nthreads = utils::inumeric(FLERR, arg[iarg+1], false, lmp); if (nthreads <= 0) error->all(FLERR,"Invalid number of threads requested for Kokkos: must be 1 or greater"); @@ -182,19 +182,20 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) } else if (strcmp(arg[iarg],"n") == 0 || strcmp(arg[iarg],"numa") == 0) { - numa = atoi(arg[iarg+1]); + numa = utils::inumeric(FLERR, arg[iarg+1], false, lmp); iarg += 2; - } else error->all(FLERR,"Invalid Kokkos command-line args"); + } else error->all(FLERR,"Invalid Kokkos command-line arg: {}", arg[iarg]); } // Initialize Kokkos. However, we cannot change any // Kokkos library parameters after the first initalization if (args.num_threads != -1) { - if (args.num_threads != nthreads || args.num_numa != numa || args.device_id != device) + if ((args.num_threads != nthreads) || (args.num_numa != numa) || (args.device_id != device)) if (me == 0) - error->warning(FLERR,"Kokkos package already initalized, cannot reinitialize with different parameters"); + error->warning(FLERR,"Kokkos package already initalized, " + "cannot reinitialize with different parameters"); nthreads = args.num_threads; numa = args.num_numa; device = args.device_id; @@ -206,8 +207,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) init_ngpus = ngpus; } - if (me == 0) - utils::logmesg(lmp, " will use up to {} GPU(s) per node\n",ngpus); + if (me == 0) utils::logmesg(lmp, " will use up to {} GPU(s) per node\n", ngpus); #ifdef LMP_KOKKOS_GPU if (ngpus <= 0) From ba7507c9e5235d3e9007793c70b72cd124ca32dd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Aug 2022 14:47:58 -0400 Subject: [PATCH 10/19] small tweaks --- src/compute_pair_local.cpp | 2 +- src/reader_xyz.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compute_pair_local.cpp b/src/compute_pair_local.cpp index 708b31c370..3176bb667b 100644 --- a/src/compute_pair_local.cpp +++ b/src/compute_pair_local.cpp @@ -68,7 +68,7 @@ ComputePairLocal::ComputePairLocal(LAMMPS *lmp, int narg, char **arg) : pstyle[nvalues++] = DZ; else if (arg[iarg][0] == 'p') { int n = atoi(&arg[iarg][1]); - if (n <= 0) error->all(FLERR, "Invalid keyword in compute pair/local command"); + if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute pair/local command", arg[iarg]); pstyle[nvalues] = PN; pindex[nvalues++] = n - 1; diff --git a/src/reader_xyz.cpp b/src/reader_xyz.cpp index 1f379bc0dd..7add54fdb9 100644 --- a/src/reader_xyz.cpp +++ b/src/reader_xyz.cpp @@ -179,8 +179,7 @@ void ReaderXYZ::read_atoms(int n, int nfield, double **fields) ++nid; rv = sscanf(line,"%*s%lg%lg%lg", &myx, &myy, &myz); - if (rv != 3) - error->one(FLERR,"Dump file is incorrectly formatted"); + if (rv != 3) error->one(FLERR,"Dump file is incorrectly formatted"); // XXX: we could insert an element2type translation here // XXX: for now we flag unrecognized types as type 0, From 5c589dbe20aafdb3818b297884aadf7a8781ef1d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Aug 2022 15:52:47 -0400 Subject: [PATCH 11/19] add -nonbuf / -nb command line flag to disable buffering for screen and logfile --- doc/src/Run_options.rst | 18 ++++++++++++++++++ src/lammps.cpp | 18 +++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/doc/src/Run_options.rst b/doc/src/Run_options.rst index ceae464a59..cfeecb10f0 100644 --- a/doc/src/Run_options.rst +++ b/doc/src/Run_options.rst @@ -14,6 +14,7 @@ letter abbreviation can be used: * :ref:`-m or -mpicolor ` * :ref:`-c or -cite ` * :ref:`-nc or -nocite ` +* :ref:`-nb or -nonbuf ` * :ref:`-pk or -package ` * :ref:`-p or -partition ` * :ref:`-pl or -plog ` @@ -257,6 +258,23 @@ Disable generating a citation reminder (see above) at all. ---------- +.. _nonbuf: + +**-nonbuf** + +Turn off buffering for screen and logfile output. For performance +reasons, output to the screen and logfile is usually buffered, i.e. +output is only generated if a buffer - typically 4096 bytes - has been +filled. However, when LAMMPS crashes, that can mean that there is +important output missing. When using this flag, this buffering is +turned off (only for screen and logfile output). Note that when running +in parallel with MPI, the screen output may still be buffered by the MPI +library which cannot be changed by LAMMPS. This flag should only be +used for debugging and not for production simulations as the performance +impact can be significant, especially for large parallel runs. + +---------- + .. _package: **-package style args ....** diff --git a/src/lammps.cpp b/src/lammps.cpp index e78f9e2019..418a740808 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -196,6 +196,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : int citelogfile = CiteMe::VERBOSE; char *citefile = nullptr; int helpflag = 0; + int nonbufflag = 0; suffix = suffix2 = suffixp = nullptr; suffix_enable = 0; @@ -298,6 +299,11 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : citeflag = 0; iarg++; + } else if (strcmp(arg[iarg],"-nonbuf") == 0 || + strcmp(arg[iarg],"-nb") == 0) { + nonbufflag = 1; + iarg++; + } else if (strcmp(arg[iarg],"-package") == 0 || strcmp(arg[iarg],"-pk") == 0) { if (iarg+2 > narg) @@ -520,7 +526,6 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : utils::flush_buffers(this); } - // universe is one or more worlds, as setup by partition switch // split universe communicator into separate world communicators // set world screen, logfile, communicator, infile @@ -540,6 +545,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : screen = fopen(str.c_str(),"w"); if (screen == nullptr) error->one(FLERR,"Cannot open screen file {}: {}",str,utils::getsyserror()); + setvbuf(screen, NULL, _IONBF, 0); } else if (strcmp(arg[screenflag],"none") == 0) { screen = nullptr; } else { @@ -563,6 +569,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : logfile = fopen(str.c_str(),"w"); if (logfile == nullptr) error->one(FLERR,"Cannot open logfile {}: {}",str, utils::getsyserror()); + setbuf(logfile, NULL); } else if (strcmp(arg[logflag],"none") == 0) { logfile = nullptr; } else { @@ -587,6 +594,15 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : } } + // make all screen and logfile output unbuffered for debugging crashes + + if (nonbufflag) { + if (universe->uscreen) setbuf(universe->uscreen, nullptr); + if (universe->ulogfile) setbuf(universe->ulogfile, nullptr); + if (screen) setbuf(screen, nullptr); + if (logfile) setbuf(logfile, nullptr); + } + // screen and logfile messages for universe and world if ((universe->me == 0) && (!helpflag)) { From 111caac960fd1bf72dbe15e6921859586d4621a7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Aug 2022 16:11:09 -0400 Subject: [PATCH 12/19] remove references to Numeric module. we only support numpy. --- tools/python/pizza/dump.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/tools/python/pizza/dump.py b/tools/python/pizza/dump.py index 6224192093..bd93d8ee95 100644 --- a/tools/python/pizza/dump.py +++ b/tools/python/pizza/dump.py @@ -189,12 +189,7 @@ import sys, re, glob, types from os import popen from math import * # any function could be used by set() -try: - import numpy as np - oldnumeric = False -except: - import Numeric as np - oldnumeric = True +import numpy as np try: from DEFAULTS import PIZZA_GUNZIP except: PIZZA_GUNZIP = "gunzip" @@ -379,10 +374,7 @@ class dump: for i in range(1,snap.natoms): words += f.readline().decode().split() floats = map(float,words) - if oldnumeric: - atom_data = np.array(list(floats),np.Float) - else: - atom_data = np.array(list(floats),np.float) + atom_data = np.array(list(floats),np.float) snap.atoms = atom_data.reshape((snap.natoms, ncol)) else: @@ -858,8 +850,7 @@ class dump: self.map(ncol+1,str) for snap in self.snaps: atoms = snap.atoms - if oldnumeric: newatoms = np.zeros((snap.natoms,ncol+1),np.Float) - else: newatoms = np.zeros((snap.natoms,ncol+1),np.float) + newatoms = np.zeros((snap.natoms,ncol+1),np.float) newatoms[:,0:ncol] = snap.atoms snap.atoms = newatoms @@ -1018,8 +1009,7 @@ class dump: # convert values to int and absolute value since can be negative types - if oldnumeric: bondlist = np.zeros((nbonds,4),np.Int) - else: bondlist = np.zeros((nbonds,4),np.int) + bondlist = np.zeros((nbonds,4),np.int) ints = [abs(int(value)) for value in words] start = 0 stop = 4 From c8b6b052fcda48399041c5790ad9d6339d02fb6e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Aug 2022 16:51:00 -0400 Subject: [PATCH 13/19] port sorting by time to python 3 while retaining compatibility with 2.7 --- tools/python/pizza/dump.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/python/pizza/dump.py b/tools/python/pizza/dump.py index bd93d8ee95..01685cf582 100644 --- a/tools/python/pizza/dump.py +++ b/tools/python/pizza/dump.py @@ -194,6 +194,21 @@ import numpy as np try: from DEFAULTS import PIZZA_GUNZIP except: PIZZA_GUNZIP = "gunzip" +# -------------------------------------------------------------------- +# wrapper to convert old style comparision function to key function + +def cmp2key(oldcmp): + class keycmp: + def __init__(self, obj, *args): + self.obj = obj + def __lt__(self, other): + return oldcmp(self.obj,other.obj) < 0 + def __gt__(self, other): + return oldcmp(self.obj,other.obj) > 0 + def __eq__(self, other): + return oldcmp(self.obj,other.obj) == 0 + return keycmp + # Class definition class dump: @@ -255,7 +270,7 @@ class dump: # sort entries by timestep, cull duplicates - self.snaps.sort(self.compare_time) + self.snaps.sort(key=cmp2key(self.compare_time)) self.cull() self.nsnaps = len(self.snaps) print("read %d snapshots" % self.nsnaps) From 6eb51a68d9f047d9427d801e69bc24a0335702db Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Aug 2022 16:49:44 -0400 Subject: [PATCH 14/19] move dump command after reset_timestep to avoid crash --- examples/neb/in.neb.sivac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/neb/in.neb.sivac b/examples/neb/in.neb.sivac index 941d063b90..7a35174466 100644 --- a/examples/neb/in.neb.sivac +++ b/examples/neb/in.neb.sivac @@ -57,14 +57,14 @@ variable u uloop 20 # only output atoms near vacancy -#dump events vacneigh custom 1000 dump.neb.sivac.$u id type x y z # initial minimization to relax vacancy displace_atoms all random 0.1 0.1 0.1 123456 minimize 1.0e-6 1.0e-4 1000 10000 +reset_timestep 0 -reset_timestep 0 +#dump events vacneigh custom 1000 dump.neb.sivac.$u id type x y z fix 1 all neb 1.0 From 3a4a0078cdb7a4484dbb631a1dfdd8c2f3646885 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Aug 2022 16:50:16 -0400 Subject: [PATCH 15/19] whitespace --- examples/neb/in.neb.hop1 | 70 +++++++++++++++++----------------- examples/neb/in.neb.hop1.end | 60 ++++++++++++++--------------- examples/neb/in.neb.hop2 | 74 ++++++++++++++++++------------------ examples/neb/in.neb.sivac | 22 +++++------ 4 files changed, 113 insertions(+), 113 deletions(-) diff --git a/examples/neb/in.neb.hop1 b/examples/neb/in.neb.hop1 index f26b52a28a..54a22a5b87 100644 --- a/examples/neb/in.neb.hop1 +++ b/examples/neb/in.neb.hop1 @@ -1,66 +1,66 @@ # 2d NEB surface simulation, hop from surface to become adatom -dimension 2 -boundary p s p +dimension 2 +boundary p s p -atom_style atomic -neighbor 0.3 bin -neigh_modify delay 5 -atom_modify map array sort 0 0.0 +atom_style atomic +neighbor 0.3 bin +neigh_modify delay 5 +atom_modify map array sort 0 0.0 -variable u uloop 20 +variable u uloop 20 # create geometry with flat surface -lattice hex 0.9 -region box block 0 20 0 10 -0.25 0.25 +lattice hex 0.9 +region box block 0 20 0 10 -0.25 0.25 -#create_box 3 box -#create_atoms 1 box -#mass * 1.0 +#create_box 3 box +#create_atoms 1 box +#mass * 1.0 #write_data initial.hop1 read_data initial.hop1 # LJ potentials -pair_style lj/cut 2.5 -pair_coeff * * 1.0 1.0 2.5 -pair_modify shift yes +pair_style lj/cut 2.5 +pair_coeff * * 1.0 1.0 2.5 +pair_modify shift yes # initial minimization to relax surface -minimize 1.0e-6 1.0e-4 1000 10000 -reset_timestep 0 +minimize 1.0e-6 1.0e-4 1000 10000 +reset_timestep 0 # define groups -region 1 block INF INF INF 1.25 INF INF -group lower region 1 -group mobile subtract all lower -set group lower type 2 +region 1 block INF INF INF 1.25 INF INF +group lower region 1 +group mobile subtract all lower +set group lower type 2 -timestep 0.05 +timestep 0.05 # group of NEB atoms - either block or single atom ID 412 -region surround block 10 18 17 20 0 0 units box -group nebatoms region surround -#group nebatoms id 412 -set group nebatoms type 3 -group nonneb subtract all nebatoms +region surround block 10 18 17 20 0 0 units box +group nebatoms region surround +#group nebatoms id 412 +set group nebatoms type 3 +group nonneb subtract all nebatoms -fix 1 lower setforce 0.0 0.0 0.0 -fix 2 nebatoms neb 1.0 parallel ideal -fix 3 all enforce2d +fix 1 lower setforce 0.0 0.0 0.0 +fix 2 nebatoms neb 1.0 parallel ideal +fix 3 all enforce2d -thermo 100 +thermo 100 -#dump 1 nebatoms atom 10 dump.neb.$u -#dump 2 nonneb atom 10 dump.nonneb.$u +#dump 1 nebatoms atom 10 dump.neb.$u +#dump 2 nonneb atom 10 dump.nonneb.$u # run NEB for 2000 steps or to force tolerance -min_style quickmin +min_style quickmin -neb 0.0 0.1 1000 1000 100 final final.hop1 +neb 0.0 0.1 1000 1000 100 final final.hop1 diff --git a/examples/neb/in.neb.hop1.end b/examples/neb/in.neb.hop1.end index 81e5315306..c5e08b40f1 100644 --- a/examples/neb/in.neb.hop1.end +++ b/examples/neb/in.neb.hop1.end @@ -1,56 +1,56 @@ # 2d NEB surface simulation, hop from surface to become adatom -dimension 2 -boundary p s p +dimension 2 +boundary p s p -atom_style atomic -neighbor 0.3 bin -neigh_modify delay 5 -atom_modify map array sort 0 0.0 +atom_style atomic +neighbor 0.3 bin +neigh_modify delay 5 +atom_modify map array sort 0 0.0 -variable u uloop 20 +variable u uloop 20 # create geometry with flat surface -lattice hex 0.9 -region box block 0 20 0 10 -0.25 0.25 +lattice hex 0.9 +region box block 0 20 0 10 -0.25 0.25 read_data initial.hop1.end # LJ potentials -pair_style lj/cut 2.5 -pair_coeff * * 1.0 1.0 2.5 -pair_modify shift yes +pair_style lj/cut 2.5 +pair_coeff * * 1.0 1.0 2.5 +pair_modify shift yes # define groups -region 1 block INF INF INF 1.25 INF INF -group lower region 1 -group mobile subtract all lower -set group lower type 2 +region 1 block INF INF INF 1.25 INF INF +group lower region 1 +group mobile subtract all lower +set group lower type 2 -timestep 0.05 +timestep 0.05 # group of NEB atoms - either block or single atom ID 412 -region surround block 10 18 17 20 0 0 units box -group nebatoms region surround -#group nebatoms id 412 -set group nebatoms type 3 -group nonneb subtract all nebatoms +region surround block 10 18 17 20 0 0 units box +group nebatoms region surround +#group nebatoms id 412 +set group nebatoms type 3 +group nonneb subtract all nebatoms -fix 1 lower setforce 0.0 0.0 0.0 -fix 2 nebatoms neb 1.0 parallel ideal end first 1.0 -fix 3 all enforce2d +fix 1 lower setforce 0.0 0.0 0.0 +fix 2 nebatoms neb 1.0 parallel ideal end first 1.0 +fix 3 all enforce2d -thermo 100 +thermo 100 -#dump 1 nebatoms atom 10 dump.neb.$u -#dump 2 nonneb atom 10 dump.nonneb.$u +#dump 1 nebatoms atom 10 dump.neb.$u +#dump 2 nonneb atom 10 dump.nonneb.$u # run NEB for 2000 steps or to force tolerance -min_style quickmin +min_style quickmin -neb 0.0 0.1 1000 1000 100 final final.hop1 +neb 0.0 0.1 1000 1000 100 final final.hop1 diff --git a/examples/neb/in.neb.hop2 b/examples/neb/in.neb.hop2 index e69fb338cd..97512dbbf9 100644 --- a/examples/neb/in.neb.hop2 +++ b/examples/neb/in.neb.hop2 @@ -1,68 +1,68 @@ # 2d NEB surface simulation, hop of adatom on surface -dimension 2 -boundary p s p +dimension 2 +boundary p s p -atom_style atomic -neighbor 0.3 bin -neigh_modify delay 5 -atom_modify map array sort 0 0.0 +atom_style atomic +neighbor 0.3 bin +neigh_modify delay 5 +atom_modify map array sort 0 0.0 -variable u uloop 20 +variable u uloop 20 # create geometry with adatom -lattice hex 0.9 -region box block 0 20 0 11 -0.25 0.25 -region box1 block 0 20 0 10 -0.25 0.25 +lattice hex 0.9 +region box block 0 20 0 11 -0.25 0.25 +region box1 block 0 20 0 10 -0.25 0.25 -#create_box 3 box -#create_atoms 1 region box1 -#create_atoms 1 single 11.5 10.5 0 -#mass * 1.0 +#create_box 3 box +#create_atoms 1 region box1 +#create_atoms 1 single 11.5 10.5 0 +#mass * 1.0 #write_data initial.hop2 read_data initial.hop2 # LJ potentials -pair_style lj/cut 2.5 -pair_coeff * * 1.0 1.0 2.5 -pair_modify shift yes +pair_style lj/cut 2.5 +pair_coeff * * 1.0 1.0 2.5 +pair_modify shift yes # initial minimization to relax surface -minimize 1.0e-6 1.0e-4 1000 10000 -reset_timestep 0 +minimize 1.0e-6 1.0e-4 1000 10000 +reset_timestep 0 # define groups -region 1 block INF INF INF 1.25 INF INF -group lower region 1 -group mobile subtract all lower -set group lower type 2 +region 1 block INF INF INF 1.25 INF INF +group lower region 1 +group mobile subtract all lower +set group lower type 2 -timestep 0.05 +timestep 0.05 # group of NEB atoms - either block or single atom ID 421 -region surround block 10 18 17 21 0 0 units box -group nebatoms region surround -#group nebatoms id 421 -set group nebatoms type 3 -group nonneb subtract all nebatoms +region surround block 10 18 17 21 0 0 units box +group nebatoms region surround +#group nebatoms id 421 +set group nebatoms type 3 +group nonneb subtract all nebatoms -fix 1 lower setforce 0.0 0.0 0.0 -fix 2 nebatoms neb 1.0 -fix 3 all enforce2d +fix 1 lower setforce 0.0 0.0 0.0 +fix 2 nebatoms neb 1.0 +fix 3 all enforce2d -thermo 100 +thermo 100 -#dump 1 nebatoms atom 10 dump.neb.$u -#dump 2 nonneb atom 10 dump.nonneb.$u +#dump 1 nebatoms atom 10 dump.neb.$u +#dump 2 nonneb atom 10 dump.nonneb.$u # run NEB for 2000 steps or to force tolerance -min_style fire +min_style fire -neb 0.0 0.05 1000 1000 100 final final.hop2 +neb 0.0 0.05 1000 1000 100 final final.hop2 diff --git a/examples/neb/in.neb.sivac b/examples/neb/in.neb.sivac index 7a35174466..22492328c6 100644 --- a/examples/neb/in.neb.sivac +++ b/examples/neb/in.neb.sivac @@ -5,7 +5,7 @@ units metal atom_style atomic atom_modify map array boundary p p p -atom_modify sort 0 0.0 +atom_modify sort 0 0.0 # coordination number cutoff @@ -45,7 +45,7 @@ group Si type 1 group del id 300 delete_atoms group del compress no group vacneigh id 174 175 301 304 306 331 337 - + # choose potential pair_style sw @@ -53,26 +53,26 @@ pair_coeff * * Si.sw Si # set up neb run -variable u uloop 20 - -# only output atoms near vacancy - +variable u uloop 20 # initial minimization to relax vacancy displace_atoms all random 0.1 0.1 0.1 123456 -minimize 1.0e-6 1.0e-4 1000 10000 +minimize 1.0e-6 1.0e-4 1000 10000 + reset_timestep 0 +# only output atoms near vacancy + #dump events vacneigh custom 1000 dump.neb.sivac.$u id type x y z -fix 1 all neb 1.0 +fix 1 all neb 1.0 -thermo 100 +thermo 100 # run NEB for 2000 steps or to force tolerance timestep 0.01 -min_style quickmin +min_style quickmin -neb 0.0 0.01 100 100 10 final final.sivac +neb 0.0 0.01 100 100 10 final final.sivac From 631f33feb594f40eaed11d5c7eee613b4f0db88f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 10 Aug 2022 06:57:59 -0400 Subject: [PATCH 16/19] remove redundant calls --- src/lammps.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lammps.cpp b/src/lammps.cpp index 418a740808..b7318b9b55 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -545,7 +545,6 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : screen = fopen(str.c_str(),"w"); if (screen == nullptr) error->one(FLERR,"Cannot open screen file {}: {}",str,utils::getsyserror()); - setvbuf(screen, NULL, _IONBF, 0); } else if (strcmp(arg[screenflag],"none") == 0) { screen = nullptr; } else { @@ -569,7 +568,6 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : logfile = fopen(str.c_str(),"w"); if (logfile == nullptr) error->one(FLERR,"Cannot open logfile {}: {}",str, utils::getsyserror()); - setbuf(logfile, NULL); } else if (strcmp(arg[logflag],"none") == 0) { logfile = nullptr; } else { From e592f0f139e82012ad3b864f3a04e3c633401ce6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 10 Aug 2022 07:03:57 -0400 Subject: [PATCH 17/19] clarify the function of -nonbuf a bit more --- doc/src/Run_options.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/src/Run_options.rst b/doc/src/Run_options.rst index cfeecb10f0..d2d7f8c155 100644 --- a/doc/src/Run_options.rst +++ b/doc/src/Run_options.rst @@ -264,12 +264,13 @@ Disable generating a citation reminder (see above) at all. Turn off buffering for screen and logfile output. For performance reasons, output to the screen and logfile is usually buffered, i.e. -output is only generated if a buffer - typically 4096 bytes - has been -filled. However, when LAMMPS crashes, that can mean that there is -important output missing. When using this flag, this buffering is -turned off (only for screen and logfile output). Note that when running -in parallel with MPI, the screen output may still be buffered by the MPI -library which cannot be changed by LAMMPS. This flag should only be +output is only written to a file if its buffer - typically 4096 bytes - +has been filled. When LAMMPS crashes for some reason, however, that can +mean that there is important output missing. With this flag the +buffering can be turned off (only for screen and logfile output) and any +output will be committed immediately. Note that when running in +parallel with MPI, the screen output may still be buffered by the MPI +library and this cannot be changed by LAMMPS. This flag should only be used for debugging and not for production simulations as the performance impact can be significant, especially for large parallel runs. From 15261aaa711783e3ac41ac98f5de020a3f0b0ae5 Mon Sep 17 00:00:00 2001 From: Karl Hammond Date: Wed, 10 Aug 2022 11:11:27 -0500 Subject: [PATCH 18/19] Fixed a bug (xz and yz reversed) in LAMMPS.F90 and changed mpif90 to mpifort in README for files in examples/COUPLE/fortran2 --- examples/COUPLE/fortran2/LAMMPS.F90 | 2 +- examples/COUPLE/fortran2/README | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/COUPLE/fortran2/LAMMPS.F90 b/examples/COUPLE/fortran2/LAMMPS.F90 index 251b56f48f..86e5a4ba2d 100644 --- a/examples/COUPLE/fortran2/LAMMPS.F90 +++ b/examples/COUPLE/fortran2/LAMMPS.F90 @@ -1105,7 +1105,7 @@ contains !! Wrapper functions local to this module {{{1 C_xy = xy C_xz = xz C_yz = yz - call lammps_actual_reset_box (ptr, C_boxlo, C_boxhi, C_xy, C_xz, C_yz) + call lammps_actual_reset_box (ptr, C_boxlo, C_boxhi, C_xy, C_yz, C_xz) end subroutine lammps_reset_box ! lammps_gather_atoms {{{2 diff --git a/examples/COUPLE/fortran2/README b/examples/COUPLE/fortran2/README index 0a7b862d86..3f88d60750 100644 --- a/examples/COUPLE/fortran2/README +++ b/examples/COUPLE/fortran2/README @@ -40,7 +40,7 @@ the dynamically-linkable library (liblammps_fortran.so). (2) Copy said library to your Fortran program's source directory or replace ${LAMMPS_LIB} with its full path in the instructions below. (3) Compile (but don't link!) LAMMPS.F90. Example: - mpif90 -c LAMMPS.f90 + mpifort -c LAMMPS.f90 OR gfortran -c LAMMPS.F90 NOTE: you may get a warning such as, @@ -72,8 +72,8 @@ the dynamically-linkable library (liblammps_fortran.so). were part of the usual LAMMPS library interface (if you have the module file visible to the compiler, that is). (6) Compile (but don't link) your Fortran program. Example: - mpif90 -c myfreeformatfile.f90 - mpif90 -c myfixedformatfile.f + mpifort -c myfreeformatfile.f90 + mpifort -c myfixedformatfile.f OR gfortran -c myfreeformatfile.f90 gfortran -c myfixedformatfile.f @@ -83,12 +83,12 @@ the dynamically-linkable library (liblammps_fortran.so). IMPORTANT: If the Fortran module from part (3) is not in the current directory or in one searched by the compiler for module files, you will need to include that location via the -I flag to the compiler, like so: - mpif90 -I${LAMMPS_SRC}/examples/COUPLE/fortran2 -c myfreeformatfile.f90 + mpifort -I${LAMMPS_SRC}/examples/COUPLE/fortran2 -c myfreeformatfile.f90 (7) Link everything together, including any libraries needed by LAMMPS (such as the C++ standard library, the C math library, the JPEG library, fftw, etc.) For example, - mpif90 LAMMPS.o LAMMPS-wrapper.o ${my_object_files} \ + mpifort LAMMPS.o LAMMPS-wrapper.o ${my_object_files} \ ${LAMMPS_LIB} -lmpi_cxx -lstdc++ -lm OR gfortran LAMMPS.o LAMMPS-wrapper.o ${my_object_files} \ @@ -105,17 +105,17 @@ You should now have a working executable. (1) Compile LAMMPS as a dynamic library (make makeshlib && make -f Makefile.shlib [targetname]). (2) Compile, but don't link, LAMMPS.F90 using the -fPIC flag, such as - mpif90 -fPIC -c LAMMPS.f90 + mpifort -fPIC -c LAMMPS.f90 (3) Compile, but don't link, LAMMPS-wrapper.cpp in the same manner, e.g. mpicxx -fPIC -c LAMMPS-wrapper.cpp (4) Make the dynamic library, like so: - mpif90 -fPIC -shared -o liblammps_fortran.so LAMMPS.o LAMMPS-wrapper.o + mpifort -fPIC -shared -o liblammps_fortran.so LAMMPS.o LAMMPS-wrapper.o (5) Compile your program, such as, - mpif90 -I${LAMMPS_SRC}/examples/COUPLE/fortran2 -c myfreeformatfile.f90 + mpifort -I${LAMMPS_SRC}/examples/COUPLE/fortran2 -c myfreeformatfile.f90 where ${LAMMPS_SRC}/examples/COUPLE/fortran2 contains the .mod file from step (3) (6) Link everything together, such as - mpif90 ${my_object_files} -L${LAMMPS_SRC} \ + mpifort ${my_object_files} -L${LAMMPS_SRC} \ -L${LAMMPS_SRC}/examples/COUPLE/fortran2 -llammps_fortran \ -llammps_openmpi -lmpi_cxx -lstdc++ -lm From f1cca7d37d283095dbdd400ba0b749a65faa5565 Mon Sep 17 00:00:00 2001 From: Dionysios Sema <75517225+chemshift@users.noreply.github.com> Date: Wed, 10 Aug 2022 12:22:29 -0600 Subject: [PATCH 19/19] Update __init__.py --- python/lammps/mliap/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/lammps/mliap/__init__.py b/python/lammps/mliap/__init__.py index 02d876bf9d..cfe3fb6b38 100644 --- a/python/lammps/mliap/__init__.py +++ b/python/lammps/mliap/__init__.py @@ -21,8 +21,8 @@ elif OS_name == "Windows": try: pylib = ctypes.CDLL(library) -except: - OSError +except Exception as e: + raise OSError("Unable to locate python shared library") from e if not pylib.Py_IsInitialized(): raise RuntimeError("This interpreter is not compatible with python-based mliap for LAMMPS.")