I want to run a simulation for a large number of events and it generates a data file but it takes time to generate.
so can i use multithreding to generate a large number of data from a model (code is written in ROOT) .
if yes, how can i do this, do i need to make changes in ROOT installation or can i do it directly by writing some lines of code in my code.
any type of help will be appreciated.
Thanks in advance !
Hi @priyanshu-gif ,
this strictly depends on how the code was written exactly.
Some parts of ROOT use multi-threading under the hood if you call ROOT::EnableImplicitMT() (see linked docs), and ROOT offers facilities to parallelize your own code, e.g. TThreadExecutor, as well as interfaces that can do data generation using multi-threading (RDataFrame).
Thanks for your reply!
yes, in my code, i have written some equations as a function and drawing that function along with this , i am writing the a file that calculates the output of those equation for a large number of events (for now done for 10k events).
but i want to generate this file with multi threading because i want to generate this file for 1 lakh or 10 lakh events.
so can you please help me with this. actually i don’t this multi threading in ROOT. what lines of code i can write in my code so it will run in multi threading mode.
For example if you have a function that you can call as
myFunction() and it returns a generated sample, you can use RDataFrame to generate a dataset with the samples like this:
ROOT::EnableImplicitMT(); // enable multi-threading
ROOT::RDataFrame df(10000); // a dataframe with 10k events
// this "snapshots" (i.e. writes) the contents of the dataframe,
// which is 10k entries with the output of `myFunction` stored in column "sample"
df.Define("sample", myFunction).Snapshot("mytree", "myfile.root");
In general how you run something on multiple threads really depends on the exact usecase, but I hope that can give you an idea.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.