From 222063e5cfc7f07cf1e28a21d3a5ad5de053121a Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Fri, 15 Oct 2021 17:32:37 -0600 Subject: [PATCH 01/18] Add preliminary support for Kokkos OpenMPTarget backend --- src/KOKKOS/kokkos.cpp | 10 +++++----- src/KOKKOS/kokkos.h | 10 +++++----- src/KOKKOS/kokkos_type.h | 15 ++++++++++++++- src/KOKKOS/npair_kokkos.cpp | 20 ++++++++++++-------- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 63a18ec387..e26513a122 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -44,7 +44,7 @@ #define GPU_AWARE_UNKNOWN static int have_gpu_aware = -1; // TODO HIP: implement HIP-aware MPI support (UCX) detection -#if defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) +#if defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) || defined(KOKKOS_ENABLE_OPENMPTARGET) GPU_AWARE_UNKNOWN #elif defined(KOKKOS_ENABLE_CUDA) @@ -121,7 +121,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) } else if (strcmp(arg[iarg],"g") == 0 || strcmp(arg[iarg],"gpus") == 0) { #ifndef LMP_KOKKOS_GPU - error->all(FLERR,"GPUs are requested but Kokkos has not been compiled for CUDA, HIP, or SYCL"); + 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]); @@ -162,7 +162,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) if (ngpus > 1 && !set_flag) error->all(FLERR,"Could not determine local MPI rank for multiple " - "GPUs with Kokkos CUDA, HIP, or SYCL because MPI library not recognized"); + "GPUs with Kokkos because MPI library not recognized"); } else if (strcmp(arg[iarg],"t") == 0 || strcmp(arg[iarg],"threads") == 0) { @@ -204,7 +204,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) #ifdef LMP_KOKKOS_GPU if (ngpus <= 0) - error->all(FLERR,"Kokkos has been compiled for CUDA, HIP, or SYCL but no GPUs are requested"); + error->all(FLERR,"Kokkos has been compiled with GPU-enabled backend but no GPUs are requested"); #endif #ifndef KOKKOS_ENABLE_SERIAL @@ -311,7 +311,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) error->warning(FLERR,"Detected MPICH. Disabling GPU-aware MPI"); #else if (me == 0) - error->warning(FLERR,"Kokkos with CUDA, HIP, or SYCL assumes CUDA-aware MPI is available," + error->warning(FLERR,"Kokkos with GPU-enabled backend assumes GPU-aware MPI is available," " but cannot determine if this is the case\n try" " '-pk kokkos gpu/aware off' if getting segmentation faults"); diff --git a/src/KOKKOS/kokkos.h b/src/KOKKOS/kokkos.h index fa5ff42a44..af35d95b9e 100644 --- a/src/KOKKOS/kokkos.h +++ b/src/KOKKOS/kokkos.h @@ -87,7 +87,7 @@ E: Invalid Kokkos command-line args Self-explanatory. See Section 2.7 of the manual for details. -E: Could not determine local MPI rank for multiple GPUs with Kokkos CUDA +E: Could not determine local MPI rank for multiple GPUs with Kokkos because MPI library not recognized The local MPI rank was not found in one of four supported environment variables. @@ -96,13 +96,13 @@ E: Invalid number of threads requested for Kokkos: must be 1 or greater Self-explanatory. -E: GPUs are requested but Kokkos has not been compiled for CUDA +E: GPUs are requested but Kokkos has not been compiled using GPU-enabled backend -Recompile Kokkos with CUDA support to use GPUs. +Recompile Kokkos with GPU-enabled backend to use GPUs. -E: Kokkos has been compiled for CUDA, HIP, or SYCL but no GPUs are requested +E: Kokkos has been compiled with GPU-enabled backend but no GPUs are requested -One or more GPUs must be used when Kokkos is compiled for CUDA/HIP/SYCL. +One or more GPUs must be used when Kokkos is compiled for CUDA/HIP/SYCL/OpenMPTarget. W: Kokkos package already initalized, cannot reinitialize with different parameters diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index cd829ec3e4..248435ba03 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -34,7 +34,7 @@ constexpr int HALF = 4; #define ISFINITE(x) std::isfinite(x) #endif -#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) || defined(KOKKOS_ENABLE_OPENMPTARGET) #define LMP_KOKKOS_GPU #endif @@ -222,6 +222,10 @@ struct ExecutionSpaceFromDevice { template<> struct ExecutionSpaceFromDevice { static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Device; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) +template<> +struct ExecutionSpaceFromDevice { + static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Device; }; #endif @@ -232,6 +236,8 @@ typedef Kokkos::CudaHostPinnedSpace LMPPinnedHostType; typedef Kokkos::Experimental::HIPHostPinnedSpace LMPPinnedHostType; #elif defined(KOKKOS_ENABLE_SYCL) typedef Kokkos::Experimental::SYCLSharedUSMSpace LMPPinnedHostType; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) +typedef Kokkos::Serial LMPPinnedHostType; #endif // create simple LMPDeviceSpace typedef for non CUDA-, HIP-, or SYCL-specific @@ -242,6 +248,8 @@ typedef Kokkos::Cuda LMPDeviceSpace; typedef Kokkos::Experimental::HIP LMPDeviceSpace; #elif defined(KOKKOS_ENABLE_SYCL) typedef Kokkos::Experimental::SYCL LMPDeviceSpace; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) +typedef Kokkos::Experimental::OpenMPTarget LMPDeviceSpace; #endif @@ -280,6 +288,11 @@ template<> struct AtomicDup { using value = Kokkos::Experimental::ScatterAtomic; }; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) +template<> +struct AtomicDup { + using value = Kokkos::Experimental::ScatterAtomic; +}; #endif #ifdef LMP_KOKKOS_USE_ATOMICS diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index 1110aef4a6..2ca16e7a60 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -240,7 +240,7 @@ void NPairKokkos::build(NeighList *list_) if (newton_pair) { if (SIZE) { NPairKokkosBuildFunctorSize f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); -#ifdef LMP_KOKKOS_GPU +#if defined(LMP_KOKKOS_GPU) && !defined(KOKKOS_ENABLE_OPENMPTARGET) if (ExecutionSpaceFromDevice::space == Device) { int team_size = atoms_per_bin*factor; int team_size_max = Kokkos::TeamPolicy(team_size,Kokkos::AUTO).team_size_max(f,Kokkos::ParallelForTag()); @@ -258,7 +258,7 @@ void NPairKokkos::build(NeighList *list_) #endif } else { NPairKokkosBuildFunctor f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); -#ifdef LMP_KOKKOS_GPU +#if defined(LMP_KOKKOS_GPU) && !defined(KOKKOS_ENABLE_OPENMPTARGET) if (ExecutionSpaceFromDevice::space == Device) { int team_size = atoms_per_bin*factor; int team_size_max = Kokkos::TeamPolicy(team_size,Kokkos::AUTO).team_size_max(f,Kokkos::ParallelForTag()); @@ -278,7 +278,7 @@ void NPairKokkos::build(NeighList *list_) } else { if (SIZE) { NPairKokkosBuildFunctorSize f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); -#ifdef LMP_KOKKOS_GPU +#if defined(LMP_KOKKOS_GPU) && !defined(KOKKOS_ENABLE_OPENMPTARGET) if (ExecutionSpaceFromDevice::space == Device) { int team_size = atoms_per_bin*factor; int team_size_max = Kokkos::TeamPolicy(team_size,Kokkos::AUTO).team_size_max(f,Kokkos::ParallelForTag()); @@ -296,7 +296,7 @@ void NPairKokkos::build(NeighList *list_) #endif } else { NPairKokkosBuildFunctor f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); -#ifdef LMP_KOKKOS_GPU +#if defined(LMP_KOKKOS_GPU) && !defined(KOKKOS_ENABLE_OPENMPTARGET) if (ExecutionSpaceFromDevice::space == Device) { int team_size = atoms_per_bin*factor; int team_size_max = Kokkos::TeamPolicy(team_size,Kokkos::AUTO).team_size_max(f,Kokkos::ParallelForTag()); @@ -605,14 +605,16 @@ void NeighborKokkosExecute::build_ItemGPU(typename Kokkos::TeamPolic other_x[MY_II + 3 * atoms_per_bin] = itype; } other_id[MY_II] = i; -#ifndef KOKKOS_ENABLE_SYCL +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); if (test) return; -#else +#elif defined(KOKKOS_ENABLE_SYCL) int not_done = (i >= 0 && i <= nlocal); dev.team_reduce(Kokkos::Max(not_done)); if(not_done == 0) return; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) + dev.team_barrier(); #endif if (i >= 0 && i < nlocal) { @@ -1055,14 +1057,16 @@ void NeighborKokkosExecute::build_ItemSizeGPU(typename Kokkos::TeamP other_x[MY_II + 4 * atoms_per_bin] = radi; } other_id[MY_II] = i; -#ifndef KOKKOS_ENABLE_SYCL +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); if (test) return; -#else +#elif defined(KOKKOS_ENABLE_SYCL) int not_done = (i >= 0 && i <= nlocal); dev.team_reduce(Kokkos::Max(not_done)); if(not_done == 0) return; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) + dev.team_barrier(); #endif if (i >= 0 && i < nlocal) { From ede188652b357cbe2172f9641a3a7844491004b4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 21 Oct 2021 07:33:00 -0400 Subject: [PATCH 02/18] update a few GPU kernels so they can be compiled on GPUs without double precisions support --- lib/gpu/lal_atom.cu | 2 +- lib/gpu/lal_atom.h | 2 +- lib/gpu/lal_zbl.cu | 12 ++++++------ lib/gpu/lal_zbl.h | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/gpu/lal_atom.cu b/lib/gpu/lal_atom.cu index 1418459301..287d72803c 100644 --- a/lib/gpu/lal_atom.cu +++ b/lib/gpu/lal_atom.cu @@ -18,7 +18,7 @@ #endif __kernel void kernel_cast_x(__global numtyp4 *restrict x_type, - const __global double *restrict x, + const __global numtyp *restrict x, const __global int *restrict type, const int nall) { int ii=GLOBAL_ID_X; diff --git a/lib/gpu/lal_atom.h b/lib/gpu/lal_atom.h index 3cf97d94a0..77c1faa784 100644 --- a/lib/gpu/lal_atom.h +++ b/lib/gpu/lal_atom.h @@ -475,7 +475,7 @@ class Atom { UCL_Vector v; #ifdef GPU_CAST - UCL_Vector x_cast; + UCL_Vector x_cast; UCL_Vector type_cast; #endif diff --git a/lib/gpu/lal_zbl.cu b/lib/gpu/lal_zbl.cu index 09e1b4f6bb..2a7d4795da 100644 --- a/lib/gpu/lal_zbl.cu +++ b/lib/gpu/lal_zbl.cu @@ -82,9 +82,9 @@ __kernel void k_zbl(const __global numtyp4 *restrict x_, const __global numtyp4 *restrict coeff1, const __global numtyp4 *restrict coeff2, const __global numtyp4 *restrict coeff3, - const double cut_globalsq, - const double cut_innersq, - const double cut_inner, + const numtyp cut_globalsq, + const numtyp cut_innersq, + const numtyp cut_inner, const int lj_types, const __global int *dev_nbor, const __global int *dev_packed, @@ -174,9 +174,9 @@ __kernel void k_zbl_fast(const __global numtyp4 *restrict x_, const __global numtyp4 *restrict coeff1_in, const __global numtyp4 *restrict coeff2_in, const __global numtyp4 *restrict coeff3_in, - const double cut_globalsq, - const double cut_innersq, - const double cut_inner, + const numtyp cut_globalsq, + const numtyp cut_innersq, + const numtyp cut_inner, const __global int *dev_nbor, const __global int *dev_packed, __global acctyp4 *restrict ans, diff --git a/lib/gpu/lal_zbl.h b/lib/gpu/lal_zbl.h index af4f1b2eac..b7b525661c 100644 --- a/lib/gpu/lal_zbl.h +++ b/lib/gpu/lal_zbl.h @@ -67,9 +67,9 @@ class ZBL : public BaseAtomic { /// If atom type constants fit in shared memory, use fast kernels bool shared_types; - double _cut_globalsq; - double _cut_innersq; - double _cut_inner; + numtyp _cut_globalsq; + numtyp _cut_innersq; + numtyp _cut_inner; /// Number of atom types int _lj_types; From 614b751f5f52fa6f731acde3fd7c5d896e64cdfe Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 22 Oct 2021 16:09:46 +0000 Subject: [PATCH 03/18] Add missing brace --- src/KOKKOS/kokkos_type.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index 248435ba03..15af1397bd 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -222,6 +222,7 @@ struct ExecutionSpaceFromDevice { template<> struct ExecutionSpaceFromDevice { static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Device; +}; #elif defined(KOKKOS_ENABLE_OPENMPTARGET) template<> struct ExecutionSpaceFromDevice { From 3cce6b46e20f3ef4602554337f0e8d67a5771bb4 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 22 Oct 2021 16:20:37 +0000 Subject: [PATCH 04/18] Fix thread divergence issue when not using CUDA/HIP --- src/KOKKOS/npair_kokkos.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index 2ca16e7a60..42ecedd78a 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -226,7 +226,8 @@ void NPairKokkos::build(NeighList *list_) data.h_resize() = 0; Kokkos::deep_copy(d_scalars, h_scalars); -#ifdef LMP_KOKKOS_GPU + +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) #define BINS_PER_BLOCK 2 const int factor = atoms_per_bin<64?2:1; #else @@ -240,7 +241,7 @@ void NPairKokkos::build(NeighList *list_) if (newton_pair) { if (SIZE) { NPairKokkosBuildFunctorSize f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); -#if defined(LMP_KOKKOS_GPU) && !defined(KOKKOS_ENABLE_OPENMPTARGET) +#ifdef LMP_KOKKOS_GPU if (ExecutionSpaceFromDevice::space == Device) { int team_size = atoms_per_bin*factor; int team_size_max = Kokkos::TeamPolicy(team_size,Kokkos::AUTO).team_size_max(f,Kokkos::ParallelForTag()); @@ -258,7 +259,7 @@ void NPairKokkos::build(NeighList *list_) #endif } else { NPairKokkosBuildFunctor f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); -#if defined(LMP_KOKKOS_GPU) && !defined(KOKKOS_ENABLE_OPENMPTARGET) +#ifdef LMP_KOKKOS_GPU if (ExecutionSpaceFromDevice::space == Device) { int team_size = atoms_per_bin*factor; int team_size_max = Kokkos::TeamPolicy(team_size,Kokkos::AUTO).team_size_max(f,Kokkos::ParallelForTag()); @@ -278,7 +279,7 @@ void NPairKokkos::build(NeighList *list_) } else { if (SIZE) { NPairKokkosBuildFunctorSize f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); -#if defined(LMP_KOKKOS_GPU) && !defined(KOKKOS_ENABLE_OPENMPTARGET) +#ifdef LMP_KOKKOS_GPU if (ExecutionSpaceFromDevice::space == Device) { int team_size = atoms_per_bin*factor; int team_size_max = Kokkos::TeamPolicy(team_size,Kokkos::AUTO).team_size_max(f,Kokkos::ParallelForTag()); @@ -296,7 +297,7 @@ void NPairKokkos::build(NeighList *list_) #endif } else { NPairKokkosBuildFunctor f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); -#if defined(LMP_KOKKOS_GPU) && !defined(KOKKOS_ENABLE_OPENMPTARGET) +#ifdef LMP_KOKKOS_GPU if (ExecutionSpaceFromDevice::space == Device) { int team_size = atoms_per_bin*factor; int team_size_max = Kokkos::TeamPolicy(team_size,Kokkos::AUTO).team_size_max(f,Kokkos::ParallelForTag()); @@ -607,7 +608,6 @@ void NeighborKokkosExecute::build_ItemGPU(typename Kokkos::TeamPolic other_id[MY_II] = i; #if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); - if (test) return; #elif defined(KOKKOS_ENABLE_SYCL) int not_done = (i >= 0 && i <= nlocal); @@ -1059,7 +1059,6 @@ void NeighborKokkosExecute::build_ItemSizeGPU(typename Kokkos::TeamP other_id[MY_II] = i; #if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); - if (test) return; #elif defined(KOKKOS_ENABLE_SYCL) int not_done = (i >= 0 && i <= nlocal); From 0901540fdadc2242566c01daa2aa006cf04c5936 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 22 Oct 2021 16:41:26 +0000 Subject: [PATCH 05/18] Remove deprecated Kokkos code --- src/KOKKOS/kokkos_type.h | 2 +- src/KOKKOS/verlet_kokkos.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index 15af1397bd..4c0dea819c 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/KOKKOS/verlet_kokkos.cpp b/src/KOKKOS/verlet_kokkos.cpp index 5e9ab757c6..14540c9ace 100644 --- a/src/KOKKOS/verlet_kokkos.cpp +++ b/src/KOKKOS/verlet_kokkos.cpp @@ -283,7 +283,7 @@ void VerletKokkos::run(int n) atomKK->sync(Device,ALL_MASK); //static double time = 0.0; - //Kokkos::Impl::Timer ktimer; + //Kokkos::Timer ktimer; timer->init_timeout(); for (int i = 0; i < n; i++) { @@ -445,7 +445,7 @@ void VerletKokkos::run(int n) if (pair_compute_flag) { atomKK->sync(force->pair->execution_space,force->pair->datamask_read); atomKK->sync(force->pair->execution_space,~(~force->pair->datamask_read|(F_MASK | ENERGY_MASK | VIRIAL_MASK))); - Kokkos::Impl::Timer ktimer; + Kokkos::Timer ktimer; force->pair->compute(eflag,vflag); atomKK->modified(force->pair->execution_space,force->pair->datamask_modify); atomKK->modified(force->pair->execution_space,~(~force->pair->datamask_modify|(F_MASK | ENERGY_MASK | VIRIAL_MASK))); From 7960a2d7d2c51cb80c5db30ad22f66ea6fd08067 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 22 Oct 2021 19:13:31 +0000 Subject: [PATCH 06/18] Fix link error with fix_acks2_reaxff_kokkos --- src/KOKKOS/fix_acks2_reaxff_kokkos.cpp | 2 +- src/KOKKOS/fix_acks2_reaxff_kokkos.h | 4 ++-- src/KOKKOS/fix_qeq_reaxff_kokkos.h | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp index 63fb1e7a53..8379dc8f46 100644 --- a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp +++ b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp @@ -1966,7 +1966,7 @@ void FixACKS2ReaxFFKokkos::get_chi_field() namespace LAMMPS_NS { template class FixACKS2ReaxFFKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixACKS2ReaxFFKokkos; #endif } diff --git a/src/KOKKOS/fix_acks2_reaxff_kokkos.h b/src/KOKKOS/fix_acks2_reaxff_kokkos.h index 67c737498f..bce90e97a3 100644 --- a/src/KOKKOS/fix_acks2_reaxff_kokkos.h +++ b/src/KOKKOS/fix_acks2_reaxff_kokkos.h @@ -299,7 +299,7 @@ struct FixACKS2ReaxFFKokkosComputeHFunctor { c.template compute_h_team(team, atoms_per_team, vector_length); } - size_t team_shmem_size(int team_size) const { + size_t team_shmem_size(int /*team_size*/) const { size_t shmem_size = Kokkos::View::shmem_size( atoms_per_team) + // s_ilist @@ -347,7 +347,7 @@ struct FixACKS2ReaxFFKokkosComputeXFunctor { c.template compute_x_team(team, atoms_per_team, vector_length); } - size_t team_shmem_size(int team_size) const { + size_t team_shmem_size(int /*team_size*/) const { size_t shmem_size = Kokkos::View::shmem_size( atoms_per_team) + // s_ilist diff --git a/src/KOKKOS/fix_qeq_reaxff_kokkos.h b/src/KOKKOS/fix_qeq_reaxff_kokkos.h index 3256e56aef..fc4f4bafd5 100644 --- a/src/KOKKOS/fix_qeq_reaxff_kokkos.h +++ b/src/KOKKOS/fix_qeq_reaxff_kokkos.h @@ -30,7 +30,6 @@ FixStyle(qeq/reax/kk/host,FixQEqReaxFFKokkos); #include "kokkos_type.h" #include "neigh_list.h" #include "neigh_list_kokkos.h" -#include "kokkos_base.h" namespace LAMMPS_NS { @@ -42,7 +41,7 @@ struct TagFixQEqReaxFFPackForwardComm {}; struct TagFixQEqReaxFFUnpackForwardComm {}; template -class FixQEqReaxFFKokkos : public FixQEqReaxFF, public KokkosBase { +class FixQEqReaxFFKokkos : public FixQEqReaxFF { public: typedef DeviceType device_type; typedef ArrayTypes AT; From c08093f768e6b92c386fa13854c3f40b01bec311 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 22 Oct 2021 16:00:01 -0400 Subject: [PATCH 07/18] modernize, avoid static buffers, use utility functions, remove debug code --- src/MANIFOLD/fix_nve_manifold_rattle.cpp | 14 ++-- src/MANIFOLD/fix_nvt_manifold_rattle.cpp | 28 +++----- src/MANIFOLD/manifold_gaussian_bump.cpp | 34 +-------- src/MANIFOLD/manifold_gaussian_bump.h | 2 - src/MANIFOLD/manifold_thylakoid.cpp | 88 +++++------------------- src/MANIFOLD/manifold_thylakoid.h | 1 - 6 files changed, 35 insertions(+), 132 deletions(-) diff --git a/src/MANIFOLD/fix_nve_manifold_rattle.cpp b/src/MANIFOLD/fix_nve_manifold_rattle.cpp index b4644a1350..1f0cc95b94 100644 --- a/src/MANIFOLD/fix_nve_manifold_rattle.cpp +++ b/src/MANIFOLD/fix_nve_manifold_rattle.cpp @@ -140,10 +140,8 @@ FixNVEManifoldRattle::FixNVEManifoldRattle( LAMMPS *lmp, int &narg, char **arg, if (strcmp(arg[argi], "every") == 0) { nevery = utils::inumeric(FLERR,arg[argi+1],false,lmp); next_output = update->ntimestep + nevery; - if (comm->me == 0) { - fprintf(screen,"Outputting every %d steps, next is %d\n", - nevery, next_output); - } + if (comm->me == 0) + utils::logmesg(lmp,"Outputting every {} steps, next is {}\n",nevery, next_output); argi += 2; } else if (error_on_unknown_keyword) { error->all(FLERR,"Error parsing arg \"{}\".\n",arg[argi]); @@ -211,11 +209,9 @@ void FixNVEManifoldRattle::print_stats( const char *header ) double inv_tdiff = 1.0/( static_cast(ntimestep) - stats.last_out ); stats.last_out = ntimestep; - fprintf(screen, "%s stats for time step " BIGINT_FORMAT " on %d atoms:\n", - header, ntimestep, stats.natoms); - fprintf(screen, " iters/atom: x = %f, v = %f, dofs removed %d", - x_iters * inv_tdiff, v_iters * inv_tdiff, stats.dofs_removed); - fprintf(screen,"\n"); + utils::logmesg(lmp, "{} stats for time step {} on {} atoms:\n", header, ntimestep, stats.natoms); + utils::logmesg(lmp, " iters/atom: x = {}, v = {}, dofs removed = {}\n", + x_iters * inv_tdiff, v_iters * inv_tdiff, stats.dofs_removed); } stats.x_iters_per_atom = 0; diff --git a/src/MANIFOLD/fix_nvt_manifold_rattle.cpp b/src/MANIFOLD/fix_nvt_manifold_rattle.cpp index f675cdff73..0dcc233b54 100644 --- a/src/MANIFOLD/fix_nvt_manifold_rattle.cpp +++ b/src/MANIFOLD/fix_nvt_manifold_rattle.cpp @@ -32,21 +32,21 @@ ------------------------------------------------------------------------- */ - #include "fix_nvt_manifold_rattle.h" -#include -#include + #include "atom.h" -#include "force.h" -#include "update.h" -#include "error.h" -#include "group.h" #include "citeme.h" -#include "modify.h" #include "compute.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "modify.h" +#include "update.h" #include "manifold.h" +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -115,9 +115,7 @@ FixNVTManifoldRattle::FixNVTManifoldRattle(LAMMPS *lmp, int narg, char **arg, mtchain = utils::inumeric(FLERR, arg[argi+1],false,lmp); argi += 2; } else if (error_on_unknown_keyword) { - char msg[2048]; - sprintf(msg,"Error parsing arg \"%s\".\n", arg[argi]); - error->all(FLERR, msg); + error->all(FLERR, "Error parsing arg \"{}\".\n", arg[argi]); } else { argi += 1; } @@ -271,12 +269,8 @@ void FixNVTManifoldRattle::nhc_temp_integrate() factor_eta = exp(-dthalf*eta_dot[0]); - if (factor_eta == 0) { - char msg[2048]; - sprintf(msg, "WTF, factor_eta is 0! dthalf = %f, eta_dot[0] = %f", - dthalf, eta_dot[0]); - error->all(FLERR,msg); - } + if (factor_eta == 0) + error->all(FLERR, "factor_eta is 0! dthalf = {}, eta_dot[0] = {}", dthalf, eta_dot[0]); nh_v_temp(); diff --git a/src/MANIFOLD/manifold_gaussian_bump.cpp b/src/MANIFOLD/manifold_gaussian_bump.cpp index 5eb2b08504..1483ff7489 100644 --- a/src/MANIFOLD/manifold_gaussian_bump.cpp +++ b/src/MANIFOLD/manifold_gaussian_bump.cpp @@ -67,9 +67,7 @@ public: double get_t_from_x( double xx ) const { if (xx < x0 || xx > x1) { - char msg[2048]; - sprintf(msg, "x ( %g ) out of bounds [%g, %g]", xx, x0, x1 ); - err->one(FLERR, msg); + err->one(FLERR,"x ( {} ) out of bounds [{}, {}]", xx, x0, x1 ); } // Newton iterate to get right t. @@ -271,8 +269,6 @@ void manifold_gaussian_bump::post_param_init() make_lut(); - - // test_lut(); } @@ -360,31 +356,3 @@ void manifold_gaussian_bump::lut_get_z_and_zp( double rr, double &zz, zz = zleft * fmin + zright * frac; zzp = zpleft * fmin + zpright * frac; } - - -void manifold_gaussian_bump::test_lut() -{ - double x[3], nn[3]; - if (comm->me != 0) return; - - FILE *fp = fopen( "test_lut_gaussian.dat", "w" ); - double dx = 0.1; - for (double xx = 0; xx < 20; xx += dx) { - x[0] = xx; - x[1] = 0.0; - x[2] = 0.0; - double gg = g( x ); - n( x, nn ); - double taper_z; - if (xx <= rc1) { - taper_z = gaussian_bump(xx); - } else if (xx < rc2) { - taper_z = lut_get_z( xx ); - } else { - taper_z = 0.0; - } - fprintf( fp, "%g %g %g %g %g %g %g\n", xx, gaussian_bump(xx), taper_z, - gg, nn[0], nn[1], nn[2] ); - } - fclose(fp); -} diff --git a/src/MANIFOLD/manifold_gaussian_bump.h b/src/MANIFOLD/manifold_gaussian_bump.h index 8c72db080f..4671b189df 100644 --- a/src/MANIFOLD/manifold_gaussian_bump.h +++ b/src/MANIFOLD/manifold_gaussian_bump.h @@ -86,8 +86,6 @@ namespace user_manifold { double lut_get_zp(double rr) const; void lut_get_z_and_zp(double rr, double &zz, double &zzp) const; - void test_lut(); - double taper(double); double taper_der(double); }; diff --git a/src/MANIFOLD/manifold_thylakoid.cpp b/src/MANIFOLD/manifold_thylakoid.cpp index b7004cac3a..5ab90ce08e 100644 --- a/src/MANIFOLD/manifold_thylakoid.cpp +++ b/src/MANIFOLD/manifold_thylakoid.cpp @@ -34,8 +34,6 @@ manifold_thylakoid::manifold_thylakoid( LAMMPS *lmp, int /*narg*/, char ** /*arg // fix should call post_param_init(); } - - manifold_thylakoid::~manifold_thylakoid() { for (std::size_t i = 0; i < parts.size(); ++i) { @@ -43,8 +41,6 @@ manifold_thylakoid::~manifold_thylakoid() } } - - void manifold_thylakoid::post_param_init() { // Set coefficients: @@ -59,52 +55,21 @@ void manifold_thylakoid::post_param_init() LB = params[1]; lB = params[2]; - if (comm->me == 0) { - fprintf(screen,"My params are now: lT = %f, LT = %f, pad = %f, " - "wB = %f, LB = %f, lB = %f\n", lT, LT, pad, wB, LB, lB ); - fprintf(screen,"Calling init_domains() from post_param_init().\n"); - } init_domains(); - checkup(); } -void manifold_thylakoid::checkup() -{ - if (comm->me == 0) { - fprintf(screen,"This is checkup of thylakoid %p\n", this); - fprintf(screen,"I have %ld parts. They are:\n", parts.size()); - for (int i = 0; i < (int)parts.size(); ++i) { - fprintf(screen, "[%f, %f] x [%f, %f] x [%f, %f]\n", - parts[i]->xlo, parts[i]->xhi, - parts[i]->ylo, parts[i]->yhi, - parts[i]->zlo, parts[i]->zhi ); - } - fprintf(screen,"My params are:\n"); - for (int i = 0; i < NPARAMS; ++i) { - fprintf(screen,"%f\n", params[i]); - } - } -} - - double manifold_thylakoid::g( const double *x ) { int err = 0; std::size_t idx; thyla_part *p = get_thyla_part(x,&err,&idx); - if (err) { - char msg[2048]; - sprintf(msg,"Error getting thyla_part for x = (%f, %f, %f)",x[0],x[1],x[2]); - error->one(FLERR,msg); - } + if (err) error->one(FLERR,"Error getting thyla_part for x = ({}, {}, {})",x[0],x[1],x[2]); + double con_val = p->g(x); if (std::isfinite(con_val)) { return con_val; } else { - char msg[2048]; - sprintf(msg,"Error, thyla_part of type %d returned %f as constraint val!", - p->type, con_val); - error->one(FLERR,msg); + error->one(FLERR,"Error, thyla_part of type {} returned {} as constraint val!", p->type, con_val); return 0; } } @@ -114,20 +79,14 @@ void manifold_thylakoid::n( const double *x, double *n ) int err = 0; std::size_t idx; thyla_part *p = get_thyla_part(x,&err,&idx); - if (err) { - char msg[2048]; - sprintf(msg,"Error getting thyla_part for x = (%f, %f, %f)",x[0],x[1],x[2]); - error->one(FLERR,msg); - } + if (err) + error->one(FLERR,"Error getting thyla_part for x = ({}, {}, {})",x[0],x[1],x[2]); p->n(x,n); if (std::isfinite(n[0]) && std::isfinite(n[1]) && std::isfinite(n[2])) { return; - } else { - char msg[2048]; - sprintf(msg,"Error, thyla_part of type %d returned (%f,%f,%f) as gradient!", - p->type, n[0], n[1], n[2]); - error->one(FLERR,msg); - } + } else + error->one(FLERR,"thyla_part of type {} returned ({},{},{}) as gradient!", + p->type, n[0], n[1], n[2]); } thyla_part *manifold_thylakoid::get_thyla_part( const double *x, int * /*err_flag*/, std::size_t *idx ) @@ -140,9 +99,7 @@ thyla_part *manifold_thylakoid::get_thyla_part( const double *x, int * /*err_fla return p; } } - char msg[2048]; - sprintf(msg,"Could not find thyla_part for x = (%f,%f,%f)", x[0],x[1],x[2]); - error->one(FLERR,msg); + error->one(FLERR,"Could not find thyla_part for x = ({},{},{})", x[0],x[1],x[2]); return nullptr; } @@ -153,12 +110,9 @@ thyla_part *manifold_thylakoid::get_thyla_part( const double *x, int * /*err_fla void manifold_thylakoid::init_domains() { - if (wB + 2*lB > LT) { - char msg[2048]; - sprintf(msg,"LT = %f not large enough to accommodate bridge with " - "wB = %f and lB = %f! %f > %f\n", LT, wB, lB, wB + 2*lB, LT); - error->one(FLERR,msg); - } + if (wB + 2*lB > LT) + error->one(FLERR,"LT = {} not large enough to accommodate bridge with " + "wB = {} and lB = {}! {} > {}\n", LT, wB, lB, wB + 2*lB, LT); // Determine some constant coordinates: x0 = -( 0.5*LB + lB + lT + LT + lT + pad); @@ -375,12 +329,9 @@ void manifold_thylakoid::init_domains() parts.push_back(p); // Check if this plane lines up with bl: - if (fabs(plr.pt[0] - bl.pt[0] + lB) > 1e-8) { - char msg[2048]; - sprintf(msg,"Origins of plane left right and bridge left misaligned! %f != %f!\n", - plr.pt[0], bl.pt[0] - lB ); - error->one(FLERR,msg); - } + if (fabs(plr.pt[0] - bl.pt[0] + lB) > 1e-8) + error->one(FLERR,"Origins of plane left right and bridge left misaligned! {} != {}!\n", + plr.pt[0], bl.pt[0] - lB ); // Now, for the right stack, you can mirror the other... // To mirror them you need to invert lo[0] and hi[0] and flip their sign. @@ -428,12 +379,9 @@ void manifold_thylakoid::init_domains() set_domain(p, prr.lo, prr.hi); parts.push_back(p); - if (fabs(prr.pt[0] - br.pt[0] - lB) > 1e-8) { - char msg[2048]; - sprintf(msg,"Origins of plane left right and bridge left misaligned! %f != %f!\n", - prr.pt[0], br.pt[0] + lB); - error->one(FLERR,msg); - } + if (fabs(prr.pt[0] - br.pt[0] - lB) > 1e-8) + error->one(FLERR,"Origins of plane left right and bridge left misaligned! {} != {}!\n", + prr.pt[0], br.pt[0] + lB); } diff --git a/src/MANIFOLD/manifold_thylakoid.h b/src/MANIFOLD/manifold_thylakoid.h index 5470d722f9..0236c3bf54 100644 --- a/src/MANIFOLD/manifold_thylakoid.h +++ b/src/MANIFOLD/manifold_thylakoid.h @@ -37,7 +37,6 @@ namespace user_manifold { virtual int nparams() { return NPARAMS; } virtual void post_param_init(); - virtual void checkup(); // Some diagnostics... private: void init_domains(); From 47eab736bb96c9feffccdade870da7c0a2e98846 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 22 Oct 2021 16:14:06 -0400 Subject: [PATCH 08/18] use anonymous namespace to manage visibility of multiple copies of parse_error class --- src/EXTRA-FIX/fix_ttm.cpp | 12 ++++++++++++ src/EXTRA-FIX/fix_ttm.h | 8 -------- src/EXTRA-FIX/fix_ttm_grid.cpp | 12 ++++++++++++ src/EXTRA-FIX/fix_ttm_mod.cpp | 12 ++++++++++++ src/EXTRA-FIX/fix_ttm_mod.h | 8 -------- src/QEQ/fix_qeq.cpp | 14 ++++++++------ src/REAXFF/fix_acks2_reaxff.cpp | 14 ++++++++------ src/REAXFF/fix_qeq_reaxff.cpp | 14 ++++++++------ src/REAXFF/reaxff_control.cpp | 16 +++++++++------- src/REAXFF/reaxff_ffield.cpp | 6 ++++-- 10 files changed, 73 insertions(+), 43 deletions(-) diff --git a/src/EXTRA-FIX/fix_ttm.cpp b/src/EXTRA-FIX/fix_ttm.cpp index 13fbd4aff4..4c0d2e9cd5 100644 --- a/src/EXTRA-FIX/fix_ttm.cpp +++ b/src/EXTRA-FIX/fix_ttm.cpp @@ -46,6 +46,18 @@ using namespace FixConst; static constexpr int OFFSET = 16384; static constexpr double SHIFT = 0.0; +// helper class + +namespace { + class parser_error : public std::exception { + std::string message; + + public: + parser_error(const std::string &mesg) { message = mesg; } + const char *what() const noexcept { return message.c_str(); } + }; +} + /* ---------------------------------------------------------------------- */ FixTTM::FixTTM(LAMMPS *lmp, int narg, char **arg) : diff --git a/src/EXTRA-FIX/fix_ttm.h b/src/EXTRA-FIX/fix_ttm.h index 1a2e9fb24a..da782b1f5a 100644 --- a/src/EXTRA-FIX/fix_ttm.h +++ b/src/EXTRA-FIX/fix_ttm.h @@ -77,14 +77,6 @@ class FixTTM : public Fix { virtual void deallocate_grid(); virtual void read_electron_temperatures(const std::string &); virtual void write_electron_temperatures(const std::string &); - - class parser_error : public std::exception { - std::string message; - - public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } - }; }; } // namespace LAMMPS_NS diff --git a/src/EXTRA-FIX/fix_ttm_grid.cpp b/src/EXTRA-FIX/fix_ttm_grid.cpp index 7b3f434907..b42b876a3b 100644 --- a/src/EXTRA-FIX/fix_ttm_grid.cpp +++ b/src/EXTRA-FIX/fix_ttm_grid.cpp @@ -41,6 +41,18 @@ static constexpr int MAXLINE = 256; static constexpr int CHUNK = 1024; static constexpr int OFFSET = 16384; +// helper class + +namespace { + class parser_error : public std::exception { + std::string message; + + public: + parser_error(const std::string &mesg) { message = mesg; } + const char *what() const noexcept { return message.c_str(); } + }; +} + /* ---------------------------------------------------------------------- */ FixTTMGrid::FixTTMGrid(LAMMPS *lmp, int narg, char **arg) : diff --git a/src/EXTRA-FIX/fix_ttm_mod.cpp b/src/EXTRA-FIX/fix_ttm_mod.cpp index 0aef2ec4ff..d39d50c9e5 100644 --- a/src/EXTRA-FIX/fix_ttm_mod.cpp +++ b/src/EXTRA-FIX/fix_ttm_mod.cpp @@ -41,6 +41,18 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; +// helper class + +namespace { + class parser_error : public std::exception { + std::string message; + + public: + parser_error(const std::string &mesg) { message = mesg; } + const char *what() const noexcept { return message.c_str(); } + }; +} + // OFFSET avoids outside-of-box atoms being rounded to grid pts incorrectly // SHIFT = 0.0 assigns atoms to lower-left grid pt // SHIFT = 0.5 assigns atoms to nearest grid pt diff --git a/src/EXTRA-FIX/fix_ttm_mod.h b/src/EXTRA-FIX/fix_ttm_mod.h index f26f270e7a..21eb0efcaa 100644 --- a/src/EXTRA-FIX/fix_ttm_mod.h +++ b/src/EXTRA-FIX/fix_ttm_mod.h @@ -87,14 +87,6 @@ class FixTTMMod : public Fix { void read_parameters(const std::string &); void read_electron_temperatures(const std::string &); void write_electron_temperatures(const std::string &); - - class parser_error : public std::exception { - std::string message; - - public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } - }; }; } // namespace LAMMPS_NS diff --git a/src/QEQ/fix_qeq.cpp b/src/QEQ/fix_qeq.cpp index 79205f7c81..b43afb00d6 100644 --- a/src/QEQ/fix_qeq.cpp +++ b/src/QEQ/fix_qeq.cpp @@ -42,12 +42,14 @@ using namespace FixConst; #define MAXLINE 1024 -class parser_error : public std::exception { - std::string message; -public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } -}; +namespace { + class parser_error : public std::exception { + std::string message; + public: + parser_error(const std::string &mesg) { message = mesg; } + const char *what() const noexcept { return message.c_str(); } + }; +} /* ---------------------------------------------------------------------- */ diff --git a/src/REAXFF/fix_acks2_reaxff.cpp b/src/REAXFF/fix_acks2_reaxff.cpp index f19b31f9ed..ec14ed72b2 100644 --- a/src/REAXFF/fix_acks2_reaxff.cpp +++ b/src/REAXFF/fix_acks2_reaxff.cpp @@ -43,12 +43,14 @@ using namespace LAMMPS_NS; using namespace FixConst; -class parser_error : public std::exception { - std::string message; -public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } -}; +namespace { + class parser_error : public std::exception { + std::string message; + public: + parser_error(const std::string &mesg) { message = mesg; } + const char *what() const noexcept { return message.c_str(); } + }; +} static const char cite_fix_acks2_reax[] = "fix acks2/reaxff command:\n\n" diff --git a/src/REAXFF/fix_qeq_reaxff.cpp b/src/REAXFF/fix_qeq_reaxff.cpp index f0ba651a26..89ee3f338f 100644 --- a/src/REAXFF/fix_qeq_reaxff.cpp +++ b/src/REAXFF/fix_qeq_reaxff.cpp @@ -49,12 +49,14 @@ using namespace LAMMPS_NS; using namespace FixConst; -class parser_error : public std::exception { - std::string message; -public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } -}; +namespace { + class parser_error : public std::exception { + std::string message; + public: + parser_error(const std::string &mesg) { message = mesg; } + const char *what() const noexcept { return message.c_str(); } + }; +} static constexpr double EV_TO_KCAL_PER_MOL = 14.4; static constexpr double SMALL = 1.0e-14; diff --git a/src/REAXFF/reaxff_control.cpp b/src/REAXFF/reaxff_control.cpp index 2020e8a5c3..90f12b2031 100644 --- a/src/REAXFF/reaxff_control.cpp +++ b/src/REAXFF/reaxff_control.cpp @@ -40,6 +40,15 @@ using LAMMPS_NS::utils::sfgets; using LAMMPS_NS::utils::logmesg; using LAMMPS_NS::ValueTokenizer; +namespace { + class parser_error : public std::exception { + std::string message; + public: + parser_error(const std::string &mesg) { message = mesg; } + const char *what() const noexcept { return message.c_str(); } + }; +} + namespace ReaxFF { static std::unordered_set inactive_keywords = { "ensemble_type", "nsteps", "dt", "proc_by_dim", "random_vel", @@ -54,13 +63,6 @@ namespace ReaxFF { "energy_update_freq", "atom_info", "atom_velocities", "atom_forces", "bond_info", "angle_info" }; - class parser_error : public std::exception { - std::string message; - public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } - }; - // NOTE: this function is run on MPI rank 0 only void Read_Control_File(const char *control_file, control_params *control) diff --git a/src/REAXFF/reaxff_ffield.cpp b/src/REAXFF/reaxff_ffield.cpp index 605e077724..db4a63972e 100644 --- a/src/REAXFF/reaxff_ffield.cpp +++ b/src/REAXFF/reaxff_ffield.cpp @@ -41,14 +41,16 @@ using LAMMPS_NS::utils::open_potential; using LAMMPS_NS::utils::getsyserror; using LAMMPS_NS::utils::uppercase; -namespace ReaxFF { - +namespace { class parser_error : public std::exception { std::string message; public: parser_error(const std::string &mesg) { message = mesg; } const char *what() const noexcept { return message.c_str(); } }; +} + +namespace ReaxFF { void Read_Force_Field(const char *filename, reax_interaction *reax, control_params *control, MPI_Comm world) From 71a24580b8eadcff62d11c88630d4e173941dd19 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 23 Oct 2021 04:24:54 -0400 Subject: [PATCH 09/18] remove parser_error exception class ambiguity completely --- src/EXTRA-FIX/fix_ttm.cpp | 17 ++--------------- src/EXTRA-FIX/fix_ttm_grid.cpp | 16 ++-------------- src/EXTRA-FIX/fix_ttm_mod.cpp | 16 ++-------------- src/QEQ/fix_qeq.cpp | 12 ++++++------ src/REAXFF/fix_acks2_reaxff.cpp | 20 ++++++-------------- src/REAXFF/fix_qeq_reaxff.cpp | 17 +++++------------ src/REAXFF/reaxff_control.cpp | 23 +++++++++++------------ src/REAXFF/reaxff_ffield.cpp | 14 ++++++-------- src/tokenizer.h | 6 +++--- 9 files changed, 43 insertions(+), 98 deletions(-) diff --git a/src/EXTRA-FIX/fix_ttm.cpp b/src/EXTRA-FIX/fix_ttm.cpp index 4c0d2e9cd5..de4b0a4c7e 100644 --- a/src/EXTRA-FIX/fix_ttm.cpp +++ b/src/EXTRA-FIX/fix_ttm.cpp @@ -28,7 +28,6 @@ #include "random_mars.h" #include "respa.h" #include "potential_file_reader.h" -#include "tokenizer.h" #include "update.h" #include @@ -46,18 +45,6 @@ using namespace FixConst; static constexpr int OFFSET = 16384; static constexpr double SHIFT = 0.0; -// helper class - -namespace { - class parser_error : public std::exception { - std::string message; - - public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } - }; -} - /* ---------------------------------------------------------------------- */ FixTTM::FixTTM(LAMMPS *lmp, int narg, char **arg) : @@ -503,10 +490,10 @@ void FixTTM::read_electron_temperatures(const std::string &filename) // check correctness of input data if ((ix < 0) || (ix >= nxgrid) || (iy < 0) || (iy >= nygrid) || (iz < 0) || (iz >= nzgrid)) - throw parser_error("Fix ttm invalid grid index in fix ttm grid file"); + throw TokenizerException("Fix ttm invalid grid index in fix ttm grid file",""); if (T_tmp < 0.0) - throw parser_error("Fix ttm electron temperatures must be > 0.0"); + throw TokenizerException("Fix ttm electron temperatures must be > 0.0",""); T_electron[iz][iy][ix] = T_tmp; T_initial_set[iz][iy][ix] = 1; diff --git a/src/EXTRA-FIX/fix_ttm_grid.cpp b/src/EXTRA-FIX/fix_ttm_grid.cpp index b42b876a3b..8890750818 100644 --- a/src/EXTRA-FIX/fix_ttm_grid.cpp +++ b/src/EXTRA-FIX/fix_ttm_grid.cpp @@ -41,18 +41,6 @@ static constexpr int MAXLINE = 256; static constexpr int CHUNK = 1024; static constexpr int OFFSET = 16384; -// helper class - -namespace { - class parser_error : public std::exception { - std::string message; - - public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } - }; -} - /* ---------------------------------------------------------------------- */ FixTTMGrid::FixTTMGrid(LAMMPS *lmp, int narg, char **arg) : @@ -318,7 +306,7 @@ void FixTTMGrid::read_electron_temperatures(const std::string &filename) int iz = values.next_int(); if (ix < 0 || ix >= nxgrid || iy < 0 || iy >= nygrid || iz < 0 || iz >= nzgrid) - throw parser_error("Fix ttm/grid invalid grid index in input"); + throw TokenizerException("Fix ttm/grid invalid grid index in input",""); if (ix >= nxlo_in && ix <= nxhi_in && iy >= nylo_in && iy <= nyhi_in && iz >= nzlo_in && iz <= nzhi_in) { @@ -326,7 +314,7 @@ void FixTTMGrid::read_electron_temperatures(const std::string &filename) T_initial_set[iz][iy][ix] = 1; } } else { - throw parser_error("Incorrect format in fix ttm electron grid file"); + throw TokenizerException("Incorrect format in fix ttm electron grid file",""); } } catch (std::exception &e) { error->one(FLERR,e.what()); diff --git a/src/EXTRA-FIX/fix_ttm_mod.cpp b/src/EXTRA-FIX/fix_ttm_mod.cpp index d39d50c9e5..233f877e8c 100644 --- a/src/EXTRA-FIX/fix_ttm_mod.cpp +++ b/src/EXTRA-FIX/fix_ttm_mod.cpp @@ -41,18 +41,6 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -// helper class - -namespace { - class parser_error : public std::exception { - std::string message; - - public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } - }; -} - // OFFSET avoids outside-of-box atoms being rounded to grid pts incorrectly // SHIFT = 0.0 assigns atoms to lower-left grid pt // SHIFT = 0.5 assigns atoms to nearest grid pt @@ -596,10 +584,10 @@ void FixTTMMod::read_electron_temperatures(const std::string &filename) // check correctness of input data if ((ix < 0) || (ix >= nxgrid) || (iy < 0) || (iy >= nygrid) || (iz < 0) || (iz >= nzgrid)) - throw parser_error("Fix ttm invalid grid index in fix ttm/mod grid file"); + throw TokenizerException("Fix ttm invalid grid index in fix ttm/mod grid file",""); if (T_tmp < 0.0) - throw parser_error("Fix ttm electron temperatures must be > 0.0"); + throw TokenizerException("Fix ttm electron temperatures must be > 0.0",""); T_electron[iz][iy][ix] = T_tmp; T_initial_set[iz][iy][ix] = 1; diff --git a/src/QEQ/fix_qeq.cpp b/src/QEQ/fix_qeq.cpp index b43afb00d6..5a4e4e4e7d 100644 --- a/src/QEQ/fix_qeq.cpp +++ b/src/QEQ/fix_qeq.cpp @@ -43,10 +43,10 @@ using namespace FixConst; #define MAXLINE 1024 namespace { - class parser_error : public std::exception { + class qeq_parser_error : public std::exception { std::string message; public: - parser_error(const std::string &mesg) { message = mesg; } + explicit qeq_parser_error(const std::string &mesg) { message = mesg; } const char *what() const noexcept { return message.c_str(); } }; } @@ -761,8 +761,8 @@ void FixQEq::read_file(char *file) FILE *fp = utils::open_potential(file,lmp,nullptr); if (fp == nullptr) - throw parser_error(fmt::format("Cannot open fix qeq parameter file {}:" - " {}", file,utils::getsyserror())); + throw qeq_parser_error(fmt::format("Cannot open fix qeq parameter file {}: {}", + file,utils::getsyserror())); TextFileReader reader(fp, "qeq parameter"); while (1) { @@ -770,12 +770,12 @@ void FixQEq::read_file(char *file) if (values.count() == 0) continue; if (values.count() < 6) - throw parser_error("Invalid qeq parameter file"); + throw qeq_parser_error("Invalid qeq parameter file"); auto word = values.next_string(); utils::bounds(FLERR,word,1,ntypes,nlo,nhi,nullptr); if ((nlo < 0) || (nhi < 0)) - throw parser_error("Invalid atom type range"); + throw qeq_parser_error(fmt::format("Invalid atom type range: {}",word)); val = values.next_double(); for (int n=nlo; n <= nhi; ++n) chi[n] = val; diff --git a/src/REAXFF/fix_acks2_reaxff.cpp b/src/REAXFF/fix_acks2_reaxff.cpp index ec14ed72b2..b6789b1b2e 100644 --- a/src/REAXFF/fix_acks2_reaxff.cpp +++ b/src/REAXFF/fix_acks2_reaxff.cpp @@ -43,15 +43,6 @@ using namespace LAMMPS_NS; using namespace FixConst; -namespace { - class parser_error : public std::exception { - std::string message; - public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } - }; -} - static const char cite_fix_acks2_reax[] = "fix acks2/reaxff command:\n\n" "@Article{O'Hearn2020,\n" @@ -175,26 +166,27 @@ void FixACKS2ReaxFF::pertype_parameters(char *arg) const char *line = reader.next_line(); if (!line) - throw parser_error("Invalid parameter file for fix acks2/reaxff"); + throw TokenizerException("Invalid parameter file for fix acks2/reaxff",""); ValueTokenizer values(line); if (values.count() != 1) - throw parser_error("Fix acks2/reaxff: Incorrect format of parameter file"); + throw TokenizerException("Fix acks2/reaxff: Incorrect parameter file format",""); bond_softness = values.next_double(); for (int i = 1; i <= ntypes; i++) { const char *line = reader.next_line(); if (!line) - throw parser_error("Invalid parameter file for fix acks2/reaxff"); + throw TokenizerException("Fix acks2/reaxff: Incorrect parameter file format",""); ValueTokenizer values(line); if (values.count() != 5) - throw parser_error("Fix acks2/reaxff: Incorrect format of parameter file"); + throw TokenizerException("Fix acks2/reaxff: Incorrect parameter file format",""); int itype = values.next_int(); if ((itype < 1) || (itype > ntypes)) - throw parser_error("Fix acks2/reaxff: invalid atom type in parameter file"); + throw TokenizerException("Fix acks2/reaxff: invalid atom type in parameter file", + std::to_string(itype)); chi[itype] = values.next_double(); eta[itype] = values.next_double(); diff --git a/src/REAXFF/fix_qeq_reaxff.cpp b/src/REAXFF/fix_qeq_reaxff.cpp index 89ee3f338f..874a10bbae 100644 --- a/src/REAXFF/fix_qeq_reaxff.cpp +++ b/src/REAXFF/fix_qeq_reaxff.cpp @@ -45,19 +45,11 @@ #include #include #include +#include using namespace LAMMPS_NS; using namespace FixConst; -namespace { - class parser_error : public std::exception { - std::string message; - public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } - }; -} - static constexpr double EV_TO_KCAL_PER_MOL = 14.4; static constexpr double SMALL = 1.0e-14; @@ -243,15 +235,16 @@ void FixQEqReaxFF::pertype_parameters(char *arg) for (int i = 1; i <= ntypes; i++) { const char *line = reader.next_line(); if (!line) - throw parser_error("Invalid param file for fix qeq/reaxff"); + throw TokenizerException("Fix qeq/reaxff: Invalid param file format",""); ValueTokenizer values(line); if (values.count() != 4) - throw parser_error("Fix qeq/reaxff: Incorrect format of param file"); + throw TokenizerException("Fix qeq/reaxff: Incorrect format of param file",""); int itype = values.next_int(); if ((itype < 1) || (itype > ntypes)) - throw parser_error("Fix qeq/reaxff: invalid atom type in param file"); + throw TokenizerException("Fix qeq/reaxff: invalid atom type in param file", + std::to_string(itype)); chi[itype] = values.next_double(); eta[itype] = values.next_double(); diff --git a/src/REAXFF/reaxff_control.cpp b/src/REAXFF/reaxff_control.cpp index 90f12b2031..a95ec1d4ac 100644 --- a/src/REAXFF/reaxff_control.cpp +++ b/src/REAXFF/reaxff_control.cpp @@ -40,15 +40,6 @@ using LAMMPS_NS::utils::sfgets; using LAMMPS_NS::utils::logmesg; using LAMMPS_NS::ValueTokenizer; -namespace { - class parser_error : public std::exception { - std::string message; - public: - parser_error(const std::string &mesg) { message = mesg; } - const char *what() const noexcept { return message.c_str(); } - }; -} - namespace ReaxFF { static std::unordered_set inactive_keywords = { "ensemble_type", "nsteps", "dt", "proc_by_dim", "random_vel", @@ -63,6 +54,15 @@ namespace ReaxFF { "energy_update_freq", "atom_info", "atom_velocities", "atom_forces", "bond_info", "angle_info" }; + class control_parser_error : public std::exception { + std::string message; + public: + explicit control_parser_error(const std::string &format, const std::string &keyword) { + message = fmt::format(format, keyword); + } + const char *what() const noexcept { return message.c_str(); } + }; + // NOTE: this function is run on MPI rank 0 only void Read_Control_File(const char *control_file, control_params *control) @@ -92,7 +92,7 @@ namespace ReaxFF { auto keyword = values.next_string(); if (!values.has_next()) - throw parser_error(fmt::format("No value(s) for control parameter: {}\n",keyword)); + throw control_parser_error("No value(s) for control parameter: {}\n", keyword); if (inactive_keywords.find(keyword) != inactive_keywords.end()) { error->warning(FLERR,fmt::format("Ignoring inactive control " @@ -114,8 +114,7 @@ namespace ReaxFF { error->warning(FLERR,"Support for writing native trajectories has " "been removed after LAMMPS version 8 April 2021"); } else { - throw parser_error(fmt::format("Unknown parameter {} in " - "control file", keyword)); + throw control_parser_error("Unknown parameter {} in control file", keyword); } } } catch (LAMMPS_NS::EOFException &) { diff --git a/src/REAXFF/reaxff_ffield.cpp b/src/REAXFF/reaxff_ffield.cpp index db4a63972e..34db1c232d 100644 --- a/src/REAXFF/reaxff_ffield.cpp +++ b/src/REAXFF/reaxff_ffield.cpp @@ -41,16 +41,14 @@ using LAMMPS_NS::utils::open_potential; using LAMMPS_NS::utils::getsyserror; using LAMMPS_NS::utils::uppercase; -namespace { - class parser_error : public std::exception { +namespace ReaxFF { + + class ffield_parser_error : public std::exception { std::string message; public: - parser_error(const std::string &mesg) { message = mesg; } + explicit ffield_parser_error(const std::string &mesg) { message = mesg; } const char *what() const noexcept { return message.c_str(); } }; -} - -namespace ReaxFF { void Read_Force_Field(const char *filename, reax_interaction *reax, control_params *control, MPI_Comm world) @@ -63,7 +61,7 @@ namespace ReaxFF { // read and parse the force field only on rank 0 #define THROW_ERROR(txt) \ - throw parser_error(fmt::format("{}:{}: {}",filename,lineno,txt)) + throw ffield_parser_error(fmt::format("{}:{}: {}",filename,lineno,txt)) if (control->me == 0) { FILE *fp = LAMMPS_NS::utils::open_potential(filename, lmp, nullptr); @@ -165,7 +163,7 @@ namespace ReaxFF { // copy element symbol in uppercase and truncate stored element symbol if necessary auto element = uppercase(values.next_string()); - strncpy(sbp[i].name,element.c_str(),4); + strncpy(sbp[i].name,element.c_str(),3); sbp[i].name[3] = '\0'; sbp[i].r_s = values.next_double(); diff --git a/src/tokenizer.h b/src/tokenizer.h index 247afd0240..060e1bf6e3 100644 --- a/src/tokenizer.h +++ b/src/tokenizer.h @@ -60,7 +60,7 @@ class TokenizerException : public std::exception { * * \param msg String with error message * \param token String of the token/word that caused the error */ - TokenizerException(const std::string &msg, const std::string &token); + explicit TokenizerException(const std::string &msg, const std::string &token); ~TokenizerException() noexcept {} @@ -74,7 +74,7 @@ class InvalidIntegerException : public TokenizerException { /** Thrown during converting string to integer number * * \param token String of the token/word that caused the error */ - InvalidIntegerException(const std::string &token) : + explicit InvalidIntegerException(const std::string &token) : TokenizerException("Not a valid integer number", token) { } @@ -85,7 +85,7 @@ class InvalidFloatException : public TokenizerException { /** Thrown during converting string to floating point number * * \param token String of the token/word that caused the error */ - InvalidFloatException(const std::string &token) : + explicit InvalidFloatException(const std::string &token) : TokenizerException("Not a valid floating-point number", token) { } From f783958e39948d48ce9b2714e1fa8477809fd380 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Oct 2021 12:11:28 -0400 Subject: [PATCH 10/18] add test for create_atoms() --- unittest/python/python-commands.py | 41 ++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index f3526d6d4b..bd8512894f 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -1,6 +1,6 @@ -import sys,os,unittest -from lammps import lammps, LMP_VAR_ATOM, LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR +import sys,os,unittest,ctypes +from lammps import lammps, LMP_VAR_ATOM, LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, LAMMPS_DOUBLE_2D, LAMMPS_AUTODETECT has_manybody=False try: @@ -494,6 +494,43 @@ create_atoms 1 single & self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0]) self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0]) + def test_create_atoms(self): + self.lmp.command("boundary f p m") + self.lmp.command("region box block 0 10 0 10 0 10") + self.lmp.command("create_box 2 box") + # second atom is outside the box -> dropped + self.lmp.create_atoms(2, [1,2], [1,1], [1.0, 1.0, 3.0, 5.0, 8.0, 12.0]) + self.assertEqual(self.lmp.get_natoms(),1) + # non-zero velocities + self.lmp.create_atoms(2, None, [2,2], [2.0, 2.0, 1.0, 3.0, 4.0, 6.0], v=[0.1, 0.2, 0.3, -0.1, -0.2, -0.3]) + self.assertEqual(self.lmp.get_natoms(),3) + # first atom is dropped, extend shrinkwrapped box for second atom, third atoms is wrapped around PBC. + self.lmp.create_atoms(3, [5,8,10], [1,2,1], [-1.0, 1.0, 3.0, 5.0, 8.0, 12.0, 1.0, -1.0, 1.0], shrinkexceed=True) + self.assertEqual(self.lmp.get_natoms(),5) + # set image flags + self.lmp.create_atoms(1, None, [2], [5.0, 8.0, 1.0], image=[self.lmp.encode_image_flags(1,0,-1)]) + self.assertEqual(self.lmp.get_natoms(),6) + tag = self.lmp.extract_atom("id") + typ = self.lmp.extract_atom("type") + pos = self.lmp.extract_atom("x",LAMMPS_DOUBLE_2D) + vel = self.lmp.extract_atom("v",LAMMPS_DOUBLE_2D) + img = self.lmp.extract_atom("image",LAMMPS_AUTODETECT) + # expected results: tag, type, x, v, image + result = [ [ 1, 1, [1.0, 1.0, 3.0], [ 0.0, 0.0, 0.0], [0, 0, 0]],\ + [ 2, 2, [2.0, 2.0, 1.0], [ 0.1, 0.2, 0.3], [0, 0, 0]],\ + [ 3, 2, [3.0, 4.0, 6.0], [-0.1, -0.2, -0.3], [0, 0, 0]],\ + [ 8, 2, [5.0, 8.0, 12.0], [ 0.0, 0.0, 0.0], [0, 0, 0]],\ + [10, 1, [1.0, 9.0, 1.0], [ 0.0, 0.0, 0.0], [0, 0, 0]],\ + [11, 2, [5.0, 8.0, 1.0], [ 0.0, 0.0, 0.0], [1, 0, -1]] ] + for i in range(len(result)): + self.assertEqual(tag[i],result[i][0]) + self.assertEqual(typ[i],result[i][1]) + for j in range(3): + self.assertEqual(pos[i][0:3],result[i][2]) + self.assertEqual(vel[i][0:3],result[i][3]) + self.assertEqual(self.lmp.decode_image_flags(img[i]), result[i][4]) + + ############################## if __name__ == "__main__": unittest.main() From 3044923cbfff0a857c03bc18413a418d2d1d3479 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Oct 2021 12:12:21 -0400 Subject: [PATCH 11/18] less ambiguous tests for arguments being not None --- python/lammps/core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 7dea6e5e6e..1588709d92 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -1361,7 +1361,7 @@ class lammps(object): This function is a wrapper around the :cpp:func:`lammps_create_atoms` function of the C-library interface, and the behavior is similar except that the *v*, *image*, and *shrinkexceed* arguments are optional and - default to *None*, *None*, and *False*, respectively. With none being + default to *None*, *None*, and *False*, respectively. With *None* being equivalent to a ``NULL`` pointer in C. The lists of coordinates, types, atom IDs, velocities, image flags can @@ -1389,7 +1389,7 @@ class lammps(object): :return: number of atoms created. 0 if insufficient or invalid data :rtype: int """ - if id: + if id != None: id_lmp = (self.c_tagint*n)() try: id_lmp[:] = id[0:n] @@ -1411,7 +1411,7 @@ class lammps(object): except ValueError: return 0 - if v: + if v != None: v_lmp = (c_double*(three_n))() try: v_lmp[:] = v[0:three_n] @@ -1420,7 +1420,7 @@ class lammps(object): else: v_lmp = None - if image: + if image != None: img_lmp = (self.c_imageint*n)() try: img_lmp[:] = image[0:n] From 3d9e4638a73db69849b306d44c3e61a7d0d6ada2 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 26 Oct 2021 13:08:03 -0400 Subject: [PATCH 12/18] Don't use -restrict for icpx --- cmake/CMakeLists.txt | 2 +- examples/plugins/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ec4a9c2eb7..449a9b3141 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -81,7 +81,7 @@ check_for_autogen_files(${LAMMPS_SOURCE_DIR}) include(CheckIncludeFileCXX) # set required compiler flags and compiler/CPU arch specific optimizations -if((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") OR (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") if(CMAKE_SYSTEM_NAME STREQUAL "Windows") if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qrestrict") diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt index c61454870a..0ca2c025e2 100644 --- a/examples/plugins/CMakeLists.txt +++ b/examples/plugins/CMakeLists.txt @@ -41,7 +41,7 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Need -restrict with Intel compilers -if((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") OR (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict") endif() From fe9dfc60957e49d6908f25b95947a065057fc36f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Oct 2021 14:17:31 -0400 Subject: [PATCH 13/18] follow Python style guidelines --- python/lammps/core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 1588709d92..5e51a7bba0 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -1389,7 +1389,7 @@ class lammps(object): :return: number of atoms created. 0 if insufficient or invalid data :rtype: int """ - if id != None: + if id is not None: id_lmp = (self.c_tagint*n)() try: id_lmp[:] = id[0:n] @@ -1411,7 +1411,7 @@ class lammps(object): except ValueError: return 0 - if v != None: + if v is not None: v_lmp = (c_double*(three_n))() try: v_lmp[:] = v[0:three_n] @@ -1420,7 +1420,7 @@ class lammps(object): else: v_lmp = None - if image != None: + if image is not None: img_lmp = (self.c_imageint*n)() try: img_lmp[:] = image[0:n] From 008013ddfbf58e9698ec504bbdeb59783ae3dd57 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 26 Oct 2021 15:00:12 -0400 Subject: [PATCH 14/18] Explicitly check for None --- python/lammps/core.py | 10 +++++----- python/lammps/pylammps.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 5e51a7bba0..fcd5c76ad5 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -99,7 +99,7 @@ class lammps(object): # load a shared object. try: - if ptr: self.lib = CDLL("",RTLD_GLOBAL) + if ptr is not None: self.lib = CDLL("",RTLD_GLOBAL) except OSError: self.lib = None @@ -329,7 +329,7 @@ class lammps(object): # ptr is the desired instance of LAMMPS # just convert it to ctypes ptr and store in self.lmp - if not ptr: + if ptr is None: # with mpi4py v2+, we can pass MPI communicators to LAMMPS # need to adjust for type of MPI communicator object @@ -338,7 +338,7 @@ class lammps(object): from mpi4py import MPI self.MPI = MPI - if comm: + if comm is not None: if not self.has_mpi_support: raise Exception('LAMMPS not compiled with real MPI library') if not self.has_mpi4py: @@ -354,7 +354,7 @@ class lammps(object): narg = 0 cargs = None - if cmdargs: + if cmdargs is not None: cmdargs.insert(0,"lammps") narg = len(cmdargs) for i in range(narg): @@ -376,7 +376,7 @@ class lammps(object): if self.has_mpi4py and self.has_mpi_support: self.comm = self.MPI.COMM_WORLD self.opened = 1 - if cmdargs: + if cmdargs is not None: cmdargs.insert(0,"lammps") narg = len(cmdargs) for i in range(narg): diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index a6e3578aef..abd4d6da98 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -854,30 +854,30 @@ class IPyLammps(PyLammps): """ cmd_args = [group, "image", filename, color, diameter] - if size: + if size is not None: width = size[0] height = size[1] cmd_args += ["size", width, height] - if view: + if view is not None: theta = view[0] phi = view[1] cmd_args += ["view", theta, phi] - if center: + if center is not None: flag = center[0] Cx = center[1] Cy = center[2] Cz = center[3] cmd_args += ["center", flag, Cx, Cy, Cz] - if up: + if up is not None: Ux = up[0] Uy = up[1] Uz = up[2] cmd_args += ["up", Ux, Uy, Uz] - if zoom: + if zoom is not None: cmd_args += ["zoom", zoom] cmd_args.append("modify backcolor " + background_color) From 3376f3daa8c41b0510d4ea9a85975d34f89bef47 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 26 Oct 2021 16:45:57 -0400 Subject: [PATCH 15/18] Remove unused import --- python/examples/matplotlib_plot.py | 1 - python/examples/simple.py | 1 - 2 files changed, 2 deletions(-) diff --git a/python/examples/matplotlib_plot.py b/python/examples/matplotlib_plot.py index b85d40c4c4..0c918507ad 100755 --- a/python/examples/matplotlib_plot.py +++ b/python/examples/matplotlib_plot.py @@ -62,7 +62,6 @@ if me == 0: plt.show(block=False) # run nfreq steps at a time w/out pre/post, query compute, refresh plot -import time while ntimestep < nsteps: lmp.command("run %d pre no post no" % nfreq) diff --git a/python/examples/simple.py b/python/examples/simple.py index 861a208895..8925ce48c0 100755 --- a/python/examples/simple.py +++ b/python/examples/simple.py @@ -13,7 +13,6 @@ from __future__ import print_function import sys -import numpy as np import ctypes # parse command line From f0318fb87429b5439c1f5494edd4ad35384c8666 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Oct 2021 19:16:13 -0400 Subject: [PATCH 16/18] try to make changing LMP_INC settings less confusing to inexperienced people --- doc/src/Build_settings.rst | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/src/Build_settings.rst b/doc/src/Build_settings.rst index 01bd8e2c80..b68313aaed 100644 --- a/doc/src/Build_settings.rst +++ b/doc/src/Build_settings.rst @@ -321,9 +321,7 @@ following settings: .. code-block:: make - LMP_INC = -DLAMMPS_JPEG - LMP_INC = -DLAMMPS_PNG - LMP_INC = -DLAMMPS_FFMPEG + LMP_INC = -DLAMMPS_JPEG -DLAMMPS_PNG -DLAMMPS_FFMPEG JPG_INC = -I/usr/local/include # path to jpeglib.h, png.h, zlib.h header files if make cannot find them JPG_PATH = -L/usr/lib # paths to libjpeg.a, libpng.a, libz.a (.so) files if make cannot find them @@ -372,7 +370,7 @@ including :doc:`read_data `, :doc:`rerun `, and .. code-block:: make - LMP_INC = -DLAMMPS_GZIP + LMP_INC = -DLAMMPS_GZIP This option requires that your operating system fully supports the "popen()" function in the standard runtime library and that a ``gzip`` @@ -454,7 +452,7 @@ those systems: .. code-block:: make - LMP_INC = -DLAMMPS_LONGLONG_TO_LONG + LMP_INC = -DLAMMPS_LONGLONG_TO_LONG ---------- @@ -481,7 +479,7 @@ e.g. to Python. Of course, the calling code has to be set up to .. code-block:: make - LMP_INC = -DLAMMPS_EXCEPTIONS + LMP_INC = -DLAMMPS_EXCEPTIONS .. note:: @@ -522,7 +520,7 @@ executable, not the library. .. code-block:: make - LMP_INC = -DLAMMPS_TRAP_FPE + LMP_INC = -DLAMMPS_TRAP_FPE After compilation with this flag set, the LAMMPS executable will stop and produce a core dump when a division by zero, overflow, illegal math From 1247f4d67b96a2d34b881a025b5173e9fba5ec8d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Oct 2021 19:54:09 -0400 Subject: [PATCH 17/18] add function to print information about available compressions tools --- doc/src/Developer_platform.rst | 3 +++ src/info.cpp | 1 + src/lammps.cpp | 2 ++ src/platform.cpp | 24 +++++++++++++++++++++--- src/platform.h | 9 +++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/doc/src/Developer_platform.rst b/doc/src/Developer_platform.rst index 4cea36f94c..c9ecd30cec 100644 --- a/doc/src/Developer_platform.rst +++ b/doc/src/Developer_platform.rst @@ -42,6 +42,9 @@ Platform information functions .. doxygenfunction:: mpi_info :project: progguide +.. doxygenfunction:: compress_info + :project: progguide + File and path functions and global constants ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/info.cpp b/src/info.cpp index bbc94fbccb..a726b2f00b 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -309,6 +309,7 @@ void Info::command(int narg, char **arg) #else // defined(LAMMPS_SMALLSMALL) fputs("-DLAMMPS_SMALLSMALL\n",out); #endif + if (has_gzip_support()) fmt::print(out,"\n{}\n",platform::compress_info()); int ncword, ncline = 0; fputs("\nInstalled packages:\n\n",out); diff --git a/src/lammps.cpp b/src/lammps.cpp index 5d571b88dd..0829c4fdbd 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -1379,6 +1379,8 @@ void LAMMPS::print_config(FILE *fp) sizeof(smallint)*8, sizeof(imageint)*8, sizeof(tagint)*8, sizeof(bigint)*8); + if (Info::has_gzip_support()) fmt::print(fp,"\n{}\n",platform::compress_info()); + fputs("\nInstalled packages:\n\n",fp); for (int i = 0; nullptr != (pkg = installed_packages[i]); ++i) { ncword = strlen(pkg); diff --git a/src/platform.cpp b/src/platform.cpp index 555026b2ac..bd0fcd9dfe 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -418,6 +418,24 @@ std::string platform::mpi_info(int &major, int &minor) return {version}; } +/* ---------------------------------------------------------------------- + collect available compression tool info +------------------------------------------------------------------------- */ + +std::string platform::compress_info() +{ + std::string buf = "Available compression formats:\n\n"; + bool none_found = true; + for (const auto &cmpi : compress_styles) { + if (cmpi.style == ::compress_info::NONE) continue; + if (find_exe_path(cmpi.command).size()) { + none_found = false; + buf += fmt::format("Extension: .{:6} Command: {}\n", cmpi.extension, cmpi.command); + } + } + if (none_found) buf += "None\n"; + return buf; +} /* ---------------------------------------------------------------------- set environment variable ------------------------------------------------------------------------- */ @@ -930,7 +948,7 @@ bool platform::file_is_readable(const std::string &path) bool platform::has_compress_extension(const std::string &file) { - return find_compress_type(file).style != compress_info::NONE; + return find_compress_type(file).style != ::compress_info::NONE; } /* ---------------------------------------------------------------------- @@ -943,7 +961,7 @@ FILE *platform::compressed_read(const std::string &file) #if defined(LAMMPS_GZIP) auto compress = find_compress_type(file); - if (compress.style == compress_info::NONE) return nullptr; + if (compress.style == ::compress_info::NONE) return nullptr; if (find_exe_path(compress.command).size()) // put quotes around file name so that they may contain blanks @@ -962,7 +980,7 @@ FILE *platform::compressed_write(const std::string &file) #if defined(LAMMPS_GZIP) auto compress = find_compress_type(file); - if (compress.style == compress_info::NONE) return nullptr; + if (compress.style == ::compress_info::NONE) return nullptr; if (find_exe_path(compress.command).size()) // put quotes around file name so that they may contain blanks diff --git a/src/platform.h b/src/platform.h index de8ecce016..95a0c3cc35 100644 --- a/src/platform.h +++ b/src/platform.h @@ -109,6 +109,15 @@ namespace platform { std::string mpi_info(int &major, int &minor); + /*! Return string with list of available compression types and executables + * + * This function tests which of the supported compression executables + * are available for reading or writing compressed files where supported. + * + * \return string with list of available compression tools */ + + std::string compress_info(); + /*! Add variable to the environment * * \param vardef variable name or variable definition (NAME=value) From 11ee3759dfdd85a015a983547656e33e00a2f9a0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 27 Oct 2021 08:22:18 -0400 Subject: [PATCH 18/18] use consistent formatting --- cmake/CMakeLists.txt | 2 +- cmake/Modules/LAMMPSUtils.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 449a9b3141..00a254197d 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -83,7 +83,7 @@ include(CheckIncludeFileCXX) # set required compiler flags and compiler/CPU arch specific optimizations if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qrestrict") endif() if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4) diff --git a/cmake/Modules/LAMMPSUtils.cmake b/cmake/Modules/LAMMPSUtils.cmake index 74102ab244..28ad99fa31 100644 --- a/cmake/Modules/LAMMPSUtils.cmake +++ b/cmake/Modules/LAMMPSUtils.cmake @@ -85,7 +85,7 @@ endfunction(GenerateBinaryHeader) # fetch missing potential files function(FetchPotentials pkgfolder potfolder) - if (EXISTS "${pkgfolder}/potentials.txt") + if(EXISTS "${pkgfolder}/potentials.txt") file(STRINGS "${pkgfolder}/potentials.txt" linelist REGEX "^[^#].") foreach(line ${linelist}) string(FIND ${line} " " blank)