enforce that the number of threads is properly reset for /omp styles
This commit is contained in:
@ -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
|
||||
|
||||
@ -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");
|
||||
|
||||
Reference in New Issue
Block a user