Problem running Geant4 + Root in multithreading

Hi,
I’m running a simulation using Geant4. To select the energy of the generated particle I’m using TH1 → GetRanom() read from a root file (using TFile.Open() to open/read it). The simulation runs smoothly when I use a single thread, but when I set the multithreading an error occurs at the begin of the simulation:

Fatal in <TClass::Init>: gInterpreter not initialized
aborting
[/Applications/root_v6.14.06/lib/libCore.so] ErrorHandler (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] Fatal(char const*, char const*, ...) (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] TClass::Init(char const*, short, std::type_info const*, TVirtualIsAProxy*, char const*, char const*, int, int, ClassInfo_t*, bool) (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] TClass::TClass(char const*, short, std::type_info const&, TVirtualIsAProxy*, char const*, char const*, int, int, bool) (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] ROOT::CreateClass(char const*, short, std::type_info const&, TVirtualIsAProxy*, char const*, char const*, int, int) (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] ROOT::Internal::TDefaultInitBehavior::CreateClass(char const*, short, std::type_info const&, TVirtualIsAProxy*, char const*, char const*, int, int) const (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] ROOT::TGenericClassInfo::GetClass() (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] TObjString::Class() (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] TObjString::CheckTObjectHashConsistency() const (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] THashTable::Add(TObject*) (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] TPluginManager::LoadHandlersFromPluginDirs(char const*) (no debug info)
[/Applications/root_v6.14.06/lib/libCore.so] TPluginManager::FindHandler(char const*, char const*) (no debug info)
[/Applications/root_v6.14.06/lib/libRIO.so] TFile::Open(char const*, char const*, char const*, int, int) (no debug info)
[/Users/eliabottalico/Documents/Geant4_simulation/B4c_build/./exampleB4c] B4PrimaryGeneratorAction::B4PrimaryGeneratorAction() (no debug info)
[/Users/eliabottalico/Documents/Geant4_simulation/B4c_build/./exampleB4c] B4cActionInitialization::Build() const (no debug info)
[/Users/eliabottalico/Documents/G4-install/lib/libG4run.dylib] G4MTRunManagerKernel::StartThread(G4WorkerThread*) (no debug info)
[/Users/eliabottalico/Documents/G4-install/lib/libG4run.dylib] void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(G4WorkerThread*), G4WorkerThread*> >(void*) (no debug info)
[/usr/lib/system/libsystem_pthread.dylib] _pthread_body (no debug info)
[/usr/lib/system/libsystem_pthread.dylib] _pthread_start (no debug info)
[/usr/lib/system/libsystem_pthread.dylib] thread_start (no debug info)
Abort trap: 6

Do you have any idea about what is happening?

_ROOT Version:6.14.00
_Geant4 Version:10.6.1
Platform: MacOS Mojave - 10.14.6


May be that’s a question for the GEANT4 forum ?

1 Like

Ok, I’ll try to move the question to GEANT4 forum. Thanks!

Just to inform people who will read this post, I solved the problem by introducing, before TFile::Open() the function ROOT::EnableThreadSafety(); In this way is possible to Mutex the “open” function and prevent threads from accessing the file at the same time.

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