Geant4 11.2.2
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 ()
 
 ~G4TaskRunManagerKernel () override=default
 
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 override
 
- Protected Member Functions inherited from G4RunManagerKernel
 G4RunManagerKernel (RMKType rmkType)
 
void SetupDefaultRegion ()
 
void SetupPhysics ()
 
void ResetNavigator ()
 
void BuildPhysicsTables (G4bool fakeRun)
 
void CheckRegions ()
 
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 67 of file G4TaskRunManagerKernel.hh.

Constructor & Destructor Documentation

◆ G4TaskRunManagerKernel()

G4TaskRunManagerKernel::G4TaskRunManagerKernel ( )

Definition at line 70 of file G4TaskRunManagerKernel.cc.

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

◆ ~G4TaskRunManagerKernel()

G4TaskRunManagerKernel::~G4TaskRunManagerKernel ( )
overridedefault

Member Function Documentation

◆ BroadcastAbortRun()

void G4TaskRunManagerKernel::BroadcastAbortRun ( G4bool softAbort)

Definition at line 329 of file G4TaskRunManagerKernel.cc.

330{
331 G4ConsumeParameters(softAbort);
332}
void G4ConsumeParameters(_Args &&...)
Definition templates.hh:177

Referenced by G4TaskRunManager::AbortRun().

◆ ExecuteWorkerInit()

void G4TaskRunManagerKernel::ExecuteWorkerInit ( )
static

Definition at line 220 of file G4TaskRunManagerKernel.cc.

221{
222 // because of TBB
223 if (G4MTRunManager::GetMasterThreadId() == G4ThisThread::get_id()) {
225 auto _fut = taskManager->async(ExecuteWorkerInit);
226 return _fut->get();
227 }
228
229 // this check is for TBB as there is not a way to run an initialization
230 // routine on each thread
231 if (!workerRM()) InitializeWorker();
232
233 auto& wrm = workerRM();
234 assert(wrm.get() != nullptr);
235 wrm->DoCleanup();
236}
static G4ThreadId GetMasterThreadId()
static G4TaskRunManager * GetMasterRunManager()
std::shared_ptr< PackagedTask< RetT, Args... > > async(FuncT &&func, Args &&... args)
TaskManager * GetTaskManager() const

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

◆ ExecuteWorkerTask()

void G4TaskRunManagerKernel::ExecuteWorkerTask ( )
static

Definition at line 240 of file G4TaskRunManagerKernel.cc.

241{
242 // because of TBB
243 if (G4MTRunManager::GetMasterThreadId() == G4ThisThread::get_id()) {
245 auto _fut = taskManager->async(ExecuteWorkerTask);
246 return _fut->get();
247 }
248
249 // this check is for TBB as there is not a way to run an initialization
250 // routine on each thread
251 if (!workerRM()) InitializeWorker();
252
253 auto& wrm = workerRM();
254 assert(wrm.get() != nullptr);
255 wrm->DoWork();
256}

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

◆ GetWorkerThread()

G4WorkerThread * G4TaskRunManagerKernel::GetWorkerThread ( )
static

Definition at line 118 of file G4TaskRunManagerKernel.cc.

119{
120 return context().get();
121}

◆ InitCommandStack()

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

Definition at line 305 of file G4TaskRunManagerKernel.cc.

306{
307 return initCmdStack;
308}
static G4RUN_DLL std::vector< G4String > initCmdStack

Referenced by G4TaskRunManager::CreateAndStartWorkers().

◆ InitializeWorker()

void G4TaskRunManagerKernel::InitializeWorker ( )
static

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

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

Definition at line 125 of file G4TaskRunManagerKernel.cc.

126{
127 if (context() && workerRM()) return;
128
130 if (G4MTRunManager::GetMasterThreadId() == G4ThisThread::get_id()) {
131 G4TaskManager* taskManager = mrm->GetTaskManager();
132 auto _fut = taskManager->async(InitializeWorker);
133 _fut->wait();
134 return;
135 }
136
137 //!!!!!!!!!!!!!!!!!!!!!!!!!!
138 //!!!!!! IMPORTANT !!!!!!!!!
139 //!!!!!!!!!!!!!!!!!!!!!!!!!!
140 // Here is not sequential anymore and G4UserWorkerThreadInitialization is
141 // a shared user initialization class
142 // This means this method cannot use data memebers of G4RunManagerKernel
143 // unless they are invariant ("read-only") and can be safely shared.
144 // All the rest that is not invariant should be incapsualted into
145 // the context (or, as for wThreadContext be G4ThreadLocal)
146 //!!!!!!!!!!!!!!!!!!!!!!!!!!
147
149 context() = std::make_unique<G4WorkerThread>();
150
151 //============================
152 // Step-0: Thread ID
153 //============================
154 // Initliazie per-thread stream-output
155 // The following line is needed before we actually do IO initialization
156 // becasue the constructor of UI manager resets the IO destination.
157 context()->SetNumberThreads((G4int)mrm->GetThreadPool()->size());
158 context()->SetThreadId(G4int(G4ThreadPool::get_this_thread_id() - 1));
159 G4int thisID = context()->GetThreadId();
162
163 //============================
164 // Optimization: optional
165 //============================
166 // Enforce thread affinity if requested
167 context()->SetPinAffinity(mrm->GetPinAffinity());
168
169 //============================
170 // Step-1: Random number engine
171 //============================
172 // RNG Engine needs to be initialized by "cloning" the master one.
173 const CLHEP::HepRandomEngine* masterEngine = mrm->getMasterRandomEngine();
175
176 //============================
177 // Step-2: Initialize worker thread
178 //============================
179 if (mrm->GetUserWorkerInitialization() != nullptr)
181
182 if (mrm->GetUserActionInitialization() != nullptr) {
184 if (sv != nullptr) G4VSteppingVerbose::SetInstance(sv);
185 }
186 // Now initialize worker part of shared objects (geometry/physics)
187 context()->BuildGeometryAndPhysicsVector();
188 workerRM().reset(static_cast<G4WorkerTaskRunManager*>(
190 auto& wrm = workerRM();
191 wrm->SetWorkerThread(context().get());
192
193 //================================
194 // Step-3: Setup worker run manager
195 //================================
196 // Set the detector and physics list to the worker thread. Share with master
198 wrm->G4RunManager::SetUserInitialization(const_cast<G4VUserDetectorConstruction*>(detector));
199 const G4VUserPhysicsList* physicslist = mrm->GetUserPhysicsList();
200 wrm->SetUserInitialization(const_cast<G4VUserPhysicsList*>(physicslist));
201
202 //================================
203 // Step-4: Initialize worker run manager
204 //================================
205 if (mrm->GetUserActionInitialization() != nullptr)
207 if (mrm->GetUserWorkerInitialization() != nullptr)
209
210 workerRM()->Initialize();
211
212 for (auto& itr : initCmdStack)
214
215 wrm->ProcessUI();
216}
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)
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
virtual G4WorkerRunManager * CreateWorkerRunManager() const
static void SetInstance(G4VSteppingVerbose *Instance)
virtual G4VSteppingVerbose * InitializeSteppingVerbose() const
virtual void Build() const =0
ThreadPool * GetThreadPool() const
static uintmax_t get_this_thread_id()
size_type size() const
G4int WorkerThreadJoinsPool()
void G4SetThreadId(G4int aNewValue)

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

◆ SetUpDecayChannels()

void G4TaskRunManagerKernel::SetUpDecayChannels ( )

Definition at line 312 of file G4TaskRunManagerKernel.cc.

313{
315 pItr->reset();
316 while ((*pItr)()) {
317 G4DecayTable* dt = pItr->value()->GetDecayTable();
318 if (dt != nullptr) {
319 G4int nCh = dt->entries();
320 for (G4int i = 0; i < nCh; i++) {
321 dt->GetDecayChannel(i)->GetDaughter(0);
322 }
323 }
324 }
325}
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
overrideprotectedvirtual

Reimplemented from G4RunManagerKernel.

Definition at line 88 of file G4TaskRunManagerKernel.cc.

89{
90 // Behavior is the same as base class (sequential mode)
91 // ShadowProcess pointer == process poitner
93}
virtual void SetupShadowProcess() const

◆ TerminateWorker() [1/2]

void G4TaskRunManagerKernel::TerminateWorker ( )
static

Definition at line 267 of file G4TaskRunManagerKernel.cc.

268{
269 if (workerRM()) TerminateWorker(workerRM().get());
270 workerRM().reset();
271 context().reset();
272}

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

◆ TerminateWorker() [2/2]

void G4TaskRunManagerKernel::TerminateWorker ( G4WorkerTaskRunManager * wrm)
static

Definition at line 286 of file G4TaskRunManagerKernel.cc.

287{
288 if (wrm == nullptr) return;
289
290 //===============================
291 // Step-6: Terminate worker thread
292 //===============================
294 if ((mrm != nullptr) && (mrm->GetUserWorkerInitialization() != nullptr))
296
297 G4WorkerThread* _context = wrm->GetWorkerThread();
299
301}
G4WorkerThread * GetWorkerThread() const
static void DestroyGeometryAndPhysicsVector()
G4int WorkerThreadLeavesPool()

◆ TerminateWorkerRunEventLoop() [1/2]

void G4TaskRunManagerKernel::TerminateWorkerRunEventLoop ( )
static

Definition at line 260 of file G4TaskRunManagerKernel.cc.

261{
262 if (workerRM()) TerminateWorkerRunEventLoop(workerRM().get());
263}

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

◆ TerminateWorkerRunEventLoop() [2/2]

void G4TaskRunManagerKernel::TerminateWorkerRunEventLoop ( G4WorkerTaskRunManager * wrm)
static

Definition at line 276 of file G4TaskRunManagerKernel.cc.

277{
278 if (wrm == nullptr) return;
279
280 wrm->TerminateEventLoop();
281 wrm->RunTermination();
282}

Member Data Documentation

◆ initCmdStack

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

Definition at line 66 of file G4TaskRunManagerKernel.hh.

67: public G4RunManagerKernel
68{
69 public:
71 ~G4TaskRunManagerKernel() override = default;
72
73 public: // with descroption
75 // G4ThreadPool tasks
76 static void InitializeWorker();
77 static void ExecuteWorkerInit();
78 static void ExecuteWorkerTask();
79 static void TerminateWorkerRunEventLoop();
80 static void TerminateWorker();
83
84 static std::vector<G4String>& InitCommandStack();
85
86 // Fill decay tables with particle definition pointers of
87 // decay products. This method has to be invoked by
88 // MTRunManager before event loop starts on workers.
89 void SetUpDecayChannels();
90
91 // This method should be invoked by G4TaskRunManager
92 void BroadcastAbortRun(G4bool softAbort);
93
94 protected:
95 void SetupShadowProcess() const override;
96 G4RUN_DLL static std::vector<G4String> initCmdStack;
97};
98
99#endif // G4TaskRunManagerKernel_hh
bool G4bool
Definition G4Types.hh:86
void SetupShadowProcess() const override
void BroadcastAbortRun(G4bool softAbort)
~G4TaskRunManagerKernel() override=default
static G4WorkerThread * GetWorkerThread()
static std::vector< G4String > & InitCommandStack()
#define G4RUN_DLL
Definition rundefs.hh:45

Referenced by InitCommandStack(), and InitializeWorker().


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