ROOT
master
Reference Guide
mtbb201_parallelHistoFill.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_multicore
3
/// \notebook
4
/// Parallel fill of a histogram.
5
/// This tutorial shows how a histogram can be filled in parallel
6
/// with a multiprocess approach.
7
///
8
/// \macro_image
9
/// \macro_code
10
///
11
/// \date January 2016
12
/// \author Danilo Piparo.
13
14
const
UInt_t
poolSize = 4U;
15
16
Int_t
mtbb201_parallelHistoFill()
17
{
18
TH1::AddDirectory
(
false
);
19
ROOT::TThreadExecutor
pool(poolSize);
20
auto
fillRandomHisto = [](
int
seed = 0) {
21
TRandom3
rndm(seed);
22
auto
h
=
new
TH1F
(
"myHist"
,
"Filled in parallel"
, 128, -8, 8);
23
for
(
auto
i :
ROOT::TSeqI
(1000000)) {
24
h
->Fill(rndm.Gaus(0, 1));
25
}
26
return
h
;
27
};
28
29
auto
seeds =
ROOT::TSeqI
(23);
30
ROOT::ExecutorUtils::ReduceObjects<TH1F *>
redfunc;
31
auto
sumRandomHisto = pool.MapReduce(fillRandomHisto, seeds, redfunc);
32
33
auto
c
=
new
TCanvas
();
34
sumRandomHisto->Draw();
35
return
0;
36
}
c
#define c(i)
Definition:
RSha256.hxx:101
ROOT::ExecutorUtils::ReduceObjects
Merge collection of TObjects.
Definition:
PoolUtils.h:35
ROOT::TThreadExecutor
This class provides a simple interface to execute the same task multiple times in parallel threads,...
Definition:
TThreadExecutor.hxx:40
ROOT::TSeqI
TSeq< int > TSeqI
Definition:
TSeq.hxx:194
Int_t
int Int_t
Definition:
RtypesCore.h:45
TRandom3
Random number generator class based on M.
Definition:
TRandom3.h:27
h
#define h(i)
Definition:
RSha256.hxx:106
TH1::AddDirectory
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition:
TH1.cxx:1282
UInt_t
unsigned int UInt_t
Definition:
RtypesCore.h:46
TCanvas
The Canvas class.
Definition:
TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition:
TH1.h:575
ROOT::TSeq
A pseudo container class which is a generator of indices.
Definition:
TSeq.hxx:66
tutorials
multicore
mtbb201_parallelHistoFill.C
ROOT master - Reference Guide Generated on Thu Feb 25 2021 12:01:50 (GVA Time) using Doxygen 1.9.0