Skip to content

Commit

Permalink
reset num threads in SLiMgui if altered
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Jul 29, 2023
1 parent 34b26ea commit 889b68d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions SLiMgui/SLiMWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions eidos/eidos_functions_other.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 889b68d

Please sign in to comment.