const UInt_t nNumbers = 20000000U; const UInt_t nWorkers = 4U; const auto workSize = nNumbers / nWorkers; %%cpp -d void fillRandom(TNtuple &ntuple, TRandom3 &rndm, UInt_t n) { for (auto i : ROOT::TSeqI(n)) ntuple.Fill(rndm.Gaus()); } gROOT->SetBatch(); TRandom3 rndm(1); TFile ofile("mt101_singleCore.root", "RECREATE"); TNtuple randomNumbers("singleCore", "Random Numbers", "r"); fillRandom(randomNumbers, rndm, nNumbers); randomNumbers.Write(); ofile.Close(); ROOT::EnableThreadSafety(); auto workItem = [](UInt_t workerID) { // One generator, file and ntuple per worker TRandom3 workerRndm(workerID); // Change the seed TFile ofile(Form("mt101_multiCore_%u.root", workerID), "RECREATE"); TNtuple workerRandomNumbers("multiCore", "Random Numbers", "r"); fillRandom(workerRandomNumbers, workerRndm, workSize); workerRandomNumbers.Write(); return 0; }; std::vector workers; for (auto workerID : ROOT::TSeqI(nWorkers)) { workers.emplace_back(workItem, workerID); } for (auto &&worker : workers) worker.join(); return 0; gROOT->GetListOfCanvases()->Draw()