/random/resetEngineFrom does not reproduce same engine states

Hello,
I have some trouble with the random engine state.

I use the Geant4.11.0.0 VM from https://geant4.cenbg.in2p3.fr/.
I changed in example B1 line 78 false to true

G4RunManager::GetRunManager()->SetRandomNumberStore(true);

I compiled it like this:
localhost.localdomain:/build < 91 >cmake -DGeant4_DIR=$G4COMP ..
localhost.localdomain:/build < 91 >make

Then I execute macro A with ./exampleB1 A.mac

# macro A.mac
/run/numberOfThreads 1
#
/random/setDirectoryName A
/random/setSavingFlag 1
#
/run/initialize
#
/gun/particle gamma
/gun/energy 6 MeV
#
/random/setSeeds 2 2
/run/beamOn 50
/random/saveThisRun  #save as A/run0.rndm

The result of macro A.mac is:

  • Cumulated dose per run, in scoring volume : 1.45607 picoGy rms = 0.565989 picoGy
  • A/run0.rndm
# A/run0.rndm
mixmax state, file version 1.0
N=17; V[N]={414469184642473095, 1887497230718120570, 2195475624800485765, 932596286296600524, 218172641998458221, 1120322260615769150, 539175102615237389, 1629436967027825808, 719649398285478826, 1292536263533526791, 1569870862419815394, 1958103466980645205, 824192756230114970, 1491737190745264678, 601594138938872905, 896013831305951495, 207235109353979734}; counter=17; sumtot=51334242799068912;

Excuting macro B with ./exampleB1 B.mac

# macro B.mac
/run/numberOfThreads 1
#
/random/setDirectoryName B
/random/setSavingFlag 1
#
/run/initialize
#
/gun/particle gamma
/gun/energy 6 MeV
#
# 
/random/resetEngineFrom A/run0.rndm
/random/setSeeds 2 2
/run/beamOn 50
/random/saveThisRun  #save as B/run0.rndm
#
/random/setSeeds 2 2
/run/beamOn 50
/random/saveThisRun  #save as B/run1.rndm
#
/random/setSeeds 2 2
/run/beamOn 50
/random/saveThisRun  #save as B/run2.rndm

The result of macro B.mac is:

  • Cumulated dose per run, in scoring volume : 1.45607 picoGy rms = 0.565989 picoGy
  • Cumulated dose per run, in scoring volume : 1.45607 picoGy rms = 0.565989 picoGy
  • Cumulated dose per run, in scoring volume : 1.45607 picoGy rms = 0.565989 picoGy
  • B/run0.rndm
  • B/run1.rndm
  • B/run2.rndm
# B/run0.rndm
mixmax state, file version 1.0
N=17; V[N]={414469184642473095, 1887497230718120570, 2195475624800485765, 932596286296600524, 218172641998458221, 1120322260615769150, 539175102615237389, 1629436967027825808, 719649398285478826, 1292536263533526791, 1569870862419815394, 1958103466980645205, 824192756230114970, 1491737190745264678, 601594138938872905, 896013831305951495, 207235109353979734}; counter=17; sumtot=51334242799068912;
# B/run1.rndm
mixmax state, file version 1.0
N=17; V[N]={2014613053947753086, 824434115577448012, 1977348868538418011, 942717300151646196, 701090698124507451, 320258490287032540, 974022719453450161, 2007169125077615826, 1724623297724457375, 906722331111185825, 1568450006560729852, 1075756346485386457, 461179858001665605, 631993966527713475, 1495955318164271570, 1896413947367753032, 483205697332176607}; counter=7; sumtot=1559211066723659473;
# B/run2.rndm
mixmax state, file version 1.0
N=17; V[N]={2014613053947753086, 824434115577448012, 1977348868538418011, 942717300151646196, 701090698124507451, 320258490287032540, 974022719453450161, 2007169125077615826, 1724623297724457375, 906722331111185825, 1568450006560729852, 1075756346485386457, 461179858001665605, 631993966527713475, 1495955318164271570, 1896413947367753032, 483205697332176607}; counter=7; sumtot=1559211066723659473;

=> The runs give the same physics, but the saved mixmax state from B/run0.rndm differs from B/run1.rndm and B/run2.rndm (and subsequent).
??? Is this as expected ???

Executing macro C with ./exampleB1 C.mac

# macro C.mac
/run/numberOfThreads 1
#
/random/setDirectoryName C
/random/setSavingFlag 1
#
/run/initialize
#
/gun/particle gamma
/gun/energy 6 MeV
#
# 
/random/resetEngineFrom A/run0.rndm
/run/beamOn 50
/random/saveThisRun  #save as C/run0.rndm
#
/random/resetEngineFrom A/run0.rndm
/run/beamOn 50
/random/saveThisRun  #save as C/run1.rndm
#
/random/resetEngineFrom A/run0.rndm
/run/beamOn 50
/random/saveThisRun  #save as C/run2.rndm

The result of macro C.mac is:

  • Cumulated dose per run, in scoring volume : 2.11361 picoGy rms = 0.892899 picoGy
  • Cumulated dose per run, in scoring volume : 2.11361 picoGy rms = 0.892899 picoGy
  • Cumulated dose per run, in scoring volume : 2.11361 picoGy rms = 0.892899 picoGy
  • C/run0.rndm
  • C/run1.rndm
  • C/run2.rndm
# C/run0.rndm
mixmax state, file version 1.0
N=17; V[N]={414469184642473095, 1887497230718120570, 2195475624800485765, 932596286296600524, 218172641998458221, 1120322260615769150, 539175102615237389, 1629436967027825808, 719649398285478826, 1292536263533526791, 1569870862419815394, 1958103466980645205, 824192756230114970, 1491737190745264678, 601594138938872905, 896013831305951495, 207235109353979734}; counter=17; sumtot=51334242799068912;
# C/run1.rndm
mixmax state, file version 1.0
N=17; V[N]={1047083528805871381, 73278982019940248, 80005222461718263, 1628391398291481934, 2302632883225043046, 1376218205706394186, 1022102991764472564, 902203220374063298, 914820296392405112, 1014491263249954051, 1829767848657640665, 2050654056682742913, 2296831036461902366, 48785260568466581, 2294715506087075472, 1696215684458299470, 655273341898698485}; counter=8; sumtot=480883644182924476;
# c/run2.rndm
mixmax state, file version 1.0
N=17; V[N]={1047083528805871381, 73278982019940248, 80005222461718263, 1628391398291481934, 2302632883225043046, 1376218205706394186, 1022102991764472564, 902203220374063298, 914820296392405112, 1014491263249954051, 1829767848657640665, 2050654056682742913, 2296831036461902366, 48785260568466581, 2294715506087075472, 1696215684458299470, 655273341898698485}; counter=8; sumtot=480883644182924476;

=> The runs give the same physics, which differ to macro B because of the different seed. But despite of “loading” the saved run0.rndm from A /random/resetEngineFrom A/run0.rndm in front of each run, the saved mixmax state from C/run0.rndm differs from C/run1.rndm and C/run2.rndm (and subsequent).
??? Is this as expected ???

This behavior is similar with RanecuEngine in exampleB1.cc in line 55.
G4Random::setTheEngine(new CLHEP::RanecuEngine);

I could not find help here:
https://geant4.web.cern.ch/support/user_documentation
https://geant4-userdoc.web.cern.ch/UsersGuides/ForApplicationDeveloper/html/Control/AllResources/Control/UIcommands/_random_.html
https://proj-clhep.web.cern.ch/proj-clhep/

Maybe I don’t understand the concept of /random/saveThisRun and /random/resetEngineFrom correct.
Please can someone help me?

Here, an exercise more on less similar to yours, but with Ranecu for better readily.
run2 and run3 are replay of run0 and run1.
I joint macro and relevant lines of the printout.
henning.mac.txt (424 Bytes)
henning.out.txt (2.3 KB)

No, I get something different.

  1. Why is there no G4WT0 > in your output? Have you removed it by hand?

  2. How can I explicitly build /example/B1 for sequential mode? Have you done that?

I think this problem is linked to the multithreading.

Again I changed in B1:

  • RanecuEngine in example01.cc in line 55
  • G4RunManager::GetRunManager()->SetRandomNumberStore(true); in RunAction.cc in line 78
  • added G4Random::showEngineStatus(); in RunAction.cc in line 79

Building with cmake -DGeant4_DIR=$G4COMP .. and make

In your macro file I added /run/numberOfThreads 1
b1.mac.txt (449 Bytes)

Executing with ./exampleB1 b1.mac results in following output:
output.txt (11.5 KB)


RUN 0

Run 0 starts with Current couple of seeds = 555675652, 180682783 in line 109.
After G4TaskRunManager::CreateAndStartWorkers() in line 116 the engine status changes to Current couple of seeds = 1299961164, 253987020 in line 123 for worker thread 0.

The save run0.rndm:

Uvec
1878463799
1
1299961164
253987020

physics result in line 139:
Cumulated dose per run, in scoring volume : 2.30316 picoGy rms = 0.857985 picoGy


RUN 1

Starts with Current couple of seeds = 1556736925, 1713575266 in line 152.
Changes to Current couple of seeds = 866203543, 434946615 in line 167 for worker thread 0.

The save run1.rndm:

Uvec
1878463799
1
866203543
434946615

physics result in line 183:
Cumulated dose per run, in scoring volume : 2.7123 picoGy rms = 0.902898 picoGy


RUN 2

Due to /random/resetEngineFrom run0.rndm engine status in Current couple of seeds = 1299961164, 253987020 in line 195+202. But then it changes to Current couple of seeds = 1110919607, 437896444 in line 215 for worker thread 0! This is different to run 0!

physics result in line 231:
Cumulated dose per run, in scoring volume : 1.67739 picoGy rms = 0.77967 picoGy
This is different to run 0!


RUN 3

Run 3 is analog to run 2.
Cumulated dose per run, in scoring volume : 1.15723 picoGy rms = 0.710998 picoGy
Run 3 is different to run 1!

I have nothing to do in the examples; it is the entire Geant4 code which is compiled in sequential mode.
Here, my CMake options :
cmake …/geant4-dev
-DCMAKE_INSTALL_PREFIX=/Users/michelmaire/Geant4/install
-DGEANT4_INSTALL_DATA=ON
-DGEANT4_INSTALL_DATADIR=/Users/michelmaire/Geant4/data
-DGEANT4_INSTALL_DATA_TIMEOUT=2400

Okay now I know how to start a simulation in sequential mode.

env G4RUN_MANAGER_TYPE=Serial ./exampleB1 b1.mac

With this I can reproduce your behavior. Results of run0 are same as run3 and run1 are same as run3. This is fine.
output_env.txt (6.1 KB)

But in MT the results differ!

I’m wondering why your geant4 installation is in sequential mode.
In the release notes https://geant4-data.web.cern.ch/ReleaseNotes/ReleaseNotes.11.0.html is the following line:
Multithreading support is now enabled in the build of Geant4 by default.
And you don’t use these flags, do you?
-DGEANT4_BUILD_MULTITHREADED=OFF -DG4MULTITHREADED=OFF

I think that you have exhibited a problem of reproductively in MT mode.
Could you open a Bugzilla report ? You can joint macro and output or, simply, a reference to this forum.
Thanks in advance, Michel

Hi Michel,

I opend a Bugzilla report.
Henning
https://bugzilla-geant4.kek.jp/show_bug.cgi?id=2476

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