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 <memory>
28
29// exclude in case ROOT does not have IMT support
30#ifndef R__USE_IMT
31// No need to error out for dictionaries.
32# if !defined(__ROOTCLING__) && !defined(G__DICTIONARY)
33# error "Cannot use ROOT::Internal::RTaskArenaWrapper if build option imt=OFF."
34# endif
35#else
36
37/// tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow
38/// to forward declare tbb::task_arena without forward declaring tbb::interface7
39
40namespace ROOT {
41
42class ROpaqueTaskArena;
43
44namespace Internal {
45
46////////////////////////////////////////////////////////////////////////////////
47/// Returns the available number of logical cores.
48///
49/// - Checks if there is CFS bandwidth control in place (linux, via cgroups,
50/// assuming standard paths)
51/// - Otherwise, returns the number of logical cores provided by
52/// std::thread::hardware_concurrency()
53////////////////////////////////////////////////////////////////////////////////
55
56
57////////////////////////////////////////////////////////////////////////////////
58/// Wrapper for tbb::task_arena.
59///
60/// Necessary in order to keep tbb away from ROOT headers.
61/// This class is thought out to be used as a singleton.
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
68private:
69 RTaskArenaWrapper(unsigned maxConcurrency = 0);
70 friend std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(unsigned maxConcurrency);
71 std::unique_ptr<ROOT::ROpaqueTaskArena> fTBBArena;
72 static unsigned fNWorkers;
73};
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// Factory function returning a shared pointer to the instance of the global
78/// RTaskArenaWrapper.
79///
80/// Allows for reinstantiation of the global RTaskArenaWrapper once all the
81/// references to the previous one are gone and the object destroyed.
82////////////////////////////////////////////////////////////////////////////////
83std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(unsigned maxConcurrency = 0);
84
85} // namespace Internal
86} // namespace ROOT
87
88#endif // R__USE_IMT
89#endif // ROOT_RTaskArena
Wrapper for tbb::task_arena.
ROOT::ROpaqueTaskArena & Access()
Provides access to the wrapped tbb::task_arena.
friend std::shared_ptr< ROOT::Internal::RTaskArenaWrapper > GetGlobalTaskArena(unsigned maxConcurrency)
Factory function returning a shared pointer to the instance of the global 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.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.