2#define TBB_USE_CAPTURED_EXCEPTION 0
12#include "tbb/task_arena.h"
13#define TBB_PREVIEW_GLOBAL_CONTROL 1
14#include "tbb/global_control.h"
51 std::ifstream
f(
"/sys/fs/cgroup/cpuacct/cpu.cfs_quota_us");
57 f.open(
"/sys/fs/cgroup/cpuacct/cpu.cfs_period_us");
61 return static_cast<int>(std::ceil(cfs_quota / cfs_period));
65 return std::thread::hardware_concurrency();
78 const unsigned tbbDefaultNumberThreads =
fTBBArena->max_concurrency();
79 maxConcurrency = maxConcurrency > 0 ? std::min(maxConcurrency, tbbDefaultNumberThreads) : tbbDefaultNumberThreads;
81 if (maxConcurrency > bcCpus) {
82 Warning(
"RTaskArenaWrapper",
"CPU Bandwith Control Active. Proceeding with %d threads accordingly", bcCpus);
83 maxConcurrency = bcCpus;
85 if (maxConcurrency > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
86 Warning(
"RTaskArenaWrapper",
"tbb::global_control is active, limiting the number of parallel workers"
87 "from this task arena available for execution.");
115 static std::weak_ptr<ROOT::Internal::RTaskArenaWrapper> weak_GTAWrapper;
118 const std::lock_guard<std::mutex> lock{
m};
119 if (
auto sp = weak_GTAWrapper.lock()) {
120 if (maxConcurrency && (sp->TaskArenaSize() != maxConcurrency)) {
121 Warning(
"RTaskArenaWrapper",
"There's already an active task arena. Proceeding with the current %d threads",
122 sp->TaskArenaSize());
127 weak_GTAWrapper = sp;
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Wrapper for tbb::task_arena.
ROOT::ROpaqueTaskArena & Access()
Provides access to the wrapped tbb::task_arena.
RTaskArenaWrapper(unsigned maxConcurrency=0)
Initializes the tbb::task_arena within RTaskArenaWrapper.
static unsigned fNWorkers
static unsigned TaskArenaSize()
std::unique_ptr< ROOT::ROpaqueTaskArena > fTBBArena
std::shared_ptr< ROOT::Internal::RTaskArenaWrapper > GetGlobalTaskArena(unsigned maxConcurrency=0)
Factory function returning a shared pointer to the instance of the global RTaskArenaWrapper.
int LogicalCPUBandwithControl()
Returns the available number of logical cores.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.