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
38/// tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow
39/// to forward declare tbb::task_arena without forward declaring tbb::interface7
40
41namespace ROOT {
42
43class ROpaqueTaskArena;
44
45namespace Internal {
46
47////////////////////////////////////////////////////////////////////////////////
48/// Returns the available number of logical cores.
49///
50/// - Checks if there is CFS bandwidth control in place (linux, via cgroups,
51/// assuming standard paths)
52/// - Otherwise, returns the number of logical cores provided by
53/// std::thread::hardware_concurrency()
54////////////////////////////////////////////////////////////////////////////////
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Wrapper for tbb::task_arena.
60///
61/// Necessary in order to keep tbb away from ROOT headers.
62/// This class is thought out to be used as a singleton.
63////////////////////////////////////////////////////////////////////////////////
65public:
66 ~RTaskArenaWrapper(); // necessary to set size back to zero
67 static unsigned TaskArenaSize(); // A static getter lets us check for RTaskArenaWrapper's existence
69 struct Attach {}; ///< Marker for attaching to an existing tbb::task_arena
70
73
74private:
75 friend std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(unsigned, ROOT::EIMTConfig);
76 std::unique_ptr<ROOT::ROpaqueTaskArena> fTBBArena;
77 static unsigned fNWorkers;
78};
79
80
81////////////////////////////////////////////////////////////////////////////////
82/// Factory function returning a shared pointer to the instance of the global
83/// RTaskArenaWrapper.
84///
85/// Allows for reinstantiation of the global RTaskArenaWrapper once all the
86/// references to the previous one are gone and the object destroyed.
87////////////////////////////////////////////////////////////////////////////////
88std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(unsigned maxConcurrency = 0);
89std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(ROOT::EIMTConfig config);
90
91} // namespace Internal
92} // namespace ROOT
93
94#endif // R__USE_IMT
95#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.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
EIMTConfig
Definition TROOT.h:83
Marker for attaching to an existing tbb::task_arena.