From 114dd48779b0830d0797d7745bded576a00c92bb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 13 Oct 2020 16:56:49 -0400 Subject: [PATCH] change behavior with respect to OpenMP versus the regular LAMMPS executable since the shell is not meant to be run with MPI we can use all threads by default. --- tools/lammps-shell/lammps-shell.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/lammps-shell/lammps-shell.cpp b/tools/lammps-shell/lammps-shell.cpp index c01d342f6c..18f60f028d 100644 --- a/tools/lammps-shell/lammps-shell.cpp +++ b/tools/lammps-shell/lammps-shell.cpp @@ -33,14 +33,20 @@ #include #endif +#if defined(_OPENMP) +#include +#endif + #include #include using namespace LAMMPS_NS; -const int buflen = 512; +char *omp_threads = nullptr; +const int buflen = 512; char buf[buflen]; void *lmp = nullptr; + enum { ATOM_STYLE, INTEGRATE_STYLE, @@ -672,6 +678,17 @@ int main(int argc, char **argv) std::cout << "WARNING: LAMMPS was compiled without exceptions\n" "WARNING: The shell will terminate on errors.\n"; +#if defined(_OPENMP) + int nthreads = omp_get_max_threads(); +#else + int nthreads = 1; +#endif + // avoid OMP_NUM_THREADS warning and change the default behavior + // to use the maximum number of threads available since this is + // not intended to be run with MPI. + omp_threads = dupstring(std::string("OMP_NUM_THREADS=" + std::to_string(nthreads))); + putenv(omp_threads); + lmp = lammps_open_no_mpi(argc, argv, nullptr); if (lmp == nullptr) return 1;