Passing array to parallel operations in root (multithreading)

I am attempting to find a way to pass a unique array of floats to each thread in a multithread function without having to create a ttree and saving it to file (in the final implementation that will be impractical). I have been looking into using the TProcessExecutor to enable the multithreaded work within Root, however I have yet to find a method that works for passing an array of numbers to it. My vision is to have 32+ threads each working on a separate array of numbers and returning a single float to the initial process. Any ideas or advice of where to go digging would be greatly appreciated!

Hi @inneedofhelp ,
and welcome to the ROOT forum!
Note that for multi-threading (rather than multi-processing) you want TThreadExecutor (rather than TProcessExecutor).

Without any information on the actual usecase, it would seem that the Foreach or Map method is what you are looking for:

#include <ROOT/TThreadExecutor.hxx>
#include <iostream>

int main() {
   ROOT::TThreadExecutor t;
   std::vector<std::vector<int>> vectors{{}, {1}, {1, 2}, {1, 2, 3}};
   t.Foreach([](const std::vector<int> &v) { std::cout << "I got size " << v.size() << '\n'; }, vectors);


Hi Enrico,

I just wanted to say quickly that this was exactly what I was looking for, and was easily adaptable to my use case! Thank you for very much for your help.

1 Like

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