Parallel fill of a histogram.
This tutorial shows how a histogram can be filled in parallel with a multithreaded approach. The difference with the multiprocess case, see mp201, is that here we cannot count on the copy-on-write mechanism, but we rather need to protect the histogram resource with a TThreadedObject class. The result of the filling is monitored with the SnapshotMerge method. This method is not thread safe: in presence of ROOT histograms, the system will not crash but the result is not uniquely defined.
{
for (
auto i :
ROOT::TSeqI(1000000)) {
}
};
std::vector<std::thread>
pool;
std::this_thread::sleep_for(std::chrono::duration<double, std::nano>(500));
auto h =
ts_h.SnapshotMerge();
std::cout <<
"Entries for the snapshot " <<
h->GetEntries() << std::endl;
}
};
}
t.join();
std::cout <<
"Entries for the total sum " <<
sumRandomHisto->GetEntries() << std::endl;
return 0;
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
A wrapper to make object instances thread private, lazily.
Random number generator class based on M.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
void EnableThreadSafety()
Enable support for multi-threading within the ROOT code in particular, enables the global mutex to ma...
- Date
- January 2016
- Author
- Danilo Piparo
Definition in file mt_parallelHistoFill.C.