Logo ROOT   6.07/09
Reference Guide
mtbb201_parallelHistoFill.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_multicore
3 /// Parallel fill of a histogram.
4 /// This tutorial shows how a histogram can be filled in parallel
5 /// with a multiprocess approach.
6 ///
7 /// \macro_image
8 /// \macro_code
9 ///
10 /// \author Danilo Piparo.
11 /// \date January 2016
12 
13 const UInt_t poolSize = 4U;
14 
15 Int_t mtbb201_parallelHistoFill()
16 {
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);
31  auto sumRandomHisto = pool.MapReduce(fillRandomHisto, seeds, redfunc);
32 
33  auto c = new TCanvas();
34  sumRandomHisto->Draw();
35  return 0;
36 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3127
Random number generator class based on M.
Definition: TRandom3.h:29
return c
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:302
TH1 * h
Definition: legend2.C:5
int Int_t
Definition: RtypesCore.h:41
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition: TH1.cxx:1220
Merge collection of TObjects.
Definition: PoolUtils.h:63
unsigned int UInt_t
Definition: RtypesCore.h:42
The Canvas class.
Definition: TCanvas.h:41
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
Definition: TROOT.cxx:498
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
TSeq< int > TSeqI
Definition: TSeq.hxx:164