ROOT
master
Reference Guide
Loading...
Searching...
No Matches
mp_parallelHistoFill.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_analysis_parallel
3
/// \notebook -js
4
/// Fill histogram in parallel with a multiprocessing approach
5
/// using TProcessExecutor and TExecutor::MapReduce.
6
///
7
/// \macro_image
8
/// \macro_code
9
///
10
/// \date January 2016
11
/// \author Danilo Piparo
12
13
const
UInt_t
poolSize
= 4U;
14
15
Int_t
mp_parallelHistoFill
()
16
{
17
TDirectory::TContext
ctx{
nullptr
};
// Don't register histograms to the current directory
18
ROOT::TProcessExecutor
pool
(
poolSize
);
19
auto
fillRandomHisto
= [](
int
seed = 0) {
20
TRandom3
rndm
(seed);
21
auto
h
=
new
TH1F
(
"myHist"
,
"Filled in parallel"
, 128, -8, 8);
22
for
(
auto
i :
ROOT
::
TSeqI
(1000000)) {
23
h
->Fill(
rndm
.Gaus(0, 1));
24
}
25
return
h
;
26
};
27
28
auto
seeds
=
ROOT::TSeqI
(23);
29
ROOT::ExecutorUtils::ReduceObjects<TH1F *>
redfunc
;
30
auto
sumRandomHisto
=
pool
.MapReduce(
fillRandomHisto
,
seeds
,
redfunc
);
31
32
auto
c
=
new
TCanvas
();
33
sumRandomHisto
->Draw();
34
return
0;
35
}
c
#define c(i)
Definition
RSha256.hxx:101
h
#define h(i)
Definition
RSha256.hxx:106
Int_t
int Int_t
Signed integer 4 bytes (int)
Definition
RtypesCore.h:59
UInt_t
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition
RtypesCore.h:60
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:360
ROOT::Detail::TRangeCast
Definition
TCollection.h:313
ROOT::ExecutorUtils::ReduceObjects
Merge collection of TObjects.
Definition
PoolUtils.h:35
ROOT::TProcessExecutor
This class provides a simple interface to execute the same task multiple times in parallel,...
Definition
TProcessExecutor.hxx:37
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TDirectory::TContext
TDirectory::TContext keeps track and restore the current directory.
Definition
TDirectory.h:89
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:878
TRandom3
Random number generator class based on M.
Definition
TRandom3.h:27
ROOT
Definition
EExecutionPolicy.hxx:4
ROOT::TSeqI
TSeq< int > TSeqI
Definition
TSeq.hxx:203
tutorials
analysis
parallel
mp_parallelHistoFill.C
ROOTmaster - Reference Guide Generated on Sat Mar 14 2026 14:28:17 (GVA Time) using Doxygen 1.10.0