enforce that the number of threads is properly reset for /omp styles

This commit is contained in:
Axel Kohlmeyer
2023-10-03 19:38:22 -04:00
parent 02b9bdd639
commit 6ff7050d2d
2 changed files with 13 additions and 2 deletions

View File

@ -34,6 +34,10 @@
#include <cstring>
#if defined(_OPENMP)
#include <omp.h>
#endif
using namespace LAMMPS_NS;
using MathConst::THIRD;
@ -44,6 +48,9 @@ ThrOMP::ThrOMP(LAMMPS *ptr, int style) : lmp(ptr), fix(nullptr), thr_style(style
// register fix omp with this class
fix = static_cast<FixOMP *>(lmp->modify->get_fix_by_id("package_omp"));
if (!fix) lmp->error->all(FLERR, "The 'package omp' command is required for /omp styles");
#if defined(_OPENMP)
omp_set_num_threads(lmp->comm->nthreads);
#endif
}
// clang-format off

View File

@ -1329,9 +1329,9 @@ void LammpsGui::preferences()
// must delete LAMMPS instance after preferences have changed that require
// using different command line flags when creating the LAMMPS instance like
// suffixes or package commands
int newthreads = settings.value("nthreads", 1).toInt();
if ((oldaccel != settings.value("accelerator", AcceleratorTab::None).toInt()) ||
(oldthreads != settings.value("nthreads", 1).toInt()) ||
(oldecho != settings.value("echo", false).toBool()) ||
(oldthreads != newthreads) || (oldecho != settings.value("echo", false).toBool()) ||
(oldcite != settings.value("cite", false).toBool())) {
if (lammps.is_running()) {
stop_run();
@ -1340,6 +1340,10 @@ void LammpsGui::preferences()
}
lammps.close();
lammpsstatus->hide();
#if defined(_OPENMP)
qputenv("OMP_NUM_THREADS", std::to_string(newthreads).c_str());
omp_set_num_threads(newthreads);
#endif
}
if (imagewindow) imagewindow->createImage();
settings.beginGroup("reformat");