Histogram fit with multithreading

Dear experts,

I recently ran into these two problems when doing a fit with multithreading. I’m not sure if they’re kind of related so I’m just putting them under this same topic. I’m sorry if they turn out unrelated.

  1. In TH1 histogram fit, the option “I” produces errors when implicit MT is enabled. The error produced can be kind of random. But it works just fine in single thread.
void test0() {
  ROOT::EnableImplicitMT();

  for (int i = 0; i < 1000; i++)
  {
    TH1D h{"h", "h", 100, -5, 5};

    for (int j = 0; j < 1000; j++)
      h.Fill(gRandom->Gaus());

    // Histogram fit option "I" produces errors with implicit MT enabled
    h.Fit("gaus", "IQ0", "", -5, 5);
  }
}

  1. Fit doesn’t seem to work well for me in RDataFrame with implicit MT enabled, even without option “I”. The following code would again give kind of random errors, but works well in a single thread.
void test() {
  ROOT::EnableImplicitMT();

  ROOT::RDataFrame df(100);
  auto df2 = df
    .DefineSlotEntry("h", [] (unsigned int slot, ULong64_t entry)
        {
          TString name{"h_"};
          name += std::to_string(entry);

          TH1D h{name, name, 100, -5, 5};

          for (int i = 0; i < 1000; i++)
            h.Fill(gRandom->Gaus());

          return h;
        }, {})
    .DefineSlotEntry("fGaus", [] (unsigned int slot, ULong64_t entry, TH1D &h)
        {
          TString name{"fGaus_"};
          name += std::to_string(entry);

          TF1 fGaus{name, "[0] * TMath::Gaus(x, [1], [2])", -5., 5.};
          fGaus.SetParameters(40, 0, 1);

          h.Fit(&fGaus, "Q0", "", -5, 5);

          return fGaus;
        }, {"h"});

  df2.Snapshot("t", "test.root");
}

Thank you!

Best,
Kevin


ROOT Version: 6.16.00
Platform: CentOS Linux 7 (lxplus)
Compiler: gcc 4.8.5


You’re right, it looks like there is an issue with ROOT::EnableImplicitMT()… Maybe @moneta can comment on this, or @dpiparo for dataframe and you might consider open a Jira issue, or even two…

Hi,

this is not an RDF issue and, actually, I see two very distinct problems:

  1. Fitting an histogram with IMT enabled produces problems
  2. Fitting an histogram or performing the operations in the second DefineSlotEntry call is not thread safe.
    I think @moneta can help.

Cheers,
D

Hi,

Thank you both for your reply!

@dpiparo Yes I agree with you. Just want to add two details here.

  1. Yes. But so far I only saw it when option “I” is enabled. Not sure how general it can be.
  2. Yes. I don’t know how ROOT::EnableImplicitMT() works. But I noticed it’s not thread safe and now gives errors even when option “I” is diabled.

Thanks again.

Best,
Kevin

Hi Kevin,

how is your 2. different from my 2.? :slight_smile:

Cheers,
D

Hi,

So first I certainly agree that it isn’t thread safe.

I was just adding a small difference. Not sure though if this would matter to the problem.
IMT + no RDF + fit produce errors only with option “I”.
IMT + RDF + fit produce errors with and without option “I”.

Best,
Kevin

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.