TTree::GetEntry() with OpenMP

Hi,

I am having problems trying to parallelize a for loop and hoping to get some help. The code is as follow:

int main()
{
  // some parameters declaration

  ROOT::EnableThreadSafety();
  int nthreads = 1;
  ROOT::EnableImplicitMT(nthreads);
  #pragma omp parallel for
  for (uint64_t entry = 0; entry < nentries; entry++)
  {
    int event_status = processedEvent.findNextEvent(entry);
    if (event_status == 0)
      // do some stuff
  }
}

where the findNextEvent() function belongs in another class and looks like this

int findNextEvent(uint64_t entry)
{
  mytree->GetEntry(entry);
  // check some variables associated with this event and return 0 or 1
}

With this current setup, I’m getting the following messages:


 *** Break *** segmentation violation

 *** Break *** segmentation violation
Error in <TTreeCache::FillBuffer>: Inconsistency: fCurrentClusterStart=2568916 fEntryCurrent=2568916 fNextClusterStart=2935904 but fEntryCurrent should not be in between the two

 *** Break *** segmentation violation

 *** Break *** segmentation violation

 *** Break *** segmentation violation

 *** Break *** segmentation violation

 *** Break *** segmentation violation

 *** Break *** segmentation violation

 *** Break *** segmentation violation

 *** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib][/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)

At this point, I am confident that the main cause of this issue is the GetEntry() function as everything else is thread-safe.

Hi @Pete,

ROOT::EnableThreadSafety() and/or ROOT::EnableImplicitMT() should enable thread-safety (IIUC, employing locks for non-parallel sections). This, most likely should work also for OpenMP, but I think it still depends on the OMP implemention.

@pcanal Any ideas / thoughts?

Cheers,
J.

TTree::GetEntry is explicitly not thread-safe. In addition to updating the internal state of TTree it write user data into the a given address for each branch. The ‘only’ two thread mode supported by TTree is one TFile, one TTreeper thread and internal (implicit) multi-thread (whereGetEntry` uses multiple thread to speed up the reading of a single entry).

The best bet to leverage many cores when reading/processing a TTree is to use RDataFrame.

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