Thank you. I also tried removing the TTree stuffs, but it also gave me error message. Did this means both TFile and TTree are not thread safe? Do you know how to make them safe?
Yes, both TTree and TFile are not thread safe. And I suggest not to parallelize a file writing task even if they are thread safe. Writing to files in parallel will cause random writes to disk and lead to bad performance.
The reason why I tried to use OpenMP for multi-processing my data is that I want to speed up the analysis work since there are many runs of experimental data files to be analyzed. And each experimental data file needs to be converted to a root file. So I think multi-process the for loop will be faster than the traditional processing. Do you have any idea about this?
You might want to use PROOF. If you could afford doing the analysis in parallel but writing the data in serial. You use the RDataFrame interface, which is thread safe (This should be faster than PROOF if you are not working with >100GB):
ROOT::EnableImplicitMT(); // Enable implicit parallel computing
auto rdf = ROOT::RDataFrame("ntuple", "data/*.root");
// Do your analysis here. For example:
auto h1 = rdf.Histo1D("eV");
auto fAna = make_shared<TFile>("plot1.root", "RECREATE");
auto TTree *tAna= make_shared<TTree>("tAna", "tree for data analysis");
tAna->Fill();
fAna->Write();
// Another analysis
auto h1 = rdf.Histo1D("var2");
etc...
Yes, concurrent processing should be faster than single-core processing, even if some locks are taken sometimes. Scaling should be fine as long as you spend most of the computing resources on logic that is trivially parallel.