20 TimerRAII(
const char *meta): fMeta(meta) {
25 std::cout << fMeta <<
" - real time elapsed " << fTimer.RealTime() <<
"s" << std::endl;
36 const UInt_t nNumbers = 20000000U;
41 for (
UInt_t i = 0; i <
n; ++i) ntuple.
Fill(rndm.Gaus());
48 TFile ofile(
"mt101_singleCore.root",
"RECREATE");
49 TNtuple randomNumbers(
"singleCore",
"Random Numbers",
"r");
53 TimerRAII
t(
"Sequential execution");
55 randomNumbers.Write();
69 TFile ofile(
Form(
"mt101_multiCore_%u.root", workerID),
"RECREATE");
70 TNtuple workerRandomNumbers(
"multiCore",
"Random Numbers",
"r");
71 fillRandom(workerRandomNumbers, workerRndm, workSize);
72 workerRandomNumbers.Write();
76 std::vector<std::thread> workers;
80 TimerRAII
t(
"Parallel execution");
83 const auto workSize = nNumbers / nWorkers;
86 for (
UInt_t workerID = 0; workerID < nWorkers; ++workerID) {
87 workers.emplace_back(workItem, workerID, workSize);
91 for (
auto && worker : workers) worker.join();
Random number generator class based on M.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
A simple TTree restricted to a list of float variables only.
char * Form(const char *fmt,...)
void fillRandom(std::vector< T > &randomV, const rangeType theRangeType)
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
virtual Int_t Fill()
[fNvar] Array of variables