Home | News | Documentation | Download

Multi-threaded fitting

Hello,

I am trying to set up multi-threaded fitting and this post is somewhat a follow up to topic:
[url]Is TH1::Fit thread-safe?
where others have tried to setup parallel fitting with ROOT.

Attached is a “simple” example how I have set up the multi-threaded fitting using the ROOT::Fit::Fitter class (instead of TH1::Fit). The ROOT script works fine as long as I am only using one thread. It works also fine if I use multiple threads and do not actually call the “Fit” function. But if I use multiple threads and call “Fit” then is crashes usually somewhere in the fit classes - not always at the same point though.

So my questions are:
Do I have to do something special/magic to get it to work. … or …
Is ROOT simply not capable of multi-threaded fitting?

Thanks a lot for any help,
Andreas
ParallelFitting.C (7.38 KB)

I’m not sure what is the exact problem in this case, but at least one problem with Fitter is that it creates minimizers through interpreter which is not thread safe and as far as I see Fitter provides no means for the user to provide the minimizer object in thread safe manner. While testing the attached code the following message was generated (at least in a debug-build)

so the described problem might be the cause here as well. Due to the lousy interface of Fitter, I haven’t found a way to fix it easily (or it’s just lousy me, ideas are welcome). But while I examined this now, I noticed that there’s a preprocessor macro
MATH_NO_PLUGIN_MANAGER (see e.g. math/mathcore/src/Factory.cxx)
that controls whether to use the plugin manager. Perhaps that could help (given that you can build ROOT yourself)?

Btw: thanks for the good example file.

Hello!

Thanks a lot for the tip!

While MATH_NO_PLUGIN_MANAGER didn’t really help - I don’t think the alternate code has been tested recently because it does not compile - I found a solution anyway:

Adding a guarding mutex just in front of the plugin manager call in Factory.cxx solcves the problem, and my little example script is now happily fitting :smiley:

I submitted a bug report with the changed file:
sft.its.cern.ch/jira/browse/ROOT-5335

Thanks a lot,
Andreas

By the way, below is an updated version of the parallel fitting example.
If “ROOT” wants to use it as example on how to do multi-threaded fitting you are welcome to do so — obviously you have to fix the bug in Factory.cxx in an upcoming release first…

Ciao,
Andreas
ParallelFitting.C (8.36 KB)