/// \file /// \ingroup multicore /// Fill histograms in parallel and write them on file. /// This example expresses the parallelism of the mt001_fillHistos.C tutorial /// with multiprocessing techniques. /// /// \macro_code /// /// \author Danilo Piparo Int_t mp001_fillHistos(UInt_t nWorkers = 4) { // Total amount of numbers const UInt_t nNumbers = 20000000U; // We define our work item auto workItem = [nNumbers](UInt_t workerID) { // One generator, file and ntuple per worker TRandom3 workerRndm(workerID); // Change the seed TFile f(Form("myFile_%u.root", workerID), "RECREATE"); TH1F h(Form("myHisto_%u", workerID), "The Histogram", 64, -4, 4); for (UInt_t i = 0; i < nNumbers; ++i) { h.Fill(workerRndm.Gaus()); } h.Write(); return 0; }; // Create the pool of workers TProcPool workers(nWorkers); // Fill the pool with work std::forward_list workerIDs(nWorkers); std::iota(std::begin(workerIDs), std::end(workerIDs), 0); workers.Map(workItem, workerIDs); return 0; }