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

#include <G4TaskRunManagerKernel.hh>

+ Inheritance diagram for G4TaskRunManagerKernel:

Public Member Functions

 G4TaskRunManagerKernel ()
 
virtual ~G4TaskRunManagerKernel ()
 
void SetUpDecayChannels ()
 
void BroadcastAbortRun (G4bool softAbort)
 
- Public Member Functions inherited from G4RunManagerKernel
 G4RunManagerKernel ()
 
virtual ~G4RunManagerKernel ()
 
void DefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
void WorkerDefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
void SetPhysics (G4VUserPhysicsList *uPhys)
 
void InitializePhysics ()
 
G4bool RunInitialization (G4bool fakeRun=false)
 
void RunTermination ()
 
void UpdateRegion ()
 
void DumpRegion (const G4String &rname) const
 
void DumpRegion (G4Region *region=nullptr) const
 
void WorkerUpdateWorldVolume ()
 
void GeometryHasBeenModified ()
 
void PhysicsHasBeenModified ()
 
G4EventManagerGetEventManager () const
 
G4StackManagerGetStackManager () const
 
G4TrackingManagerGetTrackingManager () const
 
void SetPrimaryTransformer (G4PrimaryTransformer *pt)
 
G4PrimaryTransformerGetPrimaryTransformer () const
 
const G4StringGetVersionString () const
 
void SetVerboseLevel (G4int vl)
 
void SetGeometryToBeOptimized (G4bool vl)
 
G4int GetNumberOfParallelWorld () const
 
void SetNumberOfParallelWorld (G4int i)
 
G4VUserPhysicsListGetPhysicsList () const
 
G4VPhysicalVolumeGetCurrentWorld () const
 
G4int GetNumberOfStaticAllocators () const
 

Static Public Member Functions

static G4WorkerThreadGetWorkerThread ()
 
static void InitializeWorker ()
 
static void ExecuteWorkerInit ()
 
static void ExecuteWorkerTask ()
 
static void TerminateWorkerRunEventLoop ()
 
static void TerminateWorker ()
 
static void TerminateWorkerRunEventLoop (G4WorkerTaskRunManager *)
 
static void TerminateWorker (G4WorkerTaskRunManager *)
 
static std::vector< G4String > & InitCommandStack ()
 
- Static Public Member Functions inherited from G4RunManagerKernel
static G4RunManagerKernelGetRunManagerKernel ()
 

Protected Member Functions

void SetupShadowProcess () const
 
- Protected Member Functions inherited from G4RunManagerKernel
 G4RunManagerKernel (RMKType rmkType)
 
void SetupDefaultRegion ()
 
void SetupPhysics ()
 
void ResetNavigator ()
 
void BuildPhysicsTables (G4bool fakeRun)
 
void CheckRegions ()
 
virtual void SetupShadowProcess () const
 
void PropagateGenericIonID ()
 

Static Protected Attributes

static G4RUN_DLL std::vector< G4StringinitCmdStack = {}
 

Additional Inherited Members

- Public Types inherited from G4RunManagerKernel
enum  RMKType { sequentialRMK , masterRMK , workerRMK }
 
- Protected Attributes inherited from G4RunManagerKernel
RMKType runManagerKernelType
 
G4RegiondefaultRegion = nullptr
 
G4RegiondefaultRegionForParallelWorld = nullptr
 
G4bool geometryNeedsToBeClosed = true
 

Detailed Description

Definition at line 65 of file G4TaskRunManagerKernel.hh.

Constructor & Destructor Documentation

◆ G4TaskRunManagerKernel()

G4TaskRunManagerKernel::G4TaskRunManagerKernel ( )

Definition at line 70 of file G4TaskRunManagerKernel.cc.

72{
73 // This version of the constructor should never be called in sequential mode!
74#ifndef G4MULTITHREADED
76 msg << "Geant4 code is compiled without multi-threading support "
77 "(-DG4MULTITHREADED "
78 "is set to off).";
79 msg << " This type of RunManager can only be used in mult-threaded "
80 "applications.";
81 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0109",
82 FatalException, msg);
83#endif
84 // Set flag that a MT-type kernel has been instantiated
86}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
void SetMultithreadedApplication(G4bool value)
Definition: G4Threading.cc:129

◆ ~G4TaskRunManagerKernel()

G4TaskRunManagerKernel::~G4TaskRunManagerKernel ( )
virtual

Definition at line 90 of file G4TaskRunManagerKernel.cc.

90{}

Member Function Documentation

◆ BroadcastAbortRun()

void G4TaskRunManagerKernel::BroadcastAbortRun ( G4bool  softAbort)

Definition at line 357 of file G4TaskRunManagerKernel.cc.

358{
359 G4ConsumeParameters(softAbort);
360}
void G4ConsumeParameters(_Args &&...)
Definition: templates.hh:177

Referenced by G4TaskRunManager::AbortRun().

◆ ExecuteWorkerInit()

void G4TaskRunManagerKernel::ExecuteWorkerInit ( )
static

Definition at line 233 of file G4TaskRunManagerKernel.cc.

234{
235 // because of TBB
236 if(G4MTRunManager::GetMasterThreadId() == G4ThisThread::get_id())
237 {
238 G4TaskManager* taskManager =
240 auto _fut = taskManager->async(ExecuteWorkerInit);
241 return _fut->get();
242 }
243
244 // this check is for TBB as there is not a way to run an initialization
245 // routine on each thread
246 if(!workerRM())
248
249 auto& wrm = workerRM();
250 assert(wrm.get() != nullptr);
251 wrm->DoCleanup();
252}
static G4ThreadId GetMasterThreadId()
static G4TaskRunManager * GetMasterRunManager()
std::shared_ptr< PackagedTask< RetT, Args... > > async(FuncT &&func, Args &&... args)
Definition: TaskManager.hh:107
TaskManager * GetTaskManager() const

Referenced by G4TaskRunManager::CreateAndStartWorkers(), and ExecuteWorkerInit().

◆ ExecuteWorkerTask()

void G4TaskRunManagerKernel::ExecuteWorkerTask ( )
static

Definition at line 256 of file G4TaskRunManagerKernel.cc.

257{
258 // because of TBB
259 if(G4MTRunManager::GetMasterThreadId() == G4ThisThread::get_id())
260 {
261 G4TaskManager* taskManager =
263 auto _fut = taskManager->async(ExecuteWorkerTask);
264 return _fut->get();
265 }
266
267 // this check is for TBB as there is not a way to run an initialization
268 // routine on each thread
269 if(!workerRM())
271
272 auto& wrm = workerRM();
273 assert(wrm.get() != nullptr);
274 wrm->DoWork();
275}

Referenced by G4TaskRunManager::AddEventTask(), and ExecuteWorkerTask().

◆ GetWorkerThread()

G4WorkerThread * G4TaskRunManagerKernel::GetWorkerThread ( )
static

Definition at line 124 of file G4TaskRunManagerKernel.cc.

125{
126 return context().get();
127}

◆ InitCommandStack()

std::vector< G4String > & G4TaskRunManagerKernel::InitCommandStack ( )
static

Definition at line 329 of file G4TaskRunManagerKernel.cc.

330{
331 return initCmdStack;
332}
static G4RUN_DLL std::vector< G4String > initCmdStack

Referenced by G4TaskRunManager::CreateAndStartWorkers().

◆ InitializeWorker()

void G4TaskRunManagerKernel::InitializeWorker ( )
static

!!!!!!!!!!!!!!!!!!!!!!!!! !!!!! IMPORTANT !!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!

!!!!!!!!!!!!!!!!!!!!!!!!!

Definition at line 131 of file G4TaskRunManagerKernel.cc.

132{
133 if(context() && workerRM())
134 return;
135
137 if(G4MTRunManager::GetMasterThreadId() == G4ThisThread::get_id())
138 {
139 G4TaskManager* taskManager = mrm->GetTaskManager();
140 auto _fut = taskManager->async(InitializeWorker);
141 _fut->wait();
142 return;
143 }
144
145 //!!!!!!!!!!!!!!!!!!!!!!!!!!
146 //!!!!!! IMPORTANT !!!!!!!!!
147 //!!!!!!!!!!!!!!!!!!!!!!!!!!
148 // Here is not sequential anymore and G4UserWorkerThreadInitialization is
149 // a shared user initialization class
150 // This means this method cannot use data memebers of G4RunManagerKernel
151 // unless they are invariant ("read-only") and can be safely shared.
152 // All the rest that is not invariant should be incapsualted into
153 // the context (or, as for wThreadContext be G4ThreadLocal)
154 //!!!!!!!!!!!!!!!!!!!!!!!!!!
155
157 context().reset(new G4WorkerThread);
158
159 //============================
160 // Step-0: Thread ID
161 //============================
162 // Initliazie per-thread stream-output
163 // The following line is needed before we actually do IO initialization
164 // becasue the constructor of UI manager resets the IO destination.
165 context()->SetNumberThreads((G4int)mrm->GetThreadPool()->size());
166 context()->SetThreadId(G4int(G4ThreadPool::get_this_thread_id() - 1));
167 G4int thisID = context()->GetThreadId();
170
171 //============================
172 // Optimization: optional
173 //============================
174 // Enforce thread affinity if requested
175 context()->SetPinAffinity(mrm->GetPinAffinity());
176
177 //============================
178 // Step-1: Random number engine
179 //============================
180 // RNG Engine needs to be initialized by "cloning" the master one.
181 const CLHEP::HepRandomEngine* masterEngine = mrm->getMasterRandomEngine();
183
184 //============================
185 // Step-2: Initialize worker thread
186 //============================
189
191 {
194 if(sv)
196 }
197 // Now initialize worker part of shared objects (geometry/physics)
198 context()->BuildGeometryAndPhysicsVector();
199 workerRM().reset(static_cast<G4WorkerTaskRunManager*>(
201 auto& wrm = workerRM();
202 wrm->SetWorkerThread(context().get());
203
204 //================================
205 // Step-3: Setup worker run manager
206 //================================
207 // Set the detector and physics list to the worker thread. Share with master
208 const G4VUserDetectorConstruction* detector =
210 wrm->G4RunManager::SetUserInitialization(
211 const_cast<G4VUserDetectorConstruction*>(detector));
212 const G4VUserPhysicsList* physicslist = mrm->GetUserPhysicsList();
213 wrm->SetUserInitialization(const_cast<G4VUserPhysicsList*>(physicslist));
214
215 //================================
216 // Step-4: Initialize worker run manager
217 //================================
222
223 workerRM()->Initialize();
224
225 for(auto& itr : initCmdStack)
227
228 wrm->ProcessUI();
229}
int G4int
Definition: G4Types.hh:85
G4int GetPinAffinity() const
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
const G4VUserActionInitialization * GetUserActionInitialization() const
G4VUserActionInitialization * GetNonConstUserActionInitialization() const
const G4VUserPhysicsList * GetUserPhysicsList() const
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:884
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:495
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
virtual G4WorkerRunManager * CreateWorkerRunManager() const
static void SetInstance(G4VSteppingVerbose *Instance)
virtual void Build() const =0
virtual G4VSteppingVerbose * InitializeSteppingVerbose() const
ThreadPool * GetThreadPool() const
static uintmax_t get_this_thread_id()
Definition: ThreadPool.cc:215
size_type size() const
Definition: ThreadPool.hh:252
G4int WorkerThreadJoinsPool()
Definition: G4Threading.cc:132
void G4SetThreadId(G4int aNewValue)
Definition: G4Threading.cc:125

Referenced by G4TaskRunManager::CreateAndStartWorkers(), ExecuteWorkerInit(), ExecuteWorkerTask(), and InitializeWorker().

◆ SetUpDecayChannels()

void G4TaskRunManagerKernel::SetUpDecayChannels ( )

Definition at line 336 of file G4TaskRunManagerKernel.cc.

337{
340 pItr->reset();
341 while((*pItr)())
342 {
343 G4DecayTable* dt = pItr->value()->GetDecayTable();
344 if(dt)
345 {
346 G4int nCh = dt->entries();
347 for(G4int i = 0; i < nCh; i++)
348 {
349 dt->GetDecayChannel(i)->GetDaughter(0);
350 }
351 }
352 }
353}
G4VDecayChannel * GetDecayChannel(G4int index) const
G4int entries() const
void reset(G4bool ifSkipIon=true)
G4PTblDicIterator * GetIterator() const
static G4ParticleTable * GetParticleTable()
G4ParticleDefinition * GetDaughter(G4int anIndex)

Referenced by G4TaskRunManager::InitializeEventLoop().

◆ SetupShadowProcess()

void G4TaskRunManagerKernel::SetupShadowProcess ( ) const
protectedvirtual

Reimplemented from G4RunManagerKernel.

Definition at line 94 of file G4TaskRunManagerKernel.cc.

95{
96 // Behavior is the same as base class (sequential mode)
97 // ShadowProcess pointer == process poitner
99}
virtual void SetupShadowProcess() const

◆ TerminateWorker() [1/2]

void G4TaskRunManagerKernel::TerminateWorker ( )
static

Definition at line 287 of file G4TaskRunManagerKernel.cc.

288{
289 if(workerRM())
290 TerminateWorker(workerRM().get());
291 workerRM().reset();
292 context().reset();
293}

Referenced by TerminateWorker(), and G4TaskRunManager::TerminateWorkers().

◆ TerminateWorker() [2/2]

void G4TaskRunManagerKernel::TerminateWorker ( G4WorkerTaskRunManager wrm)
static

Definition at line 309 of file G4TaskRunManagerKernel.cc.

310{
311 if(!wrm)
312 return;
313
314 //===============================
315 // Step-6: Terminate worker thread
316 //===============================
318 if(mrm && mrm->GetUserWorkerInitialization())
320
321 G4WorkerThread* _context = wrm->GetWorkerThread();
323
325}
G4WorkerThread * GetWorkerThread() const
static void DestroyGeometryAndPhysicsVector()
G4int WorkerThreadLeavesPool()
Definition: G4Threading.cc:131

◆ TerminateWorkerRunEventLoop() [1/2]

void G4TaskRunManagerKernel::TerminateWorkerRunEventLoop ( )
static

Definition at line 279 of file G4TaskRunManagerKernel.cc.

280{
281 if(workerRM())
282 TerminateWorkerRunEventLoop(workerRM().get());
283}

Referenced by TerminateWorkerRunEventLoop(), and G4TaskRunManager::WaitForEndEventLoopWorkers().

◆ TerminateWorkerRunEventLoop() [2/2]

void G4TaskRunManagerKernel::TerminateWorkerRunEventLoop ( G4WorkerTaskRunManager wrm)
static

Definition at line 297 of file G4TaskRunManagerKernel.cc.

299{
300 if(!wrm)
301 return;
302
303 wrm->TerminateEventLoop();
304 wrm->RunTermination();
305}
virtual void RunTermination() override
virtual void TerminateEventLoop() override

Member Data Documentation

◆ initCmdStack

std::vector< G4String > G4TaskRunManagerKernel::initCmdStack = {}
staticprotected

Definition at line 92 of file G4TaskRunManagerKernel.hh.

Referenced by InitCommandStack(), and InitializeWorker().


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