Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
mp201_parallelHistoFill.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_multicore
3 /// \notebook -js
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 mp201_parallelHistoFill()
17 {
18  TH1::AddDirectory(false);
19  ROOT::TProcessExecutor 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 }