Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TaskRunManager Class Reference

#include <G4TaskRunManager.hh>

+ Inheritance diagram for G4TaskRunManager:

Public Types

using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>
 
using InitializeSeedsCallback = std::function<G4bool(G4int, G4int&, G4int&)>
 
using RunTaskGroup = G4TaskGroup<void>
 
- Public Types inherited from G4MTRunManager
enum class  WorkerActionRequest { UNDEFINED , NEXTITERATION , PROCESSUI , ENDWORKER }
 
using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>
 
using masterWorlds_t = std::map<G4int, G4VPhysicalVolume*>
 
- Public Types inherited from G4RunManager
enum  RMType { sequentialRM , masterRM , workerRM }
 
using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>
 
- Public Types inherited from PTL::TaskRunManager
using pointer = TaskRunManager*
 

Public Member Functions

 G4TaskRunManager (G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false))
 
 G4TaskRunManager (G4VUserTaskQueue *taskQueue, G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false), G4int evtGrainsize=0)
 
 ~G4TaskRunManager () override
 
void SetGrainsize (G4int n)
 
G4int GetGrainsize () const
 
G4int GetNumberOfTasks () const
 
G4int GetNumberOfEventsPerTask () const
 
void SetNumberOfThreads (G4int n) override
 
G4int GetNumberOfThreads () const override
 
size_t GetNumberActiveThreads () const override
 
void Initialize () override
 
void InitializeEventLoop (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
 
void InitializeThreadPool () override
 
G4bool ThreadPoolIsInitialized () const
 
void Initialize (uint64_t nthreads) override
 
void TerminateOneEvent () override
 
void ProcessOneEvent (G4int i_event) override
 
void ConstructScoringWorlds () override
 
void RunTermination () override
 
G4bool SetUpAnEvent (G4Event *, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true) override
 
G4int SetUpNEvents (G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true) override
 
void MergeScores (const G4ScoringManager *localScoringManager)
 
void MergeRun (const G4Run *localRun)
 
void RequestWorkersProcessCommandsStack () override
 
void ThisWorkerProcessCommandsStackDone () override
 
void WaitForReadyWorkers () override
 
void WaitForEndEventLoopWorkers () override
 
void ThisWorkerReady () override
 
void ThisWorkerEndEventLoop () override
 
WorkerActionRequest ThisWorkerWaitForNextAction () override
 
void SetInitializeSeedsCallback (InitializeSeedsCallback f)
 
void AbortRun (G4bool softAbort=false) override
 
void AbortEvent () override
 
- Public Member Functions inherited from G4MTRunManager
 G4MTRunManager ()
 
 ~G4MTRunManager () override
 
void SetPinAffinity (G4int n=1)
 
G4int GetPinAffinity () const
 
std::vector< G4StringGetCommandStack ()
 
const CLHEP::HepRandomEnginegetMasterRandomEngine () const
 
void SetUserInitialization (G4VUserPhysicsList *userPL) override
 
void SetUserInitialization (G4VUserDetectorConstruction *userDC) override
 
void SetUserInitialization (G4UserWorkerInitialization *userInit) override
 
void SetUserInitialization (G4UserWorkerThreadInitialization *userInit) override
 
void SetUserInitialization (G4VUserActionInitialization *userInit) override
 
void SetUserAction (G4UserRunAction *userAction) override
 
void SetUserAction (G4VUserPrimaryGeneratorAction *userAction) override
 
void SetUserAction (G4UserEventAction *userAction) override
 
void SetUserAction (G4UserStackingAction *userAction) override
 
void SetUserAction (G4UserTrackingAction *userAction) override
 
void SetUserAction (G4UserSteppingAction *userAction) override
 
void MergeScores (const G4ScoringManager *localScoringManager)
 
void MergeRun (const G4Run *localRun)
 
void SetEventModulo (G4int i=1)
 
G4int GetEventModulo () const
 
- Public Member Functions inherited from G4RunManager
 G4RunManager ()
 
virtual ~G4RunManager ()
 
 G4RunManager (const G4RunManager &)=delete
 
G4RunManageroperator= (const G4RunManager &)=delete
 
virtual void BeamOn (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
 
virtual void DefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
virtual void InitializeGeometry ()
 
virtual void InitializePhysics ()
 
virtual G4bool ConfirmBeamOnCondition ()
 
virtual void RunInitialization ()
 
virtual void DoEventLoop (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
 
virtual void TerminateEventLoop ()
 
virtual G4EventGenerateEvent (G4int i_event)
 
virtual void AnalyzeEvent (G4Event *anEvent)
 
virtual void ConfigureProfilers (const std::vector< std::string > &args={})
 
void ConfigureProfilers (G4int argc, char **argv)
 
void DumpRegion (const G4String &rname) const
 
void DumpRegion (G4Region *region=nullptr) const
 
void GeometryHasBeenModified (G4bool prop=true)
 
void ReinitializeGeometry (G4bool destroyFirst=false, G4bool prop=true)
 
void PhysicsHasBeenModified ()
 
void CutOffHasBeenModified ()
 
void ReOptimizeMotherOf (G4VPhysicalVolume *)
 
void ReOptimize (G4LogicalVolume *)
 
void SetGeometryToBeOptimized (G4bool vl)
 
G4bool GetGeometryToBeOptimized ()
 
void GeometryDirectlyUpdated (G4bool val=true)
 
virtual void RestoreRandomNumberStatus (const G4String &fileN)
 
virtual void RestoreRndmEachEvent (G4bool)
 
const G4VUserDetectorConstructionGetUserDetectorConstruction () const
 
const G4VUserPhysicsListGetUserPhysicsList () const
 
const G4VUserActionInitializationGetUserActionInitialization () const
 
G4VUserActionInitializationGetNonConstUserActionInitialization () const
 
const G4UserWorkerInitializationGetUserWorkerInitialization () const
 
const G4UserWorkerThreadInitializationGetUserWorkerThreadInitialization () const
 
const G4UserRunActionGetUserRunAction () const
 
const G4VUserPrimaryGeneratorActionGetUserPrimaryGeneratorAction () const
 
const G4UserEventActionGetUserEventAction () const
 
const G4UserStackingActionGetUserStackingAction () const
 
const G4UserTrackingActionGetUserTrackingAction () const
 
const G4UserSteppingActionGetUserSteppingAction () const
 
void SetNumberOfAdditionalWaitingStacks (G4int iAdd)
 
const G4StringGetVersionString () const
 
void SetPrimaryTransformer (G4PrimaryTransformer *pt)
 
void StoreRandomNumberStatusToG4Event (G4int vl)
 
G4int GetFlagRandomNumberStatusToG4Event () const
 
void SetRandomNumberStore (G4bool flag)
 
G4bool GetRandomNumberStore () const
 
void SetRandomNumberStoreDir (const G4String &dir)
 
const G4StringGetRandomNumberStoreDir () const
 
const G4StringGetRandomNumberStatusForThisRun () const
 
const G4StringGetRandomNumberStatusForThisEvent () const
 
void SetRandomNumberStorePerEvent (G4bool flag)
 
G4bool GetRandomNumberStorePerEvent () const
 
void SetVerboseLevel (G4int vl)
 
G4int GetVerboseLevel () const
 
G4int GetPrintProgress ()
 
void SetPrintProgress (G4int i)
 
void SetNumberOfEventsToBeStored (G4int val)
 
const G4RunGetCurrentRun () const
 
G4RunGetNonConstCurrentRun () const
 
const G4EventGetCurrentEvent () const
 
const G4EventGetPreviousEvent (G4int i) const
 
void SetRunIDCounter (G4int i)
 
G4int GetNumberOfParallelWorld () const
 
void SetNumberOfEventsToBeProcessed (G4int val)
 
G4int GetNumberOfEventsToBeProcessed () const
 
G4int GetNumberOfSelectEvents () const
 
const G4StringGetSelectMacro () const
 
void SetDCtable (G4DCtable *DCtbl)
 
RMType GetRunManagerType () const
 
- Public Member Functions inherited from PTL::TaskRunManager
 TaskRunManager (bool useTBB=false)
 
virtual ~TaskRunManager ()
 
virtual void Terminate ()
 
ThreadPoolGetThreadPool () const
 
TaskManagerGetTaskManager () const
 
bool IsInitialized () const
 
int GetVerbose () const
 
void SetVerbose (int val)
 

Static Public Member Functions

static G4TaskRunManagerGetMasterRunManager ()
 
static G4TaskRunManagerKernelGetMTMasterRunManagerKernel ()
 
static G4ThreadId GetMasterThreadId ()
 
- Static Public Member Functions inherited from G4MTRunManager
static G4ThreadId GetMasterThreadId ()
 
static G4ScoringManagerGetMasterScoringManager ()
 
static masterWorlds_tGetMasterWorlds ()
 
static void addWorld (G4int counter, G4VPhysicalVolume *w)
 
static G4MTRunManagerGetMasterRunManager ()
 
static G4RunManagerKernelGetMasterRunManagerKernel ()
 
static G4MTRunManagerKernelGetMTMasterRunManagerKernel ()
 
static G4int SeedOncePerCommunication ()
 
static void SetSeedOncePerCommunication (G4int val)
 
- Static Public Member Functions inherited from G4RunManager
static G4RunManagerGetRunManager ()
 
static G4bool IfGeometryHasBeenDestroyed ()
 
- Static Public Member Functions inherited from PTL::TaskRunManager
static TaskRunManagerGetInstance (bool useTBB=false)
 
static TaskRunManagerGetMasterRunManager (bool useTBB=false)
 

Protected Member Functions

virtual void ComputeNumberOfTasks ()
 
G4bool InitializeSeeds (G4int) override
 
void RefillSeeds () override
 
void StoreRNGStatus (const G4String &filenamePrefix) override
 
void CreateAndStartWorkers () override
 
void TerminateWorkers () override
 
void NewActionRequest (WorkerActionRequest) override
 
virtual void AddEventTask (G4int)
 
- Protected Member Functions inherited from G4MTRunManager
virtual void PrepareCommandsStack ()
 
void rndmSaveThisRun () override
 
void rndmSaveThisEvent () override
 
- Protected Member Functions inherited from G4RunManager
 G4RunManager (RMType rmType)
 
void CleanUpPreviousEvents ()
 
void CleanUpUnnecessaryEvents (G4int keepNEvents)
 
void StackPreviousEvent (G4Event *anEvent)
 
void UpdateScoring ()
 
virtual void DeleteUserInitializations ()
 

Protected Attributes

RunTaskGroupworkTaskGroup = nullptr
 
G4boolpoolInitialized = PTL::TaskRunManager::m_is_initialized
 
G4ThreadPool *& threadPool = PTL::TaskRunManager::m_thread_pool
 
G4VUserTaskQueue *& taskQueue = PTL::TaskRunManager::m_task_queue
 
G4TaskManager *& taskManager = PTL::TaskRunManager::m_task_manager
 
InitializeSeedsCallback initSeedsCallback
 
- Protected Attributes inherited from G4MTRunManager
G4int nworkers = 2
 
G4int forcedNwokers = -1
 
G4int numberOfEventToBeProcessed = 0
 
WorkerActionRequest nextActionRequest = WorkerActionRequest::UNDEFINED
 
G4int eventModuloDef = 0
 
G4int eventModulo = 1
 
G4int nSeedsUsed = 0
 
G4int nSeedsFilled = 0
 
G4int nSeedsMax = 10000
 
G4int nSeedsPerEvent = 2
 
G4doublerandDbl = nullptr
 
G4MTBarrier beginOfEventLoopBarrier
 
G4MTBarrier endOfEventLoopBarrier
 
G4MTBarrier nextActionRequestBarrier
 
G4MTBarrier processUIBarrier
 
- Protected Attributes inherited from G4RunManager
G4RunManagerKernelkernel = nullptr
 
G4EventManagereventManager = nullptr
 
G4VUserDetectorConstructionuserDetector = nullptr
 
G4VUserPhysicsListphysicsList = nullptr
 
G4VUserActionInitializationuserActionInitialization = nullptr
 
G4UserWorkerInitializationuserWorkerInitialization = nullptr
 
G4UserWorkerThreadInitializationuserWorkerThreadInitialization = nullptr
 
G4UserRunActionuserRunAction = nullptr
 
G4VUserPrimaryGeneratorActionuserPrimaryGeneratorAction = nullptr
 
G4UserEventActionuserEventAction = nullptr
 
G4UserStackingActionuserStackingAction = nullptr
 
G4UserTrackingActionuserTrackingAction = nullptr
 
G4UserSteppingActionuserSteppingAction = nullptr
 
G4bool geometryInitialized = false
 
G4bool physicsInitialized = false
 
G4bool runAborted = false
 
G4bool initializedAtLeastOnce = false
 
G4bool geometryToBeOptimized = true
 
G4int runIDCounter = 0
 
G4int verboseLevel = 0
 
G4int printModulo = -1
 
G4Timertimer = nullptr
 
G4DCtableDCtable = nullptr
 
G4RuncurrentRun = nullptr
 
G4EventcurrentEvent = nullptr
 
std::list< G4Event * > * previousEvents = nullptr
 
G4int n_perviousEventsToBeStored = 0
 
G4int numberOfEventToBeProcessed = 0
 
G4bool storeRandomNumberStatus = false
 
G4int storeRandomNumberStatusToG4Event = 0
 
G4String randomNumberStatusDir = "./"
 
G4String randomNumberStatusForThisRun = ""
 
G4String randomNumberStatusForThisEvent = ""
 
G4bool rngStatusEventsFlag = false
 
G4VPhysicalVolumecurrentWorld = nullptr
 
G4int nParallelWorlds = 0
 
G4String msgText = " "
 
G4int n_select_msg = -1
 
G4int numberOfEventProcessed = 0
 
G4String selectMacro = ""
 
G4bool fakeRun = false
 
G4bool isScoreNtupleWriter = false
 
G4bool geometryDirectlyUpdated = false
 
RMType runManagerType
 
- Protected Attributes inherited from PTL::TaskRunManager
bool m_is_initialized = false
 
int m_verbose = 0
 
uint64_t m_workers = 0
 
VUserTaskQueuem_task_queue = nullptr
 
ThreadPoolm_thread_pool = nullptr
 
TaskManagerm_task_manager = nullptr
 

Friends

class G4RunManagerFactory
 

Additional Inherited Members

- Static Protected Attributes inherited from G4MTRunManager
static G4MTRUN_DLL G4ScoringManagermasterScM = nullptr
 
static G4MTRUN_DLL masterWorlds_t masterWorlds = G4MTRunManager::masterWorlds_t()
 
static G4MTRUN_DLL G4MTRunManagerfMasterRM = nullptr
 
static G4ThreadId masterThreadId = G4ThisThread::get_id()
 
static G4int seedOncePerCommunication = 0
 
- Static Protected Attributes inherited from G4RunManager
static G4RUN_DLL G4bool fGeometryHasBeenDestroyed = false
 

Detailed Description

Definition at line 66 of file G4TaskRunManager.hh.

Member Typedef Documentation

◆ InitializeSeedsCallback

Definition at line 73 of file G4TaskRunManager.hh.

◆ ProfilerConfig

◆ RunTaskGroup

Definition at line 74 of file G4TaskRunManager.hh.

Constructor & Destructor Documentation

◆ G4TaskRunManager() [1/2]

G4TaskRunManager::G4TaskRunManager ( G4bool useTBB = G4GetEnv<G4bool>("G4USE_TBB", false))

Definition at line 145 of file G4TaskRunManager.cc.

145: G4TaskRunManager(nullptr, useTBB, 0) {}
G4TaskRunManager(G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false))

◆ G4TaskRunManager() [2/2]

G4TaskRunManager::G4TaskRunManager ( G4VUserTaskQueue * taskQueue,
G4bool useTBB = G4GetEnv<G4bool>("G4USE_TBB", false),
G4int evtGrainsize = 0 )

Definition at line 77 of file G4TaskRunManager.cc.

78 : PTL::TaskRunManager(useTBB), eventGrainsize(grainsize)
79{
80 if (task_queue != nullptr) taskQueue = task_queue;
81
82 // override default of 2 from G4MTRunManager
84 fMasterRM = this;
85 MTkernel = static_cast<G4TaskRunManagerKernel*>(kernel);
86
87 G4int numberOfStaticAllocators = kernel->GetNumberOfStaticAllocators();
88 if (numberOfStaticAllocators > 0) {
90 msg1 << "There are " << numberOfStaticAllocators << " static G4Allocator objects detected.\n"
91 << "In multi-threaded mode, all G4Allocator objects must "
92 << "be dynamicly instantiated.";
93 G4Exception("G4TaskRunManager::G4TaskRunManager", "Run1035", FatalException, msg1);
94 }
95
98
99 // use default RandomNumberGenerator if created by user, or create default
100 masterRNGEngine = G4Random::getTheEngine();
101
104
105 //------------------------------------------------------------------------//
106 // handle threading
107 //------------------------------------------------------------------------//
108 auto _nthread_env = G4GetEnv<G4String>("G4FORCENUMBEROFTHREADS", "");
109 for (auto& itr : _nthread_env)
110 itr = (char)std::tolower(itr);
111
112 if (_nthread_env == "max")
114 else if (!_nthread_env.empty()) {
115 std::stringstream ss;
116 G4int _nthread_val = -1;
117 ss << _nthread_env;
118 ss >> _nthread_val;
119 if (_nthread_val > 0) forcedNwokers = _nthread_val;
120
122 }
123
124 //------------------------------------------------------------------------//
125 // option for forcing TBB
126 //------------------------------------------------------------------------//
127#ifdef GEANT4_USE_TBB
128 G4int _useTBB = G4GetEnv<G4int>("G4FORCE_TBB", (G4int)useTBB);
129 if (_useTBB > 0) useTBB = true;
130#else
131 if (useTBB) {
133 msg << "TBB was requested but Geant4 was not built with TBB support";
134 G4Exception("G4TaskRunManager::G4TaskRunManager(...)", "Run0131", JustWarning, msg);
135 }
136 useTBB = false;
137#endif
138
139 // handle TBB
141}
_Tp G4GetEnv(const std::string &env_id, _Tp _default=_Tp())
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
G4int numberOfEventToBeProcessed
static G4MTRUN_DLL G4ScoringManager * masterScM
static G4MTRUN_DLL G4MTRunManager * fMasterRM
G4int GetNumberOfStaticAllocators() const
G4RunManagerKernel * kernel
static G4ScoringManager * GetScoringManagerIfExist()
G4VUserTaskQueue *& taskQueue
void SetMasterUIManager(G4bool val)
static G4UImanager * GetUIpointer()
static void set_use_tbb(bool _v)
G4int G4GetNumberOfCores()

◆ ~G4TaskRunManager()

G4TaskRunManager::~G4TaskRunManager ( )
override

Definition at line 149 of file G4TaskRunManager.cc.

150{
151 // finalize profiler before shutting down the threads
153
154 // terminate all the workers
156
157 // trigger all G4AutoDelete instances
159
160 // delete the task-group
161 delete workTaskGroup;
162 workTaskGroup = nullptr;
163
164 // destroy the thread-pool
165 if (threadPool != nullptr) threadPool->destroy_threadpool();
166
168}
static void Finalize()
RunTaskGroup * workTaskGroup
void TerminateWorkers() override
G4ThreadPool *& threadPool
virtual void Terminate()
size_type destroy_threadpool()

Member Function Documentation

◆ AbortEvent()

void G4TaskRunManager::AbortEvent ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 656 of file G4TaskRunManager.cc.

657{
658 // nothing to do in the master thread
659}

◆ AbortRun()

void G4TaskRunManager::AbortRun ( G4bool softAbort = false)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 641 of file G4TaskRunManager.cc.

642{
643 // This method is valid only for GeomClosed or EventProc state
645 if (currentState == G4State_GeomClosed || currentState == G4State_EventProc) {
646 runAborted = true;
647 MTkernel->BroadcastAbortRun(softAbort);
648 }
649 else {
650 G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
651 }
652}
G4ApplicationState
@ G4State_EventProc
@ G4State_GeomClosed
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
void BroadcastAbortRun(G4bool softAbort)

◆ AddEventTask()

void G4TaskRunManager::AddEventTask ( G4int nt)
protectedvirtual

Definition at line 414 of file G4TaskRunManager.cc.

415{
416 if (verboseLevel > 1) G4cout << "Adding task " << nt << " to task-group..." << G4endl;
418}
G4GLOB_DLL std::ostream G4cout
enable_if_t< std::is_void< Up >::value, void > exec(Func func, Args... args)
Definition TaskGroup.hh:531

Referenced by CreateAndStartWorkers().

◆ ComputeNumberOfTasks()

void G4TaskRunManager::ComputeNumberOfTasks ( )
protectedvirtual

Definition at line 288 of file G4TaskRunManager.cc.

289{
290 G4int grainSize = (eventGrainsize == 0) ? (G4int)threadPool->size() : eventGrainsize;
291 grainSize = G4GetEnv<G4int>("G4FORCE_GRAINSIZE", grainSize, "Forcing grainsize...");
292 if (grainSize == 0) grainSize = 1;
293
294 G4int nEvtsPerTask =
295 (numberOfEventToBeProcessed > grainSize) ? (numberOfEventToBeProcessed / grainSize) : 1;
296
297 if (eventModuloDef > 0) {
299 }
300 else {
302 if (eventModulo < 1) eventModulo = 1;
303 }
304 if (eventModulo > nEvtsPerTask) {
305 G4int oldMod = eventModulo;
306 eventModulo = nEvtsPerTask;
307
309 msgd << "Event modulo is reduced to " << eventModulo << " (was " << oldMod << ")"
310 << " to distribute events to all threads.";
311 G4Exception("G4TaskRunManager::InitializeEventLoop()", "Run10035", JustWarning, msgd);
312 }
313 nEvtsPerTask = eventModulo;
314
315 if (fakeRun)
316 nEvtsPerTask = G4GetEnv<G4int>("G4FORCE_EVENTS_PER_TASK", nEvtsPerTask,
317 "Forcing number of events per task (overrides grainsize)...");
318 else
319 nEvtsPerTask = G4GetEnv<G4int>("G4FORCE_EVENTS_PER_TASK", nEvtsPerTask);
320
321 if (nEvtsPerTask < 1) nEvtsPerTask = 1;
322
323 numberOfTasks = numberOfEventToBeProcessed / nEvtsPerTask;
324 numberOfEventsPerTask = nEvtsPerTask;
325 eventModulo = numberOfEventsPerTask;
326
327 if (fakeRun && verboseLevel > 1) {
328 std::stringstream msg;
329 msg << "--> G4TaskRunManager::ComputeNumberOfTasks() --> " << numberOfTasks << " tasks with "
330 << numberOfEventsPerTask << " events/task...";
331
332 std::stringstream ss;
333 ss.fill('=');
334 ss << std::setw((G4int)msg.str().length()) << "";
335 G4cout << "\n" << ss.str() << "\n" << msg.str() << "\n" << ss.str() << "\n" << G4endl;
336 }
337}
size_type size() const

Referenced by CreateAndStartWorkers(), and InitializeEventLoop().

◆ ConstructScoringWorlds()

void G4TaskRunManager::ConstructScoringWorlds ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 539 of file G4TaskRunManager.cc.

540{
542 // Call base class stuff...
544
545 masterWorlds.clear();
548 for (G4int iWorld = 0; iWorld < nWorlds; ++iWorld) {
549 addWorld(iWorld, *itrW);
550 ++itrW;
551 }
552}
static void addWorld(G4int counter, G4VPhysicalVolume *w)
static G4MTRUN_DLL masterWorlds_t masterWorlds
virtual void ConstructScoringWorlds()
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
std::size_t GetNoWorlds() const

◆ CreateAndStartWorkers()

void G4TaskRunManager::CreateAndStartWorkers ( )
overrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 341 of file G4TaskRunManager.cc.

342{
343 // Now loop on requested number of workers
344 // This will also start the workers
345 // Currently we do not allow to change the
346 // number of threads: threads area created once
347 // Instead of pthread based workers, create tbbTask
348 static bool initializeStarted = false;
349
351
352 if (fakeRun) {
353 if (initializeStarted) {
354 auto initCmdStack = GetCommandStack();
355 if (!initCmdStack.empty()) {
356 threadPool->execute_on_all_threads([initCmdStack]() {
357 for (auto& itr : initCmdStack)
360 });
361 }
362 }
363 else {
364 std::stringstream msg;
365 msg << "--> G4TaskRunManager::CreateAndStartWorkers() --> "
366 << "Initializing workers...";
367
368 std::stringstream ss;
369 ss.fill('=');
370 ss << std::setw((G4int)msg.str().length()) << "";
371 G4cout << "\n" << ss.str() << "\n" << msg.str() << "\n" << ss.str() << "\n" << G4endl;
372
375 }
376 initializeStarted = true;
377 }
378 else {
379 auto initCmdStack = GetCommandStack();
380 if (!initCmdStack.empty()) {
381 threadPool->execute_on_all_threads([initCmdStack]() {
382 for (auto& itr : initCmdStack)
384 });
385 }
386
387 // cleans up a previous run and events in case a thread
388 // does not execute any tasks
390
391 {
392 std::stringstream msg;
393 msg << "--> G4TaskRunManager::CreateAndStartWorkers() --> "
394 << "Creating " << numberOfTasks << " tasks with " << numberOfEventsPerTask
395 << " events/task...";
396
397 std::stringstream ss;
398 ss.fill('=');
399 ss << std::setw((G4int)msg.str().length()) << "";
400 G4cout << "\n" << ss.str() << "\n" << msg.str() << "\n" << ss.str() << "\n" << G4endl;
401 }
402
404 for (G4int nt = 0; nt < numberOfTasks + 1; ++nt) {
405 if (remaining > 0) AddEventTask(nt);
406 remaining -= numberOfEventsPerTask;
407 }
409 }
410}
std::vector< G4String > GetCommandStack()
static std::vector< G4String > & InitCommandStack()
virtual void AddEventTask(G4int)
virtual void ComputeNumberOfTasks()
G4int ApplyCommand(const char *aCommand)
static G4WorkerTaskRunManager * GetWorkerRunManager()
void execute_on_all_threads(FuncT &&_func)

Referenced by InitializeEventLoop().

◆ GetGrainsize()

G4int G4TaskRunManager::GetGrainsize ( ) const
inline

Definition at line 99 of file G4TaskRunManager.hh.

99{ return eventGrainsize; }

◆ GetMasterRunManager()

◆ GetMasterThreadId()

G4ThreadId G4TaskRunManager::GetMasterThreadId ( )
static

Definition at line 172 of file G4TaskRunManager.cc.

173{
175}
static G4ThreadId GetMasterThreadId()

◆ GetMTMasterRunManagerKernel()

G4TaskRunManagerKernel * G4TaskRunManager::GetMTMasterRunManagerKernel ( )
static

Definition at line 70 of file G4TaskRunManager.cc.

71{
72 return GetMasterRunManager()->MTkernel;
73}
static G4TaskRunManager * GetMasterRunManager()

◆ GetNumberActiveThreads()

size_t G4TaskRunManager::GetNumberActiveThreads ( ) const
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 105 of file G4TaskRunManager.hh.

106 {
108 }
virtual size_t GetNumberActiveThreads() const

◆ GetNumberOfEventsPerTask()

G4int G4TaskRunManager::GetNumberOfEventsPerTask ( ) const
inline

Definition at line 101 of file G4TaskRunManager.hh.

101{ return numberOfEventsPerTask; }

◆ GetNumberOfTasks()

G4int G4TaskRunManager::GetNumberOfTasks ( ) const
inline

Definition at line 100 of file G4TaskRunManager.hh.

100{ return numberOfTasks; }

◆ GetNumberOfThreads()

G4int G4TaskRunManager::GetNumberOfThreads ( ) const
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 215 of file G4TaskRunManager.cc.

216{
217 // If the ThreadPool isn't initialized, it will return 0 even if we've already
218 // set nworkers
220}
virtual int GetNumberOfThreads() const

◆ Initialize() [1/2]

void G4TaskRunManager::Initialize ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 224 of file G4TaskRunManager.cc.

225{
226 G4bool firstTime = (threadPool == nullptr);
227 if (firstTime) InitializeThreadPool();
228
230
231 // make sure all worker threads are set up.
233 if (firstTime) G4RunManager::SetRunIDCounter(0);
234 // G4UImanager::GetUIpointer()->SetIgnoreCmdNotFound(true);
235}
bool G4bool
Definition G4Types.hh:86
virtual void Initialize()
void SetRunIDCounter(G4int i)
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
void InitializeThreadPool() override

◆ Initialize() [2/2]

void G4TaskRunManager::Initialize ( uint64_t nthreads)
inlineoverridevirtual

Reimplemented from PTL::TaskRunManager.

Definition at line 118 of file G4TaskRunManager.hh.

virtual void Initialize(uint64_t n=std::thread::hardware_concurrency())

◆ InitializeEventLoop()

void G4TaskRunManager::InitializeEventLoop ( G4int n_event,
const char * macroFile = nullptr,
G4int n_select = -1 )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 446 of file G4TaskRunManager.cc.

447{
448 MTkernel->SetUpDecayChannels();
451
452 if (!fakeRun) {
453 nSeedsUsed = 0;
454 nSeedsFilled = 0;
455
456 if (verboseLevel > 0) timer->Start();
457
458 n_select_msg = n_select;
459 if (macroFile != nullptr) {
460 if (n_select_msg < 0) n_select_msg = n_event;
461
462 msgText = "/control/execute ";
463 msgText += macroFile;
464 selectMacro = macroFile;
465 }
466 else {
467 n_select_msg = -1;
468 selectMacro = "";
469 }
470
472
473 // initialize seeds
474 // If user did not implement InitializeSeeds,
475 // use default: nSeedsPerEvent seeds per event
476
477 if (n_event > 0) {
478 G4bool _overload = InitializeSeeds(n_event);
479 G4bool _functor = false;
480 if (!_overload) _functor = initSeedsCallback(n_event, nSeedsPerEvent, nSeedsFilled);
481 if (!_overload && !_functor) {
483 switch (SeedOncePerCommunication()) {
484 case 0:
485 nSeedsFilled = n_event;
486 break;
487 case 1:
488 nSeedsFilled = numberOfTasks;
489 break;
490 case 2:
491 nSeedsFilled = n_event / eventModulo + 1;
492 break;
493 default:
495 msgd << "Parameter value <" << SeedOncePerCommunication()
496 << "> of seedOncePerCommunication is invalid. It is reset "
497 "to 0.";
498 G4Exception("G4TaskRunManager::InitializeEventLoop()", "Run10036", JustWarning, msgd);
500 nSeedsFilled = n_event;
501 }
502
503 // Generates up to nSeedsMax seed pairs only.
505 masterRNGEngine->flatArray(nSeedsPerEvent * nSeedsFilled, randDbl);
506 helper->Fill(randDbl, nSeedsFilled, n_event, nSeedsPerEvent);
507 }
508 }
509 }
510
511 // Now initialize workers. Check if user defined a WorkerThreadInitialization
512 if (userWorkerThreadInitialization == nullptr)
514
515 // Prepare UI commands for threads
517
518 // Start worker threads
520}
virtual void flatArray(const int size, double *vect)=0
static G4int SeedOncePerCommunication()
static void SetSeedOncePerCommunication(G4int val)
virtual void PrepareCommandsStack()
G4Timer * timer
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4int numberOfEventProcessed
G4String msgText
G4String selectMacro
void CreateAndStartWorkers() override
G4bool InitializeSeeds(G4int) override
InitializeSeedsCallback initSeedsCallback
static G4TemplateRNGHelper< T > * GetInstance()
void Fill(G4double *dbl, G4int nev, G4int nev_tot, G4int nrpe)
void Start()

◆ InitializeSeeds()

G4bool G4TaskRunManager::InitializeSeeds ( G4int )
inlineoverrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 182 of file G4TaskRunManager.hh.

182{ return false; }

Referenced by InitializeEventLoop().

◆ InitializeThreadPool()

void G4TaskRunManager::InitializeThreadPool ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 239 of file G4TaskRunManager.cc.

240{
241 if (poolInitialized && (threadPool != nullptr) && (workTaskGroup != nullptr)) {
242 G4Exception("G4TaskRunManager::InitializeThreadPool", "Run1040", JustWarning,
243 "Threadpool already initialized. Ignoring...");
244 return;
245 }
246
249
250 // create the joiners
251 if (workTaskGroup == nullptr) {
253 }
254
255 if (verboseLevel > 0) {
256 std::stringstream ss;
257 ss.fill('=');
258 ss << std::setw(90) << "";
259 G4cout << "\n" << ss.str() << G4endl;
260
262 G4cout << "G4TaskRunManager :: Using TBB..." << G4endl;
263 }
264 else {
265 G4cout << "G4TaskRunManager :: Using G4ThreadPool..." << G4endl;
266 }
267
268 G4cout << ss.str() << "\n" << G4endl;
269 }
270}
G4TaskGroup< void > RunTaskGroup
void SetVerbose(int val)
bool is_tbb_threadpool() const

Referenced by Initialize().

◆ MergeRun()

void G4TaskRunManager::MergeRun ( const G4Run * localRun)

Definition at line 564 of file G4TaskRunManager.cc.

565{
566 G4AutoLock l(&runMergerMutex);
567 if (currentRun != nullptr) currentRun->Merge(localRun);
568}
G4Run * currentRun
virtual void Merge(const G4Run *)
Definition G4Run.cc:65

◆ MergeScores()

void G4TaskRunManager::MergeScores ( const G4ScoringManager * localScoringManager)

Definition at line 556 of file G4TaskRunManager.cc.

557{
558 G4AutoLock l(&scorerMergerMutex);
559 if (masterScM != nullptr) masterScM->Merge(localScoringManager);
560}
void Merge(const G4ScoringManager *scMan)

◆ NewActionRequest()

void G4TaskRunManager::NewActionRequest ( WorkerActionRequest )
inlineoverrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 192 of file G4TaskRunManager.hh.

192{}

◆ ProcessOneEvent()

void G4TaskRunManager::ProcessOneEvent ( G4int i_event)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 274 of file G4TaskRunManager.cc.

275{
276 // Nothing to do
277}

◆ RefillSeeds()

void G4TaskRunManager::RefillSeeds ( )
overrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 422 of file G4TaskRunManager.cc.

423{
425 G4int nFill = 0;
426 switch (SeedOncePerCommunication()) {
427 case 0:
429 break;
430 case 1:
431 nFill = numberOfTasks - nSeedsFilled;
432 break;
433 case 2:
434 default:
436 }
437 // Generates up to nSeedsMax seed pairs only.
438 if (nFill > nSeedsMax) nFill = nSeedsMax;
439 masterRNGEngine->flatArray(nSeedsPerEvent * nFill, randDbl);
440 helper->Refill(randDbl, nFill);
441 nSeedsFilled += nFill;
442}
void Refill(G4double *dbl, G4int nev)

Referenced by SetUpAnEvent(), and SetUpNEvents().

◆ RequestWorkersProcessCommandsStack()

void G4TaskRunManager::RequestWorkersProcessCommandsStack ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 675 of file G4TaskRunManager.cc.

676{
678
679 auto process_commands_stack = []() {
681 if (mrm != nullptr) {
682 auto cmds = mrm->GetCommandStack();
683 for (const auto& itr : cmds)
684 G4UImanager::GetUIpointer()->ApplyCommand(itr); // TLS instance
686 }
687 };
688
689 if (threadPool != nullptr) threadPool->execute_on_all_threads(process_commands_stack);
690}
virtual void ThisWorkerProcessCommandsStackDone()

Referenced by TerminateWorkers().

◆ RunTermination()

void G4TaskRunManager::RunTermination ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 524 of file G4TaskRunManager.cc.

525{
526 // Wait for all worker threads to have finished the run
527 // i.e. wait for them to return from RunTermination()
528 // This guarantee that userrunaction for workers has been called
529
530 // Wait now for all threads to finish event-loop
532 // Now call base-class methof
535}
virtual void RunTermination()
virtual void TerminateEventLoop()
void WaitForEndEventLoopWorkers() override

◆ SetGrainsize()

void G4TaskRunManager::SetGrainsize ( G4int n)
inline

Definition at line 98 of file G4TaskRunManager.hh.

98{ eventGrainsize = n; }

◆ SetInitializeSeedsCallback()

void G4TaskRunManager::SetInitializeSeedsCallback ( InitializeSeedsCallback f)
inline

Definition at line 171 of file G4TaskRunManager.hh.

171{ initSeedsCallback = f; }

◆ SetNumberOfThreads()

void G4TaskRunManager::SetNumberOfThreads ( G4int n)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 188 of file G4TaskRunManager.cc.

189{
190 if (forcedNwokers > 0) {
191 if (verboseLevel > 0) {
193 msg << "\n### Number of threads is forced to " << forcedNwokers
194 << " by G4FORCENUMBEROFTHREADS environment variable. G4TaskRunManager::" << __FUNCTION__
195 << "(" << n << ") ignored ###";
196 G4Exception("G4TaskRunManager::SetNumberOfThreads(G4int)", "Run0132", JustWarning, msg);
197 }
199 }
200 else {
201 nworkers = n;
202 if (poolInitialized) {
203 if (verboseLevel > 0) {
204 std::stringstream ss;
205 ss << "\n### Thread-pool already initialized. Resizing to " << nworkers << "threads ###";
206 G4cout << ss.str() << "\n" << G4endl;
207 }
208 GetThreadPool()->resize(n);
209 }
210 }
211}
ThreadPool * GetThreadPool() const
void resize(size_type _n)

◆ SetUpAnEvent()

G4bool G4TaskRunManager::SetUpAnEvent ( G4Event * evt,
G4long & s1,
G4long & s2,
G4long & s3,
G4bool reseedRequired = true )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 572 of file G4TaskRunManager.cc.

574{
575 G4AutoLock l(&setUpEventMutex);
578 if (reseedRequired) {
580 G4int idx_rndm = nSeedsPerEvent * nSeedsUsed;
581 s1 = helper->GetSeed(idx_rndm);
582 s2 = helper->GetSeed(idx_rndm + 1);
583 if (nSeedsPerEvent == 3) s3 = helper->GetSeed(idx_rndm + 2);
584 ++nSeedsUsed;
586 }
588 return true;
589 }
590 return false;
591}
void SetEventID(G4int i)
Definition G4Event.hh:85
void RefillSeeds() override
virtual const T GetSeed(const G4int &sdId)

◆ SetUpNEvents()

G4int G4TaskRunManager::SetUpNEvents ( G4Event * evt,
G4SeedsQueue * seedsQueue,
G4bool reseedRequired = true )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 595 of file G4TaskRunManager.cc.

596{
597 G4AutoLock l(&setUpEventMutex);
599 G4int nevt = numberOfEventsPerTask;
600 G4int nmod = eventModulo;
604 }
606
607 if (reseedRequired) {
609 G4int nevRnd = nmod;
610 if (SeedOncePerCommunication() > 0) nevRnd = 1;
611 for (G4int i = 0; i < nevRnd; ++i) {
612 seedsQueue->push(helper->GetSeed(nSeedsPerEvent * nSeedsUsed));
613 seedsQueue->push(helper->GetSeed(nSeedsPerEvent * nSeedsUsed + 1));
614 if (nSeedsPerEvent == 3) seedsQueue->push(helper->GetSeed(nSeedsPerEvent * nSeedsUsed + 2));
615 nSeedsUsed++;
617 }
618 }
620 return nevt;
621 }
622 return 0;
623}

◆ StoreRNGStatus()

void G4TaskRunManager::StoreRNGStatus ( const G4String & filenamePrefix)
overrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 179 of file G4TaskRunManager.cc.

180{
181 std::ostringstream os;
182 os << randomNumberStatusDir << "G4Master_" << fn << ".rndm";
183 G4Random::saveEngineStatus(os.str().c_str());
184}
G4String randomNumberStatusDir

◆ TerminateOneEvent()

void G4TaskRunManager::TerminateOneEvent ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 281 of file G4TaskRunManager.cc.

282{
283 // Nothing to do
284}

◆ TerminateWorkers()

void G4TaskRunManager::TerminateWorkers ( )
overrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 627 of file G4TaskRunManager.cc.

628{
629 // Force workers to execute (if any) all UI commands left in the stack
631
632 if (workTaskGroup != nullptr) {
634 if (!fakeRun)
636 }
637}
void RequestWorkersProcessCommandsStack() override
Up join(Up accum={})
Definition TaskGroup.hh:654

Referenced by ~G4TaskRunManager().

◆ ThisWorkerEndEventLoop()

void G4TaskRunManager::ThisWorkerEndEventLoop ( )
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 164 of file G4TaskRunManager.hh.

164{}

◆ ThisWorkerProcessCommandsStackDone()

void G4TaskRunManager::ThisWorkerProcessCommandsStackDone ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 694 of file G4TaskRunManager.cc.

694{}

◆ ThisWorkerReady()

void G4TaskRunManager::ThisWorkerReady ( )
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 163 of file G4TaskRunManager.hh.

163{}

◆ ThisWorkerWaitForNextAction()

WorkerActionRequest G4TaskRunManager::ThisWorkerWaitForNextAction ( )
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 166 of file G4TaskRunManager.hh.

◆ ThreadPoolIsInitialized()

G4bool G4TaskRunManager::ThreadPoolIsInitialized ( ) const
inline

Definition at line 116 of file G4TaskRunManager.hh.

116{ return poolInitialized; }

◆ WaitForEndEventLoopWorkers()

void G4TaskRunManager::WaitForEndEventLoopWorkers ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 663 of file G4TaskRunManager.cc.

664{
665 if (workTaskGroup != nullptr) {
667 if (!fakeRun)
670 }
671}

Referenced by RunTermination().

◆ WaitForReadyWorkers()

void G4TaskRunManager::WaitForReadyWorkers ( )
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 161 of file G4TaskRunManager.hh.

161{}

Friends And Related Symbol Documentation

◆ G4RunManagerFactory

friend class G4RunManagerFactory
friend

Definition at line 68 of file G4TaskRunManager.hh.

Member Data Documentation

◆ initSeedsCallback

InitializeSeedsCallback G4TaskRunManager::initSeedsCallback
protected
Initial value:
= [](G4int, G4int&, G4int&) {
return false;
}

Definition at line 205 of file G4TaskRunManager.hh.

205 {
206 return false;
207 };

Referenced by InitializeEventLoop(), and SetInitializeSeedsCallback().

◆ poolInitialized

G4bool& G4TaskRunManager::poolInitialized = PTL::TaskRunManager::m_is_initialized
protected

◆ taskManager

G4TaskManager*& G4TaskRunManager::taskManager = PTL::TaskRunManager::m_task_manager
protected

Definition at line 203 of file G4TaskRunManager.hh.

◆ taskQueue

G4VUserTaskQueue*& G4TaskRunManager::taskQueue = PTL::TaskRunManager::m_task_queue
protected

Definition at line 202 of file G4TaskRunManager.hh.

Referenced by G4TaskRunManager().

◆ threadPool

◆ workTaskGroup

RunTaskGroup* G4TaskRunManager::workTaskGroup = nullptr
protected

The documentation for this class was generated from the following files: