From 889b68db182b487ddbe34d78f5dba83b38cfa016 Mon Sep 17 00:00:00 2001 From: Ben Haller Date: Sat, 29 Jul 2023 15:53:34 -0400 Subject: [PATCH] reset num threads in SLiMgui if altered --- SLiMgui/SLiMWindowController.mm | 6 ++++++ eidos/eidos_functions_other.cpp | 3 +++ 2 files changed, 9 insertions(+) diff --git a/SLiMgui/SLiMWindowController.mm b/SLiMgui/SLiMWindowController.mm index 98d446e3..992ad8e5 100644 --- a/SLiMgui/SLiMWindowController.mm +++ b/SLiMgui/SLiMWindowController.mm @@ -463,6 +463,12 @@ - (void)startNewSimulationFromScript slimgui = nullptr; } + // Reset the number of threads to be used in parallel regions, if it has been changed by parallelSetNumThreads(); + // note that we do not save/restore the value across context switches between models, as we do RNGs and such, + // since we don't support end users running SLiMgui multithreaded anyhow + gEidosNumThreads = gEidosMaxThreads; + omp_set_num_threads(gEidosMaxThreads); + // Free the old simulation RNG and make a new one, to have clean state if (sim_RNG_initialized) { diff --git a/eidos/eidos_functions_other.cpp b/eidos/eidos_functions_other.cpp index 6c4b5b55..dfdf8885 100644 --- a/eidos/eidos_functions_other.cpp +++ b/eidos/eidos_functions_other.cpp @@ -737,6 +737,9 @@ EidosValue_SP Eidos_ExecuteFunction_parallelSetNumThreads(__attribute__((unused) gEidosNumThreads = (int)numThreads; omp_set_num_threads((int)numThreads); + // Note that this affects every running model, in SLiMgui. Since we don't really support end users running SLiMgui + // multithreaded, I'm not going to bother fixing that by saving/restoring it across SLiMgui context switches. + return gStaticEidosValueVOID; }