2#define TBB_USE_CAPTURED_EXCEPTION 0
15#include "tbb/task_arena.h"
16#define TBB_PREVIEW_GLOBAL_CONTROL 1
17#include "tbb/global_control.h"
52 if (
const char *envMaxThreads =
gSystem->Getenv(
"ROOT_MAX_THREADS")) {
53 char *str_end =
nullptr;
54 long maxThreads = std::strtol(envMaxThreads, &str_end, 0 );
55 if (str_end == envMaxThreads && maxThreads == 0) {
56 Error(
"ROOT::Internal::LogicalCPUBandwidthControl()",
57 "cannot parse number in environment variable ROOT_MAX_THREADS; ignoring.");
58 }
else if (maxThreads < 1) {
59 Error(
"ROOT::Internal::LogicalCPUBandwidthControl()",
60 "environment variable ROOT_MAX_THREADS must be >= 1, but set to %ld; ignoring.",
68 std::ifstream
f(
"/sys/fs/cgroup/cpuacct/cpu.cfs_quota_us");
74 f.open(
"/sys/fs/cgroup/cpuacct/cpu.cfs_period_us");
78 return static_cast<int>(std::ceil(cfs_quota / cfs_period));
82 return std::thread::hardware_concurrency();
95 const unsigned tbbDefaultNumberThreads =
fTBBArena->max_concurrency();
96 maxConcurrency = maxConcurrency > 0 ? std::min(maxConcurrency, tbbDefaultNumberThreads) : tbbDefaultNumberThreads;
98 if (maxConcurrency > bcCpus) {
99 Warning(
"RTaskArenaWrapper",
"CPU Bandwith Control Active. Proceeding with %d threads accordingly", bcCpus);
100 maxConcurrency = bcCpus;
102 if (maxConcurrency > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
103 Warning(
"RTaskArenaWrapper",
"tbb::global_control is active, limiting the number of parallel workers"
104 "from this task arena available for execution.");
120 fTBBArena->initialize(tbb::task_arena::attach{});
144std::shared_ptr<ROOT::Internal::RTaskArenaWrapper>
147 static std::weak_ptr<ROOT::Internal::RTaskArenaWrapper> weak_GTAWrapper;
150 const std::lock_guard<std::mutex> lock{
m};
151 if (
auto sp = weak_GTAWrapper.lock()) {
152 if (maxConcurrency && (sp->TaskArenaSize() != maxConcurrency)) {
153 Warning(
"RTaskArenaWrapper",
"There's already an active task arena. Proceeding with the current %d threads",
154 sp->TaskArenaSize());
158 std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> sp;
165 sp = std::make_shared<ROOT::Internal::RTaskArenaWrapper>(maxConcurrency);
167 weak_GTAWrapper = sp;
174 ::Fatal(
"ROOT::Internal::GetGlobalTaskArena",
175 "Unsupported enum value %d", (
int)config);
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
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
int LogicalCPUBandwidthControl()
Returns the available number of logical cores.
std::shared_ptr< ROOT::Internal::RTaskArenaWrapper > GetGlobalTaskArena(unsigned maxConcurrency=0)
Factory function returning a shared pointer to the instance of the global RTaskArenaWrapper.
void EnableThreadSafety()
Enable support for multi-threading within the ROOT code in particular, enables the global mutex to ma...
@ kWholeMachine
Default configuration.
@ kNumConfigs
Number of support IMT semantic configurations.
@ kExistingTBBArena
Use the existing TBB arena.
Marker for attaching to an existing tbb::task_arena.