I have encountered a bug in my simulation when simulating very few events (1 or 2, less than the number of threads) per run. Specifically, the RunID in the output logs of the worker threads is sometimes incorrect.
The last few lines of file run.mac:
/run/beamOn 1
/run/beamOn 1
/run/beamOn 1
Output:
### Run 0 starts.
========================================================================================
- → G4TaskRunManager::CreateAndStartWorkers() → Creating 1 tasks with 1 events/task…
========================================================================================G4WT2 > ### Run 0 starts on worker thread 2.
G4WT2 > Start to simulate the event 0
G4WT2 > [thread 2] Thread-local run terminated.
G4WT3 > [thread 3] Thread-local run terminated.
G4WT1 > [thread 1] Thread-local run terminated.
G4WT1 > [thread 1] Run Summary
G4WT1 > [thread 1] Number of events processed : 0
G4WT3 > [thread 3] Run Summary
G4WT2 > [thread 2] Run Summary
G4WT1 > [thread 1] User=1.680000s Real=1686857408.236517s Sys=0.070000s [Cpu=0.0%]
G4WT0 > [thread 0] Thread-local run terminated.
G4WT3 > [thread 3] Number of events processed : 0
G4WT2 > [thread 2] Number of events processed : 1
G4WT0 > [thread 0] Run Summary
G4WT0 > [thread 0] Number of events processed : 0
G4WT3 > [thread 3] User=1.680000s Real=1686857408.236499s Sys=0.070000s [Cpu=0.0%]
G4WT0 > [thread 0] User=1.680000s Real=1686857408.236543s Sys=0.070000s [Cpu=0.0%]
G4WT2 > [thread 2] User=0.000000s Real=0.001383s Sys=0.000000s [Cpu=0.0%]
Run terminated.
Run Summary
Number of events processed : 1
User=0.150000s Real=0.171914s Sys=0.020000s [Cpu=98.9%]
The run with RunID 0 is finished.
### Run 1 starts.
========================================================================================
- → G4TaskRunManager::CreateAndStartWorkers() → Creating 1 tasks with 1 events/task…
========================================================================================G4WT2 > ### Run 1 starts on worker thread 2.
G4WT2 > Start to simulate the event 0
G4WT2 > [thread 2] Thread-local run terminated.
G4WT2 > [thread 2] Run Summary
G4WT2 > [thread 2] Number of events processed : 1
G4WT2 > [thread 2] User=0.000000s Real=0.003557s Sys=0.000000s [Cpu=0.0%]
G4WT0 > [thread 0] Thread-local run terminated.
G4WT0 > [thread 0] Run Summary
G4WT0 > [thread 0] Number of events processed : 0
G4WT3 > [thread 3] Thread-local run terminated.
G4WT3 > [thread 3] Run Summary
G4WT3 > [thread 3] Number of events processed : 0
G4WT1 > [thread 1] Thread-local run terminated.
G4WT1 > [thread 1] Run Summary
G4WT3 > [thread 3] User=1.740000s Real=1686857408.697229s Sys=0.090000s [Cpu=0.0%]
G4WT0 > [thread 0] User=1.740000s Real=1686857408.697265s Sys=0.090000s [Cpu=0.0%]
G4WT1 > [thread 1] Number of events processed : 0
G4WT1 > [thread 1] User=1.740000s Real=1686857408.697245s Sys=0.090000s [Cpu=0.0%]
Run terminated.
Run Summary
Number of events processed : 1
User=0.000000s Real=0.013344s Sys=0.000000s [Cpu=0.0%]
The run with RunID 1 is finished.
### Run 2 starts.
========================================================================================
- → G4TaskRunManager::CreateAndStartWorkers() → Creating 1 tasks with 1 events/task…
========================================================================================G4WT3 > ### Run 0 starts on worker thread 3.
G4WT3 > Start to simulate the event 0
G4WT3 > [thread 3] Thread-local run terminated.
G4WT1 > [thread 1] Thread-local run terminated.
G4WT1 > [thread 1] Run Summary
G4WT1 > [thread 1] Number of events processed : 0
G4WT0 > [thread 0] Thread-local run terminated.
G4WT0 > [thread 0] Run Summary
G4WT0 > [thread 0] Number of events processed : 0
G4WT0 > [thread 0] User=1.750000s Real=1686857408.734895s Sys=0.090000s [Cpu=0.0%]
G4WT3 > [thread 3] Run Summary
G4WT3 > [thread 3] Number of events processed : 1
G4WT3 > [thread 3] User=0.000000s Real=0.001905s Sys=0.000000s [Cpu=0.0%]
G4WT1 > [thread 1] User=1.750000s Real=1686857408.734926s Sys=0.090000s [Cpu=0.0%]
G4WT2 > [thread 2] Thread-local run terminated.
G4WT2 > [thread 2] Run Summary
G4WT2 > [thread 2] Number of events processed : 1
G4WT2 > [thread 2] User=0.010000s Real=0.041244s Sys=0.000000s [Cpu=24.2%]
Run terminated.
Run Summary
Number of events processed : 1
User=0.010000s Real=0.014532s Sys=0.000000s [Cpu=68.8%]
The run with RunID 2 is finished.
As you can see the output of RunID from the worker threads in Run2 is incorrect. The RunID in the output logs of the worker threads should match the actual RunID.
Additionally, if I simulate 4 events per run (same as the number of threads), another issue occurs:
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : Run10035
issued by : G4TaskRunManager::InitializeEventLoop()
\Event modulo is reduced to 1 (was 2) to distribute events to all threads.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------
I am using Geant4 version 11.1.1 and I believe this issue is not related to my code. This has caused trouble for me in naming files using RunID in multi-threading mode. Please let me know if anyone can help to resolve it.