Multi-threaded mode

Hello experts

I am encountering difficulties to visualise the code output, but the code itself run without a problem, but after 100% run, to visualise the code with multithreading, I get this
Available UI session types: [ Qt, tcsh, csh ]
QObject::connect: No such signal QTabWidget::tabCloseRequested(G4int)
QObject::connect: No such signal QTabWidget::currentChanged(G4int)
QObject::connect: No such signal QTabWidget::currentChanged(G4int)
QObject::connect: No such signal QComboBox::activated(G4int)
Random engine seeded with 1502758931


Geant4 version Name: geant4-11-01-patch-01 [MT] (10-February-2023)
<< in Multi-threaded mode >>
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
: NIM A 835 (2016), 186-225
WWW : http://geant4.org/


G4PhysListFactory::GetReferencePhysList <QGSP_BERT_HP_EMZ> EMoption= 4
<<< Geant4 Physics List simulation engine: QGSP_BERT_HP

G4VModularPhysicsList::ReplacePhysics: G4EmStandard with type : 2 is replaced with G4EmStandard_opt4

G4VModularPhysicsList::ReplacePhysics: G4EmStandard_opt4 with type : 2 is replaced with G4EmLivermorePolarized
G4VModularPhysicsList::ReplacePhysics: Decay with type : 4 is replaced with Decay
Segmentation fault: 11

Please how can this be solved

Segmentation faults are usually best tracked down through running the application in a debugger such as gdb or lldb. There are lots of posts on the forum about this, e.g. this one: Error segmentation fault (core dump) - #2 by bmorgan (or search for “gdb” or “debugger” here).

The problem is in multi threading because when I tried to comment out multi-threaded lines it worked
here is the code, help to find the problem so that I can run it without commenting out multi-threaded lines
in other computer is working fine, so I wonder why for me it is not!
#define G4MULTITHREADED
#ifdef G4MULTITHREADED
#include “G4MTRunManager.hh”
#else
#include “G4RunManager.hh”
#endif
#include “G4PhysListFactory.hh”
#include “BDetectorConstruction.hh”
#include “G4EmLivermorePolarizedPhysics.hh”
#include “G4DecayPhysics.hh”
#include “G4RadioactiveDecayPhysics.hh”
#include “BActionInitialization.hh”
#include “G4UIExecutive.hh”
#include “G4UImanager.hh”
#include “G4VisExecutive.hh”

#include

int main(int argc,char** argv)
{

// if(argc>2)
// B::outfname=argv[2];
// else
// B::outfname=“B”;

// Do this first to capture all output
G4UIExecutive* ui = new G4UIExecutive(argc, argv);
//G4UIExecutive* ui = nullptr;

// Choose the Random engine
G4Random::setTheEngine(new CLHEP::RanecuEngine);

// int seed;

//
// if(argc>3)
// {
// G4int batchNum = G4UIcommand::ConvertToInt(argv[3]);
// G4cout << time(0) << G4endl;
// seed = time(0) + 2*batchNum;
// G4cout << batchNum << G4endl;
// }
// else
// {
// seed = time(0);
// }
//
// seed |=1; // Make sure it’s odd
int seed = 1502758931; // Activate this line with a fixed seed if desired
CLHEP::HepRandom::setTheSeed(seed);
G4cout << "Random engine seeded with " << seed << G4endl;

#ifdef G4MULTITHREADED
G4MTRunManager* runManager = new G4MTRunManager;
#else
G4RunManager* runManager = new G4RunManager;
#endif
// G4RunManager* runManager = new G4RunManager;

runManager->SetUserInitialization(new BDetectorConstruction);

G4int verbose;
G4PhysListFactory factory;
G4VModularPhysicsList* physList = factory.GetReferencePhysList(“QGSP_BERT_HP_EMZ”); //FTFP_BERT
physList->SetVerboseLevel(verbose = 1);
physList->ReplacePhysics(new G4EmLivermorePolarizedPhysics);
physList->ReplacePhysics(new G4DecayPhysics);
//physList->ReplacePhysics(new G4RadioactiveDecayPhysics);
runManager->SetUserInitialization(physList);

runManager->SetUserInitialization(new BActionInitialization);

G4VisManager* visManager = new G4VisExecutive(“Quiet”);
visManager->Initialize();

G4UImanager* UImanager = G4UImanager::GetUIpointer();

G4String command = "/control/execute ";
G4String fileName = argv[1];
UImanager->ApplyCommand(command+fileName);

ui->SessionStart();

delete ui;
delete visManager;
delete runManager;
}

This should never be manually defined as it is set at build time and compiled into the libraries. To check if Geant4 supports multithreading or not, it’s best to do:

// This includes the definition or not of G4MULTITHREADED for the build
#include "globals.hh"

#ifdef G4MULTITHREADED
...

However, as you’re using Geant4 11.1, there’s no need to do things this way to construct the run manager. Instead, it’s sufficient to do:

#include "G4RunManagerFactory.hh"

int main()
{
  auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);

  // use runManager as you need
  ...
}

This explicit definition of G4MULTITHREADED might be the cause of the segfault, but if the above doesn’t fix things you’ll need to run in a debugger to pinpoint things.