Warning, /geant4/examples/README.HowToRunMT.md is written in an unsupported language. File is not indexed.
0001 \page README_HowToRunMT Tips how to run an example in multi-threading mode
0002
0003 Only migrated examples or user applications can be run in multi-threading (MT) mode.
0004 The instructions for migrating user applications can be found in Geant4 documentation guides
0005 and a short howto is available here:
0006
0007 https://twiki.cern.ch/twiki/bin/view/Geant4/QuickMigrationGuideForGeant4V10
0008
0009 In this file, we give just useful tips for running already migrated examples
0010 (or user applications).
0011
0012 ## Run example in multi-threading mode
0013
0014 No special steps are needed to build an example in multi-threading (MT) mode.
0015 The examples which has been migrated to multi-threading will automatically
0016 run in MT when they are built against the Geant4 libraries built with MT mode
0017 activated, otherwise they will run in sequential mode.
0018 Not migrated examples will run in sequential mode even when built against
0019 Geant4 libraries built with MT mode activated.
0020
0021 The examples which do NOT support MT can be easily recognized by the following line
0022 of code in main ():
0023 ```
0024 G4RunManager* runManager = new G4RunManager;
0025 ```
0026 or
0027 ```
0028 auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly);
0029 ```
0030
0031 ## Set number of threads
0032
0033 When the number of threads is not selected in the application, the default number
0034 (which is actually 2) will be used. Another number of threads can be set in several
0035 ways:
0036
0037 - in the code
0038 ```
0039 auto* runManager = ...;
0040 runManager->SetNumberOfThreads(4);
0041 ```
0042
0043 - in a macro file via UI command added just before /run/initialize
0044 ```
0045 /run/numberOfThreads 4
0046 ```
0047
0048 - by setting the environment variable
0049 ```
0050 export G4FORCENUMBEROFTHREADS = 4
0051 or
0052 setenv G4FORCENUMBEROFTHREADS 4
0053 ```
0054
0055 The environment variable value is forced and it cannot be changed from a code
0056 call or a macro. A warning is issued in such situation.
0057
0058 ## Output from threads
0059
0060 In MT processing each worker produces its output and these messages are interlayed
0061 on the screen. The messeges from threads are preceded with a predefined string
0062 G4WTi> where i is the thread number. Users can change this default behaviour
0063 and choose
0064
0065 - to limit the output from threads to one selected thread only:
0066 ```
0067 /control/cout/ignoreThreadsExcept 0
0068 ```
0069
0070 - to redirect the output from threads in a file:
0071 ```
0072 /control/cout/setCoutFile coutFileName
0073 /control/cout/setCerrFile cerrFileName
0074 ```
0075
0076 - to buffer the output from each thread at a time, so that the output of each
0077 thread is grouped and printed at the end of the job
0078 ```
0079 /control/cout/useBuffer true|false
0080 ```