Imt 0 0 1_Par Branch Processing

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.

Author: Enric Tejedor
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Thursday, February 25, 2021 at 09:30 AM.

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.

In [1]:
int nthreads = 4;
ROOT::EnableImplicitMT(nthreads);

Open the file containing the tree

In [2]:
auto file = TFile::Open("http://root.cern.ch/files/h1/dstarmb.root");

Get the tree

In [3]:
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

In [4]:
for (auto i : ROOT::TSeqUL(nEntries)) {
   tree->GetEntry(i); // parallel read
}

Imt parallelisation can be disabled for a specific tree

In [5]:
tree->SetImplicitMT(false);

If now getentry is invoked on the tree, the reading is sequential

In [6]:
for (auto i : ROOT::TSeqUL(nEntries)) {
   tree->GetEntry(i); // sequential read
}

Parallel reading can be re-enabled

In [7]:
tree->SetImplicitMT(true);

Imt can be also disabled globally. As a result, no tree will run GetEntry in parallel

In [8]:
ROOT::DisableImplicitMT();

This is still sequential: the global flag is disabled, even if the flag for this particular tree is enabled

In [9]:
for (auto i : ROOT::TSeqUL(nEntries)) {
   tree->GetEntry(i); // sequential read
}

return 0;

Draw all canvases

In [10]:
gROOT->GetListOfCanvases()->Draw()