Logo ROOT   6.18/05
Reference Guide
imt001_parBranchProcessing.C File Reference

Detailed Description

View in nbviewer Open in SWAN 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.

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
auto file = TFile::Open("http://root.cern.ch/files/h1/dstarmb.root");
// Get the tree
auto tree = file->Get<TTree>("h42");
const auto nEntries = tree->GetEntries();
// Read the branches in parallel.
// Note that the interface does not change, the parallelisation is internal
for (auto i : ROOT::TSeqUL(nEntries)) {
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 (auto i : ROOT::TSeqUL(nEntries)) {
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 (auto i : ROOT::TSeqUL(nEntries)) {
tree->GetEntry(i); // sequential read
}
return 0;
}
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3980
A TTree represents a columnar dataset.
Definition: TTree.h:71
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
Definition: TROOT.cxx:579
void DisableImplicitMT()
Disables the implicit multi-threading in ROOT (see EnableImplicitMT).
Definition: TROOT.cxx:596
Definition: file.py:1
Definition: tree.py:1
Date
26/09/2016
Author
Enric Tejedor

Definition in file imt001_parBranchProcessing.C.