Problem 2522 - Example biasing/B03 not working in multi threaded mode
Summary: Example biasing/B03 not working in multi threaded mode
Status: ASSIGNED
Alias: None
Product: Examples/Extended
Classification: Unclassified
Component: biasing/B01, B02, B03 (show other problems)
Version: 10.6
Hardware: All All
: P4 normal
Assignee: alexander.howard
URL:
Depends on:
Blocks:
 
Reported: 2022-12-13 19:52 CET by Birgit Zatschler
Modified: 2023-04-06 19:27 CEST (History)
0 users

See Also:


Attachments
Text output running in MT mode with G4-10.6 (26.81 KB, text/x-log)
2022-12-13 19:52 CET, Birgit Zatschler
Details
Text output running in ST mode with G4-10.6 (28.07 KB, text/x-log)
2022-12-13 19:53 CET, Birgit Zatschler
Details

Note You need to log in before you can comment on or make changes to this problem.
Description Birgit Zatschler 2022-12-13 19:52:31 CET
Created attachment 797 [details]
Text output running in MT mode with G4-10.6

Dear Geant4 experts, 

I have compiled example extended/biasing/B03 against the corresponding Geant4 versions 10.6, 10.7 and 11. In all three cases the importance process is added to the G4ProcessVector only in ST mode, not in MT mode. In the ST mode, the output suggests that the track weight (Av.Tr.WGT) is changed when the particle passes through the importance layers (i.e. 1 -> 0.5 -> 0.25 etc.) However, in MT mode the track weight always stays the same (i.e. 1 -> 1 -> 1). I have attached the output generated for ST and MT with G4-10.6.

Looking at B03PhysicsList.cc (https://github.com/Geant4/geant4/blob/master/examples/extended/biasing/B03/src/B03PhysicsList.cc#L680-L684) the code block
if(!G4Threading::IsMasterThread()) fGeomSampler.AddProcess();
suggests that the process should be added on the worker threads. However, this part of the code is only executed on the master thread, not on the worker threads. As a consequence the is-not-master-thread condition just prevents a G4exception, because the process would only be added on the master thread. Omitting the condition, i.e. following the documentation (https://geant4-userdoc.web.cern.ch/UsersGuides/ForApplicationDeveloper/BackupVersions/V10.6c/html/Fundamentals/biasing.html#changing-the-sampling) shows the previously suppressed exception message:

G4WT0 >
-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : Run0117
      issued by : G4WorkerRunManagerKernel::SetupShadowProcess()
 Size of G4ProcessVector is inconsistent between master and worker threads  for the particle <neutron>.
 size of G4ProcessVector for worker thread is 7 while master thread is 8.
*** Fatal Exception *** core dump ***
G4WT0 >  **** Track information is not available at this moment
G4WT0 >  **** Step information is not available at this moment
G4WT0 >
-------- EEEE -------- G4Exception-END --------- EEEE -------

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

I'm looking for a solution for our own application for which we used this example as a base. What should be changed in the example so that it is running in MT mode?

Best regards,
Birgit
Comment 1 Birgit Zatschler 2022-12-13 19:53:11 CET
Created attachment 798 [details]
Text output running in ST mode with G4-10.6
Comment 2 alexander.howard 2022-12-15 12:17:04 CET
Thanks for bringing this to our attention. I will investigate and get back to you shortly - within a week.
Alex
Comment 3 Birgit Zatschler 2023-02-13 14:28:39 CET
Hi Alex,
were you able to track down this issue?
Best regards, 
Birgit
Comment 4 Birgit Zatschler 2023-04-04 15:21:19 CEST
Is anyone looking into this? I really would like to get a solution.

Best regards, 
Birgit
Comment 5 alexander.howard 2023-04-04 17:41:44 CEST
Hi Birgit,
Yes I am investigating this. The problem is a bit tricky as a simple solution creates a race condition in MT mode, which is not always present - depends on the compiler. I will try to find a solution soon.
In the meantime is there a reason you cannot use the modular physics list implementation as in B02? Or do I miss something?
Best regards,
Alex
Comment 6 Birgit Zatschler 2023-04-06 19:27:17 CEST
Hi Alex, 

thanks for the hint of looking into B02. Indeed, this implementation reports the correct track weights in ST and MT mode. I will have a deeper look into code and I will try to implement such a modular physics list in our own application. 

Best regards, 
Birgit