Skip to content

Commit

Permalink
warn on tbb::global_control interferences
Browse files Browse the repository at this point in the history
    warn when the number of threads set by the user is limited at runtime
    by tbb::global_control.

    Fix for github issue root-project#6363: root-project#6363
  • Loading branch information
xvallspl authored and mrodozov committed Jan 21, 2021
1 parent 27c4773 commit c7af7d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/imt/src/RTaskArena.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mutex>
#include <thread>
#include "tbb/task_arena.h"
#include "tbb/global_control.h"

//////////////////////////////////////////////////////////////////////////
///
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions core/imt/src/TThreadExecutor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ TThreadExecutor::TThreadExecutor(UInt_t nThreads)
void TThreadExecutor::ParallelFor(unsigned int start, unsigned int end, unsigned step,
const std::function<void(unsigned int i)> &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);
Expand All @@ -150,12 +156,24 @@ void TThreadExecutor::ParallelFor(unsigned int start, unsigned int end, unsigned
double TThreadExecutor::ParallelReduce(const std::vector<double> &objs,
const std::function<double(double a, double b)> &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<double>(objs, redfunc); });
}

float TThreadExecutor::ParallelReduce(const std::vector<float> &objs,
const std::function<float(float a, float b)> &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<float>(objs, redfunc); });
}

Expand Down

0 comments on commit c7af7d1

Please sign in to comment.