Hi Rooters,
I am probably doing this backwards but here goes.
I went on a quest to try to use OpenMP compiling with gcc version 4.9.3 with and linking the root libraries (Probably barbaric and someone will probably quickly point out that I am doing it wrong for what I want to do) trying to parallelise few nested loops containing a Tree->Draw() with a TCut, in essence I have these lines in a nested for loop.
I first start to load the MyTree in a non parallel block then try to clone MyTree in the first instance of the parallel block using a #pragma omp critical block to clone it.
MyTree->Draw("SomeVariable >> htemp_MyTree", OptiCut);
TH1F *htemp_MyTree = (TH1F*)gPad->GetPrimitive("htemp_MyTree");
ResultMyTree = htemp_MyTree->GetEntries() * htemp_MyTree->GetMean();
The issue is, even if I try to create multiple “independent” copies of the original MyTree into memory by cloning it locally (I suppose here it does what I expect it to do, probably it’s where it fails miserably) I find myself with apparent non thread safeness, maybe due to the structure of the Tree itself because it somehow still knows where it comes from and also maybe eventually the pad itself is non thread safe. Though honestly on this one I am clueless.
I write the results to an output TTree but using the #pragma omp critical for the Write() seems to work decently well (each thread creates its own tree into the output TFile, probably someone would propose a merge of the independent TTrees and if so, even if that’s not the main concern, I would still be grateful for any additional information).
Here are my “simple” questions :
Is it possible to parallelise nested for loops on a Tree->Draw(“SomeVariable >> htemp_Tree”,TCut)?
If so how should I do it or where should I look for it, is there any example anywhere?
Is there a way at the end of the Multi-threading to merge the TTrees before writing them to my TFile?
I am aware of the existence of TThread but I am 100% sure I didn’t understand exactly how to deal with these and more especially how I would do to collapse a nested for loop.
Thanks a lot to anyone taking time to read this and eventually able to help.
Cheers,
Geoffrey.