From 14aa8bcf2091ffa1aef6911f52647e0158d4b628 Mon Sep 17 00:00:00 2001 From: Xavier Valls Pla Date: Mon, 16 Nov 2020 09:51:43 +0100 Subject: [PATCH] warn on tbb::global_control interferences warn when the number of threads set by the user is limited at runtime by tbb::global_control. Fix for github issue #6363: https://github.com/root-project/root/issues/6363 --- core/imt/src/RTaskArena.cxx | 5 +++++ core/imt/src/TThreadExecutor.cxx | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/imt/src/RTaskArena.cxx b/core/imt/src/RTaskArena.cxx index 477dfc932b6ab..883cee96d870f 100644 --- a/core/imt/src/RTaskArena.cxx +++ b/core/imt/src/RTaskArena.cxx @@ -6,6 +6,7 @@ #include #include #include "tbb/task_arena.h" +#include "tbb/global_control.h" ////////////////////////////////////////////////////////////////////////// /// @@ -75,6 +76,10 @@ RTaskArenaWrapper::RTaskArenaWrapper(unsigned maxConcurrency) : fTBBArena(new tb Warning("RTaskArenaWrapper", "CPU Bandwith Control Active. Proceeding with %d threads accordingly", bcCpus); maxConcurrency = bcCpus; } + if (maxConcurrency > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) { + Warning("RTaskArenaWrapper", "tbb::global_control is active, limiting the number of parallel workers" + "from this task arena available for execution."); + } fTBBArena->initialize(maxConcurrency); fNWorkers = maxConcurrency; ROOT::EnableThreadSafety(); diff --git a/core/imt/src/TThreadExecutor.cxx b/core/imt/src/TThreadExecutor.cxx index 13397af671845..4c20075c03f4a 100644 --- a/core/imt/src/TThreadExecutor.cxx +++ b/core/imt/src/TThreadExecutor.cxx @@ -155,6 +155,12 @@ TThreadExecutor::TThreadExecutor(UInt_t nThreads) void TThreadExecutor::ParallelFor(unsigned int start, unsigned int end, unsigned step, const std::function &f) { + if (GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) { + Warning("TThreadExecutor::ParallelFor", + "tbb::global_control is limiting the number of parallel workers." + " Proceeding with %zu threads this time", + tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)); + } fTaskArenaW->Access().execute([&] { tbb::this_task_arena::isolate([&] { tbb::parallel_for(start, end, step, f); @@ -171,6 +177,12 @@ void TThreadExecutor::ParallelFor(unsigned int start, unsigned int end, unsigned double TThreadExecutor::ParallelReduce(const std::vector &objs, const std::function &redfunc) { + if (GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) { + Warning("TThreadExecutor::ParallelReduce", + "tbb::global_control is limiting the number of parallel workers." + " Proceeding with %zu threads this time", + tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)); + } return fTaskArenaW->Access().execute([&] { return ROOT::Internal::ParallelReduceHelper(objs, redfunc); }); } @@ -183,6 +195,12 @@ double TThreadExecutor::ParallelReduce(const std::vector &objs, float TThreadExecutor::ParallelReduce(const std::vector &objs, const std::function &redfunc) { + if (GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) { + Warning("TThreadExecutor::ParallelReduce", + "tbb::global_control is limiting the number of parallel workers." + " Proceeding with %zu threads this time", + tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)); + } return fTaskArenaW->Access().execute([&] { return ROOT::Internal::ParallelReduceHelper(objs, redfunc); }); }