Logo ROOT   6.18/05
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
14const UInt_t poolSize = 4U;
15
16Int_t mtbb201_parallelHistoFill()
17{
19 TH1::AddDirectory(false);
20 ROOT::TThreadExecutor pool(poolSize);
21 auto fillRandomHisto = [](int seed = 0) {
22 TRandom3 rndm(seed);
23 auto h = new TH1F("myHist", "Filled in parallel", 128, -8, 8);
24 for (auto i : ROOT::TSeqI(1000000)) {
25 h->Fill(rndm.Gaus(0, 1));
26 }
27 return h;
28 };
29
30 auto seeds = ROOT::TSeqI(23);
32 auto sumRandomHisto = pool.MapReduce(fillRandomHisto, seeds, redfunc);
33
34 auto c = new TCanvas();
35 sumRandomHisto->Draw();
36 return 0;
37}
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
Merge collection of TObjects.
Definition: PoolUtils.h:35
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
This class provides a simple interface to execute the same task multiple times in parallel,...
The Canvas class.
Definition: TCanvas.h:31
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:571
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition: TH1.cxx:1225
Random number generator class based on M.
Definition: TRandom3.h:27
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
Definition: TROOT.cxx:548
TSeq< int > TSeqI
Definition: TSeq.hxx:194