Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
mtbb001_fillHistos.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_multicore
3/// \notebook
4/// Fill histograms in parallel and write them on file.
5/// This example expresses the parallelism of the mt001_fillHistos.C tutorial
6/// with multiprocessing techniques.
7///
8/// \macro_code
9///
10/// \date January 2016
11/// \author Danilo Piparo
12
13// Total amount of numbers
14const UInt_t nNumbers = 20000000U;
15
16// The number of workers
17const UInt_t nThreads = 4U;
18
19Int_t mtbb001_fillHistos()
20{
21 // We define our work item
22 auto workItem = [](UInt_t workerID) {
23 // One generator, file and ntuple per worker
24 TRandom3 workerRndm(workerID); // Change the seed
25 TFile f(Form("myFile_mtbb001_%u.root", workerID), "RECREATE");
26 TH1F h(Form("myHisto_%u", workerID), "The Histogram", 64, -4, 4);
27 for (UInt_t i = 0; i < nNumbers; ++i) {
28 h.Fill(workerRndm.Gaus());
29 }
30 h.Write();
31 return 0;
32 };
33
34 // Create the pool of threads
35 ROOT::TThreadExecutor pool(nThreads);
36
37 // Fill the pool with work
38 pool.Map(workItem, ROOT::TSeqI(nThreads));
39 return 0;
40}
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
A pseudo container class which is a generator of indices.
Definition TSeq.hxx:67
This class provides a simple interface to execute the same task multiple times in parallel threads,...
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:622
Random number generator class based on M.
Definition TRandom3.h:27