allpix::MTRunManager
A custom run manager for Geant4 that can work with external threads and be used concurrently. More…
#include <MTRunManager.hpp>
Inherits from G4MTRunManager
Public Functions
Name | |
---|---|
MTRunManager() | |
~MTRunManager() override =default | |
void | Run(G4int n_event, uint64_t seed1, uint64_t seed2) Thread safe version of G4RunManager::BeamOn. Offload the work to a thread specific worker. |
void | Initialize() override Initialize the run manager to be ready for run. |
void | InitializeForThread() Initializes thread local objects including the worker manager. |
void | TerminateForThread() Cleanup worker specific data stored as thread local. |
SensitiveDetectorAndFieldConstruction * | GetSDAndFieldConstruction() const Returns the user’s sensitive detector construction. |
void | SetSDAndFieldConstruction(std::unique_ptr< SensitiveDetectorAndFieldConstruction > sd_field_construction) Sets the user’s sensitive detector construction. |
void | AbortRun(G4bool softAbort) override Overriding G4RunManager::AbortRun so as to reset the state to G4State_Idle in order to allow the next event to run BeamOn. |
Protected Functions
Name | |
---|---|
WorkerActionRequest | ThisWorkerWaitForNextAction() override Previously used by workers to wait for master commands. Worker manager waits on the shared barrier until master issues a new command. It will now do nothing. |
void | CreateAndStartWorkers() override Previously used to create threads and start worker managers. Creates my own threads and start the worker run managers. It will now do nothing. |
void | NewActionRequest(WorkerActionRequest ) override Previously used to issue a new command to the workers. Send a new command to workers waiting for master to tell them what to do. It will now do nothing. |
G4bool | InitializeSeeds(G4int ) override Previously used to generate initial seeds. We skip this since we provide seeds to each event directly It is important to override this function to make sure Geant4 is not seeding itself independently. |
void | RequestWorkersProcessCommandsStack() override Previously used to tell workers to execute UI commands. Send commands to workers to execute the UI commands stored in master. It will now do nothing. |
G4bool | SetUpAnEvent(G4Event * , long & , long & , long & , G4bool ) override Previously used by the worker to initialize an event. |
G4int | SetUpNEvents(G4Event * , G4SeedsQueue * , G4bool ) override Previously used by the worker to initialize N event. |
void | TerminateWorkers() override Previously used to stop all the workers. Stop the workers. It will now do nothing. |
void | ThisWorkerEndEventLoop() override Previously used by workers to signal they finished the event loop. Synchronize with master about finishing the assigned work. It will now do nothing. |
void | ThisWorkerProcessCommandsStackDone() override Previously used by workers to signal they finished running UI commands. Synchronize with master about finishing UI commands. It will now do nothing. |
void | ThisWorkerReady() override Previously used by workers to signal they are ready to do work. Synchronize with master we finished initialization and ready for work. It will now do nothing. |
void | WaitForEndEventLoopWorkers() override Previously used to wait until all workers have finished the event loop. Wait for all the workers to finish and signal the end of event loop. It will now do nothing. |
void | WaitForReadyWorkers() override Previously used to wait for workers to finish initialization. Wait for all the workers to finish initialization. It will now do nothing. |
Friends
Name | |
---|---|
class | WorkerRunManager |
Detailed Description
class allpix::MTRunManager;
A custom run manager for Geant4 that can work with external threads and be used concurrently.
This manager overrides G4MTRunManager class so it doesn’t create its own thread and work with the threads already created by ModuleManager class. Also, it provides a concurrent API that can be used by multiple threads safely at the same time. Most of the APIs defined by G4MTRunManager are overridden to simply do nothing since this custom run manager doesn’t operate its own event loop and assumes it is part of the client event loop and the results of each event are independent from each other. Also, this manager doesn’t maintain any threads, it only maintains the worker managers which are allocated on a per thread basis.
Public Functions Documentation
function MTRunManager
MTRunManager()
function ~MTRunManager
~MTRunManager() override =default
function Run
void Run(
G4int n_event,
uint64_t seed1,
uint64_t seed2
)
Thread safe version of G4RunManager::BeamOn. Offload the work to a thread specific worker.
Parameters:
- n_event number of events to simulate in one run.
- seed1 First event seed for the worker run manager of the calling thread
- seed2 Second event seed for the worker run manager of the calling thread
Run the specified number of events on a separate worker that is associated with the calling thread. The worker will be initialized with a new set of seeds to be used specifically for this event. The seeds are obtained from the calling module, thereby ensuring that results can be reproduced.
function Initialize
void Initialize() override
Initialize the run manager to be ready for run.
Initializes the manager to be in a ready state. It will also prepare the random seeds which will be used to seed the RNG on each worker thread. If you want to set the seeds for G4 RNG it must happen before calling this method.
function InitializeForThread
void InitializeForThread()
Initializes thread local objects including the worker manager.
Initializes the worker run manager associated to the calling thread. This must be called by every thread that intends to call Run method. Only the first call by a given thread will actually initialize the workers and further calls by the same thread will be ignored.
function TerminateForThread
void TerminateForThread()
Cleanup worker specific data stored as thread local.
Cleanup all thread local objects allocated previously by the calling thread. Each thread that ever used this class must call this method to ensure correct termination.
function GetSDAndFieldConstruction
inline SensitiveDetectorAndFieldConstruction * GetSDAndFieldConstruction() const
Returns the user’s sensitive detector construction.
function SetSDAndFieldConstruction
inline void SetSDAndFieldConstruction(
std::unique_ptr< SensitiveDetectorAndFieldConstruction > sd_field_construction
)
Sets the user’s sensitive detector construction.
function AbortRun
void AbortRun(
G4bool softAbort
) override
Overriding G4RunManager::AbortRun so as to reset the state to G4State_Idle in order to allow the next event to run BeamOn.
Protected Functions Documentation
function ThisWorkerWaitForNextAction
inline WorkerActionRequest ThisWorkerWaitForNextAction() override
Previously used by workers to wait for master commands. Worker manager waits on the shared barrier until master issues a new command. It will now do nothing.
function CreateAndStartWorkers
inline void CreateAndStartWorkers() override
Previously used to create threads and start worker managers. Creates my own threads and start the worker run managers. It will now do nothing.
function NewActionRequest
inline void NewActionRequest(
WorkerActionRequest
) override
Previously used to issue a new command to the workers. Send a new command to workers waiting for master to tell them what to do. It will now do nothing.
function InitializeSeeds
inline G4bool InitializeSeeds(
G4int
) override
Previously used to generate initial seeds. We skip this since we provide seeds to each event directly It is important to override this function to make sure Geant4 is not seeding itself independently.
function RequestWorkersProcessCommandsStack
inline void RequestWorkersProcessCommandsStack() override
Previously used to tell workers to execute UI commands. Send commands to workers to execute the UI commands stored in master. It will now do nothing.
function SetUpAnEvent
inline G4bool SetUpAnEvent(
G4Event * ,
long & ,
long & ,
long & ,
G4bool
) override
Previously used by the worker to initialize an event.
Worker will ask us to setup the event. This includes figuring out the event number that worker will do and setting up the seeds to ensure results can be reproduced. It will now do nothing.
function SetUpNEvents
inline G4int SetUpNEvents(
G4Event * ,
G4SeedsQueue * ,
G4bool
) override
Previously used by the worker to initialize N event.
Worker will ask us to setup the events. This includes figuring out the event numbers that worker will do and setting up the seeds to ensure results can be reproduced. It will now do nothing.
function TerminateWorkers
inline void TerminateWorkers() override
Previously used to stop all the workers. Stop the workers. It will now do nothing.
function ThisWorkerEndEventLoop
inline void ThisWorkerEndEventLoop() override
Previously used by workers to signal they finished the event loop. Synchronize with master about finishing the assigned work. It will now do nothing.
function ThisWorkerProcessCommandsStackDone
inline void ThisWorkerProcessCommandsStackDone() override
Previously used by workers to signal they finished running UI commands. Synchronize with master about finishing UI commands. It will now do nothing.
function ThisWorkerReady
inline void ThisWorkerReady() override
Previously used by workers to signal they are ready to do work. Synchronize with master we finished initialization and ready for work. It will now do nothing.
function WaitForEndEventLoopWorkers
inline void WaitForEndEventLoopWorkers() override
Previously used to wait until all workers have finished the event loop. Wait for all the workers to finish and signal the end of event loop. It will now do nothing.
function WaitForReadyWorkers
inline void WaitForReadyWorkers() override
Previously used to wait for workers to finish initialization. Wait for all the workers to finish initialization. It will now do nothing.
Friends
friend WorkerRunManager
friend class WorkerRunManager(
WorkerRunManager
);
Updated on 2024-12-13 at 08:31:36 +0000