# How to make sure that reading a tree is really parallel?

**URL:** <https://root-forum.cern.ch/t/how-to-make-sure-that-reading-a-tree-is-really-parallel/29256>\
**Category:** ROOT\
**Created:** [June 5, 2018, 12:18pm UTC](https://root-forum.cern.ch/t/how-to-make-sure-that-reading-a-tree-is-really-parallel/29256 "2018-06-05T12:18:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanysha](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tanysha/32/32811_2.png) [@Tanysha](https://root-forum.cern.ch/u/Tanysha)\
**Post date:** [June 5, 2018, 12:18pm UTC](https://root-forum.cern.ch/t/how-to-make-sure-that-reading-a-tree-is-really-parallel/29256/1 "2018-06-05T12:18:31Z")

</div>

Dear experts!  
I use the ROOT::EnableImplicitMT() and GetEntry() function when reading a tree. But the time of the macro is the same as in the non-parallel case.

How can I make sure that reading a tree is distributed over several threads and that these threads run in parallel? Is there a method that shows the actual number of threads in the ROOT environment when the macro is executed.

* * *

_ROOT Version:_ 6.13  
_Platform:_ LINUX  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [June 5, 2018, 2:05pm UTC](https://root-forum.cern.ch/t/how-to-make-sure-that-reading-a-tree-is-really-parallel/29256/2 "2018-06-05T14:05:03Z")

</div>

Hi,  
you can ask ROOT how big the thread-pool that it is using is with `ROOT::GetImplicitMTPoolSize()`.  
To verify that it is _actually_ used when you call `TTree::GetEntry` you can monitor the core usage of your machine during execution, e.g. with `htop`, or the `%CPU` field when you run your application through `/usr/bin/time`, or you can run the application through `gdb`, add a breakpoint in `TTree.cxx:5483` (the inside of the `mapFunction` which is distributed between workers) and check if you hit it from multiple threads, or again from `gdb` you can just break the application with `ctrl+C` at random times during the event loop and check how many threads are working and what they are doing with `thread apply all backtrace 20`.

Hope this helps!  
Enrico

---

<div class="post-metadata">

**Author:** ![Tanysha](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tanysha/32/32811_2.png) [@Tanysha](https://root-forum.cern.ch/u/Tanysha)\
**Post date:** [June 6, 2018, 1:19pm UTC](https://root-forum.cern.ch/t/how-to-make-sure-that-reading-a-tree-is-really-parallel/29256/3 "2018-06-06T13:19:41Z")

</div>

Thank you!  
I tried to call ROOT::GetImplicitMTPoolSize(). The result is the same as the number of determinated threads in ROOT::EnableImplicit(nthreads) . But it is unclear whether these threads are running in parallel or they are executed sequentially one after the other?  
The execution time of parallel and non-parallel macros coincide. Therefore, probably, though the task is divided into several threads, but they are executed sequentially.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [June 6, 2018, 1:32pm UTC](https://root-forum.cern.ch/t/how-to-make-sure-that-reading-a-tree-is-really-parallel/29256/4 "2018-06-06T13:32:29Z")

</div>

Hi Tanysha,  
it’s improbable that threads execute tasks one after the other.  
It’s more likely that

1. most of your runtime is spent outside of `TTree::GetEntry`, so parallelizing that is not helping you
2. each call to `TTree::GetEntry` does too little work for parallelization to be effective: for example, you have only one or two branches in the TTree
3. a bug in ROOT prevents parallelization: to exclude this is the case you can try running on lxplus with the latest ROOT: `source /cvmfs/sft.cern.ch/lcg/views/dev3/latest/x86_64-centos7-gcc7-opt/setup.sh`

You can use one of the methods I described in my previous post to check what’s going on.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [June 20, 2018, 1:32pm UTC](https://root-forum.cern.ch/t/how-to-make-sure-that-reading-a-tree-is-really-parallel/29256/5 "2018-06-20T13:32:31Z")

</div>

Closed on June 20, 2018, 1:32pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
