cap the maximum number of threads used by default at 16

This commit is contained in:
Axel Kohlmeyer
2024-08-03 08:26:54 -04:00
parent c60c42cede
commit 4dfc15151a

View File

@ -137,8 +137,8 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
// check and initialize nthreads setting. Default is to use max if there // check and initialize nthreads setting. Default is to use max if there
// is no preference but do not override OMP_NUM_THREADS // is no preference but do not override OMP_NUM_THREADS
#if defined(_OPENMP) #if defined(_OPENMP)
// use maximum number of available threads unless OMP_NUM_THREADS was set // use up to 16 available threads unless OMP_NUM_THREADS was set
int nthreads = settings.value("nthreads", omp_get_max_threads()).toInt(); int nthreads = settings.value("nthreads", std::min(omp_get_max_threads(), 16)).toInt();
if (!qEnvironmentVariableIsSet("OMP_NUM_THREADS")) { if (!qEnvironmentVariableIsSet("OMP_NUM_THREADS")) {
qputenv("OMP_NUM_THREADS", std::to_string(nthreads).c_str()); qputenv("OMP_NUM_THREADS", std::to_string(nthreads).c_str());
} }