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.
This commit is contained in:
Axel Kohlmeyer
2020-10-13 16:56:49 -04:00
parent bdb4334210
commit 114dd48779

View File

@ -33,14 +33,20 @@
#include <signal.h> #include <signal.h>
#endif #endif
#if defined(_OPENMP)
#include <omp.h>
#endif
#include <readline/history.h> #include <readline/history.h>
#include <readline/readline.h> #include <readline/readline.h>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
const int buflen = 512; char *omp_threads = nullptr;
const int buflen = 512;
char buf[buflen]; char buf[buflen];
void *lmp = nullptr; void *lmp = nullptr;
enum { enum {
ATOM_STYLE, ATOM_STYLE,
INTEGRATE_STYLE, INTEGRATE_STYLE,
@ -672,6 +678,17 @@ int main(int argc, char **argv)
std::cout << "WARNING: LAMMPS was compiled without exceptions\n" std::cout << "WARNING: LAMMPS was compiled without exceptions\n"
"WARNING: The shell will terminate on errors.\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); lmp = lammps_open_no_mpi(argc, argv, nullptr);
if (lmp == nullptr) return 1; if (lmp == nullptr) return 1;