9#include "tbb/task_arena.h"
10#define TBB_PREVIEW_GLOBAL_CONTROL 1
11#include "tbb/global_control.h"
47 std::ifstream
f(
"/sys/fs/cgroup/cpuacct/cpu.cfs_quota_us");
53 f.open(
"/sys/fs/cgroup/cpuacct/cpu.cfs_period_us");
57 return static_cast<int>(
std::ceil(cfs_quota / cfs_period));
61 return std::thread::hardware_concurrency();
74 const unsigned tbbDefaultNumberThreads =
fTBBArena->max_concurrency();
75 maxConcurrency = maxConcurrency > 0 ? std::min(maxConcurrency, tbbDefaultNumberThreads) : tbbDefaultNumberThreads;
77 if (maxConcurrency > bcCpus) {
78 Warning(
"RTaskArenaWrapper",
"CPU Bandwith Control Active. Proceeding with %d threads accordingly", bcCpus);
79 maxConcurrency = bcCpus;
81 if (maxConcurrency > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
82 Warning(
"RTaskArenaWrapper",
"tbb::global_control is active, limiting the number of parallel workers"
83 "from this task arena available for execution.");
111 static std::weak_ptr<ROOT::Internal::RTaskArenaWrapper> weak_GTAWrapper;
114 const std::lock_guard<std::mutex> lock{
m};
115 if (
auto sp = weak_GTAWrapper.lock()) {
116 if (maxConcurrency && (sp->TaskArenaSize() != maxConcurrency)) {
117 Warning(
"RTaskArenaWrapper",
"There's already an active task arena. Proceeding with the current %d threads",
118 sp->TaskArenaSize());
123 weak_GTAWrapper = sp;
void Warning(const char *location, const char *msgfmt,...)
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.