You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I fail to see how these examples were ever thread safe. The models/base/BC_X_Fitters all hold a single pointer to a TF1 object which is being used to fit. To be thread safe, this TF1 needs to be copied over to NChain copies. However this doesn't guarantee thread safety, since the user could build an unsafe TF1 that when copied is still not thread safe (for example one that uses a method called from a particular object).
I agree, this setup with a pointer to a TF1 is a classic example for not being thread safe. I agree that a user could create an unsafe TF1 but I still think we should make the copies for the NChains such that fast fitters can be thread safe.
I can tackle this. Looking at the code there seems to be a fair amount of copy and paste amongst all the classes that inherit from BCFitter. (They all, for example, have a TF1* fFitFunction.) I can clean this up as well.
OK. This is in my fork, branch reformat. I can submit a pull request... however, I didn't fix the bug int he examples. The classes are all now ostensibly thread-safe (I also fixed parallel_TEST). The examples work fine in nonparallel mode with my changes. But they still break in parallelization because ROOT needs to know about openmp in macro mode. I tried simply including omp.h in the macro, but that didn't work. Either of you know a solution?
As far as the histogram fitter is concerned, I'm all for making copies.
For other cases (user specified models) where thread-safety just isn't possible (because 3rd party code, etc.) - should we add the possibility to explicitly mark a model as not thread-safe? We could add a member function like
virtual bool isThreadSafe() { return true; } // overload to return false if your model isn't thread-safe
And make BAT limit itself to one thread if this doesn't return true.
That's what my code does... it just copies the function.
I don't know if the thread safety variable is necessary. If a user knows his code is not threadsafe, he can simply set the number of threads to 1 through the appropriate environment variable, no? Or turn off parallelization (if he controls the installation).
I don't know if the thread safety variable is necessary. If a user knows his code is not threadsafe, he can simply set the number of threads to 1 through the appropriate environment variable, no?
Yes he can, but is has to be documented - the person who codes the model might not be the only one using it. And even with proper documentation, it's another complication for the user of the model, and another source for errors.
For automated testing it would also make things significantly simpler if different tests didn't need different environment variable settings.
The root macro uses cling, so clang. Clang doesn't support openmp yet
but it's supposed to be there soon. A development branch offered openmp
support for a while.
So until root ships with an openmp-ready cling, the macros won't run
multithreaded.
On 08/31/2015 03:46 PM, greenwald wrote:
OK. This is in my fork, branch |reformat|. I can submit a pull
request... however, I didn't fix the bug int he examples. The classes
are all now ostensibly thread-safe (I also fixed |parallel_TEST|). The
examples work fine in nonparallel mode with my changes. But they still
break in parallelization because ROOT needs to know about openmp in
macro mode. I tried simply including omp.h in the macro, but that
didn't work. Either of you know a solution?
—
Reply to this email directly or view it on GitHub #9 (comment).
The root macro uses cling, so clang. Clang doesn't support openmp yet
...
So until root ships with an openmp-ready cling, the macros won't run
multithreaded.
I don't see why they shouldn't - all BAT code that uses OMP seems to be in source files, not in headers. So Cling should never see it directly - and when Cling calls functions with OMP pragmas, OMP should be used.
Activity
oschulz commentedon Aug 25, 2015
Depends on #40.
greenwald commentedon Aug 26, 2015
I fail to see how these examples were ever thread safe. The models/base/BC_X_Fitters all hold a single pointer to a TF1 object which is being used to fit. To be thread safe, this TF1 needs to be copied over to NChain copies. However this doesn't guarantee thread safety, since the user could build an unsafe TF1 that when copied is still not thread safe (for example one that uses a method called from a particular object).
fredRos commentedon Aug 31, 2015
I agree, this setup with a pointer to a
TF1is a classic example for not being thread safe. I agree that a user could create an unsafeTF1but I still think we should make the copies for the NChains such that fast fitters can be thread safe.greenwald commentedon Aug 31, 2015
I can tackle this. Looking at the code there seems to be a fair amount of copy and paste amongst all the classes that inherit from BCFitter. (They all, for example, have a
TF1* fFitFunction.) I can clean this up as well.greenwald commentedon Aug 31, 2015
OK. This is in my fork, branch
reformat. I can submit a pull request... however, I didn't fix the bug int he examples. The classes are all now ostensibly thread-safe (I also fixedparallel_TEST). The examples work fine in nonparallel mode with my changes. But they still break in parallelization because ROOT needs to know about openmp in macro mode. I tried simply including omp.h in the macro, but that didn't work. Either of you know a solution?oschulz commentedon Aug 31, 2015
As far as the histogram fitter is concerned, I'm all for making copies.
For other cases (user specified models) where thread-safety just isn't possible (because 3rd party code, etc.) - should we add the possibility to explicitly mark a model as not thread-safe? We could add a member function like
And make BAT limit itself to one thread if this doesn't return true.
greenwald commentedon Aug 31, 2015
That's what my code does... it just copies the function.
I don't know if the thread safety variable is necessary. If a user knows his code is not threadsafe, he can simply set the number of threads to 1 through the appropriate environment variable, no? Or turn off parallelization (if he controls the installation).
oschulz commentedon Aug 31, 2015
Yes he can, but is has to be documented - the person who codes the model might not be the only one using it. And even with proper documentation, it's another complication for the user of the model, and another source for errors.
For automated testing it would also make things significantly simpler if different tests didn't need different environment variable settings.
fredRos commentedon Sep 1, 2015
The root macro uses cling, so clang. Clang doesn't support openmp yet
but it's supposed to be there soon. A development branch offered openmp
support for a while.
So until root ships with an openmp-ready cling, the macros won't run
multithreaded.
On 08/31/2015 03:46 PM, greenwald wrote:
oschulz commentedon Sep 1, 2015
I don't see why they shouldn't - all BAT code that uses OMP seems to be in source files, not in headers. So Cling should never see it directly - and when Cling calls functions with OMP pragmas, OMP should be used.
fredRos commentedon Sep 9, 2015
I see your point and agree. In fact the examples now run fine, the problem was in the fast fitter classes and not in root
fredRos commentedon Nov 26, 2015
The last issues with threads should be resolved in #98