Logo ROOT   6.08/07
Reference Guide
TImplicitMT.cxx
Go to the documentation of this file.
1 // @(#)root/thread:$Id$
2 // // Author: Enric Tejedor Saavedra 03/12/15
3 //
4 /*************************************************************************
5  * Copyright (C) 1995-2015, 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 // TImplicitMT //
15 // //
16 // This file implements the methods to enable, disable and check the //
17 // status of the global implicit multi-threading in ROOT. //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 
21 #include "TError.h"
22 #include "TThread.h"
23 
24 #include <atomic>
25 #include "tbb/task_scheduler_init.h"
26 
27 
28 static tbb::task_scheduler_init &GetScheduler()
29 {
30  static tbb::task_scheduler_init scheduler(tbb::task_scheduler_init::deferred);
31  return scheduler;
32 }
33 
34 static bool &GetImplicitMTFlag()
35 {
36  static bool enabled = false;
37  return enabled;
38 }
39 
40 static std::atomic_int &GetParBranchProcessingCount()
41 {
42  static std::atomic_int count(0);
43  return count;
44 }
45 
46 static std::atomic_int &GetParTreeProcessingCount()
47 {
48  static std::atomic_int count(0);
49  return count;
50 }
51 
52 extern "C" void ROOT_TImplicitMT_EnableImplicitMT(UInt_t numthreads)
53 {
54  if (!GetImplicitMTFlag()) {
55  if (!GetScheduler().is_active()) {
57 
58  if (numthreads == 0)
59  numthreads = tbb::task_scheduler_init::automatic;
60 
61  GetScheduler().initialize(numthreads);
62  }
63  GetImplicitMTFlag() = true;
64  }
65  else {
66  ::Warning("ROOT_TImplicitMT_EnableImplicitMT", "Implicit multi-threading is already enabled");
67  }
68 };
69 
71 {
72  if (GetImplicitMTFlag()) {
73  GetImplicitMTFlag() = false;
74  }
75  else {
76  ::Warning("ROOT_TImplicitMT_DisableImplicitMT", "Implicit multi-threading is already disabled");
77  }
78 };
79 
81 {
82  return GetImplicitMTFlag();
83 };
84 
86 {
88 };
89 
91 {
93 };
94 
96 {
97  return GetParBranchProcessingCount() > 0;
98 };
99 
101 {
103 };
104 
106 {
108 };
109 
111 {
112  return GetParTreeProcessingCount() > 0;
113 };
void ROOT_TImplicitMT_DisableParTreeProcessing()
static void Initialize()
Initialize the Thread package.
Definition: TThread.cxx:296
static bool & GetImplicitMTFlag()
Definition: TImplicitMT.cxx:34
bool ROOT_TImplicitMT_IsParBranchProcessingEnabled()
Definition: TImplicitMT.cxx:95
void ROOT_TImplicitMT_EnableParTreeProcessing()
static std::atomic_int & GetParBranchProcessingCount()
Definition: TImplicitMT.cxx:40
bool ROOT_TImplicitMT_IsImplicitMTEnabled()
Definition: TImplicitMT.cxx:80
static std::atomic_int & GetParTreeProcessingCount()
Definition: TImplicitMT.cxx:46
static tbb::task_scheduler_init & GetScheduler()
Definition: TImplicitMT.cxx:28
unsigned int UInt_t
Definition: RtypesCore.h:42
void Warning(const char *location, const char *msgfmt,...)
void ROOT_TImplicitMT_DisableImplicitMT()
Definition: TImplicitMT.cxx:70
bool ROOT_TImplicitMT_IsParTreeProcessingEnabled()
void ROOT_TImplicitMT_DisableParBranchProcessing()
Definition: TImplicitMT.cxx:90
void ROOT_TImplicitMT_EnableParBranchProcessing()
Definition: TImplicitMT.cxx:85
void ROOT_TImplicitMT_EnableImplicitMT(UInt_t numthreads)
Definition: TImplicitMT.cxx:52