Geant4-11
|
This directory contains a Geant4 run manager which uses a tasking system for the G4Event loop. This tasking system is fully compatible with TBB if GEANT4_USE_TBB=ON
is specified when configuring CMake. The default behavior, however, is to submit the tasks to an internal thread-pool and task-queue.
G4TaskRunManager
multiply inherits from G4MTRunManager
and PTL::TaskRunManager
. PTL::TaskRunManager
holds the thread-pool instance, the size of the thread-pool, and the default task-queue. The constructor of G4TaskRunManager
takes a G4VUserTaskQueue
pointer (can be nullptr), a boolean for whether to use TBB if available, and a grainsize.
Environment Variable:
G4FORCE_GRAINSIZE=N
The grainsize is essentially the number of tasks. If set to 0, the default grainsize will be poolSize
and each thread will get numEvents / poolSize
events. If the grainsize is set to 1, then all the events will be submitted as one task (i.e. be processed serially by one thread in the pool). If the grainsize is set to 50 and there are 500 events, then 50 tasks of 10 events will be submitted.
Environment Variable:
G4FORCE_EVENTS_PER_TASK=N
Sometimes is easier to specify the number of events in a task instead of the grainsize. If the events-per-task is set to 10 and there are 500 events, then 50 tasks of 10 events will be submitted.
An enumeration G4RunManagerType
and a function G4RunManagerFactory::CreateRunManager(...)
was added to "G4RunManagerFactory.hh"
to simplify the selection of the various run managers. The first parameter is either one of the enumerated G4RunManagerType
or a string identifier
Enumeration | String ID | Class |
---|---|---|
G4RunManagerType::Serial | "Serial" | G4RunManager |
G4RunManagerType::MT | "MT" | G4MTRunManager |
G4RunManagerType::Tasking | "Tasking" | G4TaskRunManager |
G4RunManagerType::TBB | "TBB" | G4TaskRunManager |
G4RunManagerType::Default | "Default" | Environment setting |
G4RunManagerType::SerialOnly | "Serial" | G4RunManager |
G4RunManagerType::MTOnly | "MT" | G4MTRunManager |
G4RunManagerType::TaskingOnly | "Tasking" | G4TaskRunManager |
G4RunManagerType::TBBOnly | "TBB" | G4TaskRunManager |
The Default
enumeration value will defer to the following environment variable G4RUN_MANAGER_TYPE
if specified and will default to "MT"
if MT is supported and serial if MT is not supported. If the G4FORCE_RUN_MANAGER_TYPE
environment variable is set, this variable will override the value passed to the CreateRunManager
function unless G4RunManagerType
matches one of the <TYPE>Only
values. In this case, the environment variable is ignored and the run manager will be <TYPE>
.
Environment Variable | Options | Description |
---|---|---|
G4RUN_MANAGER_TYPE | "Serial" , "MT" , "Tasking" , "TBB" | Only applicable when G4RunManagerType::Default is used |
G4FORCE_RUN_MANAGER_TYPE | "Serial" , "MT" , "Tasking" , "TBB" | Will override explicitly specifed G4RunManagerType if application allows and fail if type is not available |
G4RunManagerFactory::CreateRunManager(...)
function takes either G4RunManagerType
enumerated type or string to specify the desired G4RunManagerG4RunManager*
int numberOfThreads
- executes G4MTRunManager::SetNumberOfThreads(numberOfThreads)
before returning if > 00
bool fail_if_unavail
- will cause a runtime failure if requested type is not available with Geant4 buildtrue
G4VTaskQueue*
- a task-queue managernullptr
With G4TaskRunManager, Geant4 events will be launched asynchronously as tasks. These tasks are placed into a queue until one of the thread in the pool is available to execute the task. Users can take advantage of this system to load-balance expensive sub-event calculations which might have previously resulted in serial bottlenecks. For example, if an application needs to do extensive event analysis on electrons and thread #1 ends up with 10x as many of these events, the other threads might finish their G4Run significantly eariler and be idle while thread #1 has a lot of work. Tasking allows these analysis calculations to be offload back into the queue so that other threads can contribute to their completion.
foo(int, double)
asynchronously:task_group<T>
object where T
is the return type of all the functions in the groupT
is non-void, you must provide a join functor who return type and first argument are both references to the joined type and the second argument is type T
, e.g. task_group<int>
can provide a join functor with vector<int>&
as the return type and T
as the second argument or int&
as the return and first argument and int
as the second argumentT
is void, the join functor is optional and can be treated as a final synchronization operation after all the tasks have been completed.NOTE: The join functor for task-groups are called sequentially on the thread that is waiting on
task_group<T>::join()
member function.