Skip to content

histogramfitter exampler not thread safe #9

Closed

Description

@fredRos

Are other examples affected? What about the other fast fitters?

Activity

  1. self-assigned this
    on Oct 6, 2014
  2. added this to the 1.0 milestone on Oct 6, 2014
  3. oschulz commented on Aug 25, 2015

    @oschulz
    Member

    Depends on #40.

  4. greenwald commented on Aug 26, 2015

    @greenwald
    Contributor

    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).

  5. fredRos commented on Aug 31, 2015

    @fredRos
    ContributorAuthor

    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.

  6. greenwald commented on Aug 31, 2015

    @greenwald
    Contributor

    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.

  7. greenwald commented on Aug 31, 2015

    @greenwald
    Contributor

    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?

  8. oschulz commented on Aug 31, 2015

    @oschulz
    Member

    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.

  9. greenwald commented on Aug 31, 2015

    @greenwald
    Contributor

    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).

  10. oschulz commented on Aug 31, 2015

    @oschulz
    Member

    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.

  11. fredRos commented on Sep 1, 2015

    @fredRos
    ContributorAuthor

    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).

  12. oschulz commented on Sep 1, 2015

    @oschulz
    Member

    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.

  13. fredRos commented on Sep 9, 2015

    @fredRos
    ContributorAuthor

    So Cling should never see it directly - and when Cling calls functions with OMP pragmas, OMP should be used.

    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

  14. fredRos commented on Nov 26, 2015

    @fredRos
    ContributorAuthor

    The last issues with threads should be resolved in #98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions