User’s hook for state change -- doesn't work in MT mode

Hi,
I try to use the User’s hook for state change from chapter 3.4.3 in the Book For Application Developers, Release 11.0.
The problem is that it doesn’t work as described in multi-threading mode.

I use Geant4 v11.0.0 and example B1 with little changes
diff_to_vanilla_B1_example.txt (3.3 KB)

I added UserHookForAbortState* uhfas = new UserHookForAbortState(); in main(),
created UserHookForAbortState.hh and UserHookForAbortState.cc and force an exception in EventAction::BeginOfEventAction(const G4Event*).

Executing with env G4RUN_MANAGER_TYPE=Serial ./exampleB1 run.mac in sequential mode behaves as expected:
output_Serial.txt (43.1 KB)

@@@ GetNumberOfEvent=3

@@@ in if


-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : had006
      issued by : G4HadronicProcess::PostStepDoIt
force this exception! 

*** Fatal Exception *** core dump ***
G4Track (0x2cc0818) - track ID = 4, parent ID = 3
 Particle type : e- - creator process : phot, creator model : model_PhotoElectron
 Kinetic energy : 0 eV  - Momentum direction : (2.31839e-316,0.567689,-0.696325)
 Step length : 200.482 nm  - total energy deposit : 2.23031 keV
 Pre-step point : (50.4612,-12.4468,-77.6538) - Physical volume : Envelope (G4_WATER)
 - defined by : not available
 Post-step point : (50.4611,-12.4468,-77.6539) - Physical volume : Envelope (G4_WATER)
 - defined by : eIoni - step status : 3
 *** Note: Step information might not be properly updated.

-------- EEEE -------- G4Exception-END --------- EEEE -------

$$$$$$$$$$$$$$$$$$ 6
!!!!!!!!!! inside abort state handling!!!!!!!!!!

*** G4Exception: Aborting execution ***

### CAUGHT SIGNAL: 6 ### address: 0x3e800001c34,  signal =  SIGABRT, value =    6, description = abort program (formerly SIGIOT).

But executing with env G4RUN_MANAGER_TYPE=MT ./exampleB1 run.mac or ./exampleB1 run.mac in MT mode the outcome is different:
output_MT.txt (42.3 KB)

G4WT0 > @@@ GetNumberOfEvent=3

G4WT0 > @@@ in if

G4WT0 > 
-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : had006
      issued by : G4HadronicProcess::PostStepDoIt
force this exception! 

*** Fatal Exception *** core dump ***
G4WT0 > G4Track (0x7f6fec401f48) - track ID = 2, parent ID = 1
G4WT0 >  Particle type : e- - creator process : conv, creator model : model_EplusEminisPair
G4WT0 >  Kinetic energy : 0 eV  - Momentum direction : (6.92278e-310,-0.874157,0.478461)
G4WT0 >  Step length : 250.798 um  - total energy deposit : 139.212 keV
G4WT0 >  Pre-step point : (-3.20631,11.6247,4.5065) - Physical volume : Envelope (G4_WATER)
G4WT0 >  - defined by : eIoni - step status : 3
G4WT0 >  Post-step point : (-3.19546,11.5107,4.56888) - Physical volume : Envelope (G4_WATER)
G4WT0 >  - defined by : eIoni - step status : 3
G4WT0 >  *** Note: Step information might not be properly updated.
G4WT0 > 
-------- EEEE -------- G4Exception-END --------- EEEE -------

G4WT0 > 
G4WT0 > *** G4Exception: Aborting execution ***

### CAUGHT SIGNAL: 6 ### address: 0x3e800001bff,  signal =  SIGABRT, value =    6, description = abort program (formerly SIGIOT). 

These two lines are missing, which is the part where the abort state handling should be done!

$$$$$$$$$$$$$$$$$$ 6
!!!!!!!!!! inside abort state handling!!!!!!!!!!

Can someone help me please?
Best regards
Henning

BTW in the Book For Application Developers, Release 11.0 there is an #endif missing at the end of the first code block (Listing 3.1) in chapter 3.4.3.

OK I solved this issue by putting UserHookForAbortState* uhfas = new UserHookForAbortState(); not in main() but in constructor of RunAction.
In this way it works fine in sequential mode and MT mode.

That sounds right. By putting it into RunAction, you get a hook instantiated on both the master thread and each worker thread. In sequential mode, there’s only one thread so the one instance via main() was sufficient.

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