Message: Question on accessing G4 from different threads Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Question on accessing G4 from different threads 

Forum: Multithreading
Date: 19 Jun, 2018
From: Simon Spannagel <Simon Spannagel>

Dear all,

we are using Geant4 in our simulation framework to generate initial
energy deposition in the sensitive volumes. The main work, however, is
performed independently from Geant4. We have therefore encapsulated the
Geant4 access in just one small module of our framework while the rest
is independent of G4.

Currently, our framework uses just one thread and processes events
sequentially. Each event consists of one call to Geant4's BeamOn and
several processing steps in our own modules. In order to speed up event
generation on multi-core machines, we are currently working on
implementing multi-threaded simulation where multiple events are
processed in different threads in parallel.

We are however facing some issues in how to talk to Geant4 in this
set-up and hope that you could help us out here. We understand that we
cannot make multiple calls to BeamOn in parallel and that Geant4's
multi-threading capabilities are completely encapsulated inside its run
function.

What we would like to do is to have one instance of Geant4 running, but
have calls to BeamOn from different threads, secured by a mutex lock.
This however does not seem to be possible as Geant4 initializes things
like its logging facilities depending on the process it is called from.
For us this seems to imply, after calling BeamOn from process 1, we
cannot make a subsequent call to it from process 2 for the second event.

Is there any solution to this? Can we force Geant4 to initialize
everything in the main thread before calling BeamOn for the first time?
Is there a way to allow calls from other processes afterwards?

Or would it be possible to have independent instances of Geant4 for 
each of the worker threads?

Some guidance would be very much appreciated.

Best regards,
Simon

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Question on accessing G4 from different threads   (Simon Spannagel - 01 Aug, 2018)
2 None: Re: Question on accessing G4 from different threads   (Makoto Asai - 01 Aug, 2018)
1 None: Re: Question on accessing G4 from different threads   (Simon Spannagel - 01 Aug, 2018)
(_ Feedback: Re: Question on accessing G4 from different threads   (Jonathan Madsen - 01 Aug, 2018)
(_ None: Re: Question on accessing G4 from different threads   (Simon Spannagel - 01 Aug, 2018)
(_ None: Re: Question on accessing G4 from different threads   (Makoto Asai - 02 Aug, 2018)
 Add Message Add Message
to: "Question on accessing G4 from different threads"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews