Only migrated examples or user applications can be run in multi-threading (MT) mode. The instructions for migrating user applications can be found in Geant4 documentation guides and a short howto is available here:
https://twiki.cern.ch/twiki/bin/view/Geant4/QuickMigrationGuideForGeant4V10
In this file, we give just useful tips for running already migrated examples (or user applications).
No special steps are needed to build an example in multi-threading (MT) mode. The examples which has been migrated to multi-threading will automatically run in MT when they are built against the Geant4 libraries built with MT mode activated, otherwise they will run in sequential mode. Not migrated examples will run in sequential mode even when built against Geant4 libraries built with MT mode activated.
The examples which do NOT support MT can be easily recognized by the following line of code in main ():
G4RunManager* runManager = new G4RunManager;
or
auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly);
When the number of threads is not selected in the application, the default number (which is actually 2) will be used. Another number of threads can be set in several ways:
auto* runManager = ...; runManager->SetNumberOfThreads(4);
/run/numberOfThreads 4
export G4FORCENUMBEROFTHREADS = 4 or setenv G4FORCENUMBEROFTHREADS 4
The environment variable value is forced and it cannot be changed from a code call or a macro. A warning is issued in such situation.
In MT processing each worker produces its output and these messages are interlayed on the screen. The messeges from threads are preceded with a predefined string G4WTi> where i is the thread number. Users can change this default behaviour and choose
/control/cout/ignoreThreadsExcept 0
/control/cout/setCoutFile coutFileName /control/cout/setCerrFile cerrFileName
/control/cout/useBuffer true|false