Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RTaskArena.hxx
Go to the documentation of this file.
1// @(#)root/thread:$Id$
2// // Author: Xavier Valls Pla 08/05/20
3//
4/*************************************************************************
5 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// RTaskArena //
15// //
16// This file implements the method to initialize and retrieve ROOT's //
17// global task arena, together with a method to check for active //
18// CPU bandwith control, and a class to wrap the tbb task arena with //
19// the purpose of keeping tbb off the installed headers //
20// //
21//////////////////////////////////////////////////////////////////////////
22
23#ifndef ROOT_RTaskArena
24#define ROOT_RTaskArena
25
26#include "RConfigure.h"
27#include "TROOT.h" // For ROOT::EIMTConfig
28#include <memory>
29
30// exclude in case ROOT does not have IMT support
31#ifndef R__USE_IMT
32// No need to error out for dictionaries.
33# if !defined(__ROOTCLING__) && !defined(G__DICTIONARY)
34# error "Cannot use ROOT::Internal::RTaskArenaWrapper if build option imt=OFF."
35# endif
36#else
37
38namespace ROOT {
39
40class ROpaqueTaskArena;
41
42namespace Internal {
43
44////////////////////////////////////////////////////////////////////////////////
45/// Returns the available number of logical cores.
46///
47/// - Checks if there is CFS bandwidth control in place (linux, via cgroups,
48/// assuming standard paths)
49/// - Otherwise, returns the number of logical cores provided by
50/// std::thread::hardware_concurrency()
51////////////////////////////////////////////////////////////////////////////////
53
54////////////////////////////////////////////////////////////////////////////////
55/// Wrapper for tbb::task_arena.
56///
57/// Necessary in order to keep tbb away from ROOT headers.
58/// This class is thought out to be used as a singleton.
59///
60/// tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow
61/// to forward declare tbb::task_arena without forward declaring tbb::interface7
62////////////////////////////////////////////////////////////////////////////////
64public:
65 ~RTaskArenaWrapper(); // necessary to set size back to zero
66 static unsigned TaskArenaSize(); // A static getter lets us check for RTaskArenaWrapper's existence
68 struct Attach {}; ///< Marker for attaching to an existing tbb::task_arena
69
72
73private:
74 friend std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(unsigned, ROOT::EIMTConfig);
75 std::unique_ptr<ROOT::ROpaqueTaskArena> fTBBArena;
76 static unsigned fNWorkers;
77};
78
79
80////////////////////////////////////////////////////////////////////////////////
81/// Factory function returning a shared pointer to the instance of the global
82/// RTaskArenaWrapper.
83///
84/// Allows for reinstantiation of the global RTaskArenaWrapper once all the
85/// references to the previous one are gone and the object destroyed.
86////////////////////////////////////////////////////////////////////////////////
87std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(unsigned maxConcurrency = 0);
88std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(ROOT::EIMTConfig config);
89
90} // namespace Internal
91} // namespace ROOT
92
93#endif // R__USE_IMT
94#endif // ROOT_RTaskArena
Wrapper for tbb::task_arena.
friend std::shared_ptr< ROOT::Internal::RTaskArenaWrapper > GetGlobalTaskArena(unsigned, ROOT::EIMTConfig)
ROOT::ROpaqueTaskArena & Access()
Provides access to the wrapped tbb::task_arena.
RTaskArenaWrapper(unsigned maxConcurrency=0)
Initializes the tbb::task_arena within RTaskArenaWrapper.
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.
Namespace for new ROOT classes and functions.
EIMTConfig
Definition TROOT.h:83
Marker for attaching to an existing tbb::task_arena.