Logo ROOT   6.08/07
Reference Guide
imt001_parBranchProcessing.C File Reference

Detailed Description

Demonstrate how to activate and use the implicit parallelisation of TTree::GetEntry.

Such parallelisation creates one task per top-level branch of the tree being read. In this example, most of the branches are floating point numbers, which are very fast to read. This parallelisation can be used, though, on bigger trees with many (complex) branches, which are more likely to benefit from speedup gains.

/// \date 26/09/2016
int imt001_parBranchProcessing()
{
// First enable implicit multi-threading globally, so that the implicit parallelisation is on.
// The parameter of the call specifies the number of threads to use.
int nthreads = 4;
// Open the file containing the tree
TFile *file = TFile::Open("http://root.cern.ch/files/h1/dstarmb.root");
// Get the tree
TTree *tree = nullptr;
file->GetObject<TTree>("h42", tree);
// Read the branches in parallel.
// Note that the interface does not change, the parallelisation is internal
for (Long64_t i = 0; i < tree->GetEntries(); ++i) {
tree->GetEntry(i); // parallel read
}
// IMT parallelisation can be disabled for a specific tree
tree->SetImplicitMT(false);
// If now GetEntry is invoked on the tree, the reading is sequential
for (Long64_t i = 0; i < tree->GetEntries(); ++i) {
tree->GetEntry(i); // sequential read
}
// Parallel reading can be re-enabled
tree->SetImplicitMT(true);
// IMT can be also disabled globally.
// As a result, no tree will run GetEntry in parallel
// This is still sequential: the global flag is disabled, even if the
// flag for this particular tree is enabled
for (Long64_t i = 0; i < tree->GetEntries(); ++i) {
tree->GetEntry(i); // sequential read
}
return 0;
}
Author
Enric Tejedor

Definition in file imt001_parBranchProcessing.C.