Skip to content
Snippets Groups Projects
Unverified Commit b495d645 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony Committed by GitHub
Browse files

Merge pull request #27517 from mantidproject/27375_setting_max_threads_from_config

Make OpenMP for loops use max threads value from config
parents e6838b78 56bc4c83
No related branches found
No related tags found
No related merge requests found
......@@ -399,19 +399,6 @@ void SofQWNormalisedPolygon::exec() {
const auto &inputIndices = inputWS->indexInfo();
const auto &spectrumInfo = inputWS->spectrumInfo();
/*
On linux, the value value that is set at startup for the number of allowed
threads when mulitprocessing is not carried over to new execution threads.
As a result, mantid can segfault due to accessing workspaces that are
created in the main thread, as they have too few indexes that are supposed
to match the number of threads.
Resetting the number of threads here to what is set in the config file is a
temporary solution.
*/
// TODO: Do this via a MultiThreaded.h macro via:
// https://github.com/mantidproject/mantid/issues/27375#issuecomment-553799284
FrameworkManager::Instance().setNumOMPThreadsToConfigValue();
PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
for (int64_t i = 0; i < static_cast<int64_t>(nHistos); ++i) {
PARALLEL_START_INTERUPT_REGION
......
......@@ -127,6 +127,7 @@ void AtomicOp(std::atomic<T> &f, T d, BinaryOp op) {
// compiler.
#ifdef _OPENMP
#include "MantidKernel/ConfigService.h"
#include <omp.h>
/** Includes code to add OpenMP commands to run the next for loop in parallel.
......@@ -135,14 +136,18 @@ void AtomicOp(std::atomic<T> &f, T d, BinaryOp op) {
* code to be executed in parallel
*/
#define PARALLEL_FOR_IF(condition) \
PRAGMA(omp parallel for if (condition) )
setMaxCoresToConfig(); \
PARALLEL_SET_DYNAMIC(false); \
PRAGMA(omp parallel for if (condition) )
/** Includes code to add OpenMP commands to run the next for loop in parallel.
* This includes no checks to see if workspaces are suitable
* and therefore should not be used in any loops that access workspaces.
*/
#define PARALLEL_FOR_NO_WSP_CHECK() \
PRAGMA(omp parallel for)
setMaxCoresToConfig(); \
PARALLEL_SET_DYNAMIC(false); \
PRAGMA(omp parallel for)
/** Includes code to add OpenMP commands to run the next for loop in parallel.
* and declare the variables to be firstprivate.
......@@ -150,9 +155,13 @@ void AtomicOp(std::atomic<T> &f, T d, BinaryOp op) {
* and therefore should not be used in any loops that access workspace.
*/
#define PARALLEL_FOR_NOWS_CHECK_FIRSTPRIVATE(variable) \
setMaxCoresToConfig(); \
PARALLEL_SET_DYNAMIC(false); \
PRAGMA(omp parallel for firstprivate(variable) )
#define PARALLEL_FOR_NO_WSP_CHECK_FIRSTPRIVATE2(variable1, variable2) \
setMaxCoresToConfig(); \
PARALLEL_SET_DYNAMIC(false); \
PRAGMA(omp parallel for firstprivate(variable1, variable2) )
/** Ensures that the next execution line or block is only executed if
......@@ -196,6 +205,14 @@ void AtomicOp(std::atomic<T> &f, T d, BinaryOp op) {
#define PARALLEL_SECTION PRAGMA(omp section)
inline void setMaxCoresToConfig() {
const auto maxCores = Mantid::Kernel::ConfigService::Instance().getValue<int>(
"MultiThreaded.MaxCores");
if (maxCores.get_value_or(0) > 0) {
PARALLEL_SET_NUM_THREADS(maxCores.get());
}
}
/** General purpose define for OpenMP, becomes the equivalent of
* #pragma omp EXPRESSION
* (if your compiler supports OpenMP)
......
......@@ -14,7 +14,7 @@ include (InstallRequiredSystemLibraries)
add_definitions ( -D_WINDOWS -DMS_VISUAL_STUDIO )
add_definitions ( -D_USE_MATH_DEFINES -DNOMINMAX )
add_definitions ( -DGSL_DLL -DJSON_DLL )
add_definitions ( -DPOCO_DLL -DPOCO_NO_UNWINDOWS )
add_definitions ( -DPOCO_DLL -DPOCO_NO_UNWINDOWS -DPOCO_NO_AUTOMATIC_LIBS)
add_definitions ( -DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE )
add_definitions ( -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS )
# Prevent deprecation errors from std::tr1 in googletest until it is fixed upstream. In MSVC 2017 and later
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment