Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
mtbb_parallelHistoFill.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_analysis
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/// \date January 2016
11/// \author Danilo Piparo.
12
13const UInt_t poolSize = 4U;
14
15Int_t mtbb_parallelHistoFill()
16{
17 TH1::AddDirectory(false);
18 ROOT::TThreadExecutor 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);
30 auto sumRandomHisto = pool.MapReduce(fillRandomHisto, seeds, redfunc);
31
32 auto c = new TCanvas();
33 sumRandomHisto->Draw();
34 return 0;
35}
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
Merge collection of TObjects.
Definition PoolUtils.h:35
This class provides a simple interface to execute the same task multiple times in parallel threads,...
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:634
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition TH1.cxx:1281
Random number generator class based on M.
Definition TRandom3.h:27
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TSeq< int > TSeqI
Definition TSeq.hxx:203