Hi, I want to boost the speed of TTree->GetEntry by using multiple threads. My machine has 12 workers and I want to use full of them.
My code usually goes like this:
TFile *f = new TFile(“file.root”);
TTree *t = (TTree *) f->Get(“tree”);
vector *x = 0;
TBranch *b = 0;
t->SetBranchAddress(“x”, &x, &b);
for (int i=0; iGetEntries(); i++){
b->GetEntry();
SomeWork(x);
}
Since there is massive number of entries in my root file, the for loop above takes a lot of time.
So I want to use 12 workers to boost the speed 12 times faster.
With python, I used to deal with this kind of problem using Pool of Multiprocessing.
But that method is not compatible with PyROOT.
I tried C++ version of multithreading with somewhat following:
TFile *f = new TFile(“file.root”);
TTree *t = (TTree *) f->Get(“tree”);
vector *x = 0;
auto foo = [](TTree *t, TBranch *b, vector *x, int entry1, int entry2){
t->SetBranchAddress(“x”, &x, &b);
for (int i=entry1; i<entry2; i++){
b->GetEntry(i);
}
};
TBranch *b1 = 0;
TBranch *b2 = 0;
TBranch *b3 = 0;
TBranch *b4 = 0;
thread th1(foo, t, b1, 0, 99);
thread th2(foo, t, b2, 100, 199);
thread th3(foo, t, b3, 200, 299);
thread th4(foo, t, b4, 300, 399);
th1.join();
th2.join();
th3.join();
th4.join();
And it didn’t work.
Any ideas?? Please help me.
ROOT Version: 6.09/03
Platform: Linux
Compiler: Not Provided