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

#include <G4MTRunManagerKernel.hh>

+ Inheritance diagram for G4MTRunManagerKernel:

Public Member Functions

 G4MTRunManagerKernel ()
 
 ~G4MTRunManagerKernel () override
 
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 void StartThread (G4WorkerThread *context)
 
static G4WorkerThreadGetWorkerThread ()
 
- 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 ()
 

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 66 of file G4MTRunManagerKernel.hh.

Constructor & Destructor Documentation

◆ G4MTRunManagerKernel()

G4MTRunManagerKernel::G4MTRunManagerKernel ( )

Definition at line 72 of file G4MTRunManagerKernel.cc.

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

◆ ~G4MTRunManagerKernel()

G4MTRunManagerKernel::~G4MTRunManagerKernel ( )
override

Definition at line 92 of file G4MTRunManagerKernel.cc.

93{
94 G4AutoLock l(&workerRMMutex);
95 if (workerRMvector != nullptr) {
96 if (!workerRMvector->empty()) {
98 msg << "G4MTRunManagerKernel is to be deleted while " << workerRMvector->size()
99 << " G4WorkerRunManager are still alive.";
100 G4Exception("G4RunManagerKernel::~G4RunManagerKernel()", "Run10035", FatalException, msg);
101 }
102 delete workerRMvector;
103 workerRMvector = nullptr;
104 }
105}

Member Function Documentation

◆ BroadcastAbortRun()

void G4MTRunManagerKernel::BroadcastAbortRun ( G4bool softAbort)

Definition at line 255 of file G4MTRunManagerKernel.cc.

256{
257 G4AutoLock wrmm(&workerRMMutex);
258
259 for (const auto& itr : *workerRMvector) {
260 itr->AbortRun(softAbort);
261 }
262}

Referenced by G4MTRunManager::AbortRun().

◆ GetWorkerThread()

G4WorkerThread * G4MTRunManagerKernel::GetWorkerThread ( )
static

Definition at line 116 of file G4MTRunManagerKernel.cc.

117{
118 return wThreadContext;
119}

◆ SetUpDecayChannels()

void G4MTRunManagerKernel::SetUpDecayChannels ( )

Definition at line 239 of file G4MTRunManagerKernel.cc.

240{
242 pItr->reset();
243 while ((*pItr)()) {
244 G4DecayTable* dt = pItr->value()->GetDecayTable();
245 if (dt != nullptr) {
246 G4int nCh = dt->entries();
247 for (G4int i = 0; i < nCh; ++i) {
248 dt->GetDecayChannel(i)->GetDaughter(0);
249 }
250 }
251 }
252}
int G4int
Definition G4Types.hh:85
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 G4MTRunManager::InitializeEventLoop().

◆ SetupShadowProcess()

void G4MTRunManagerKernel::SetupShadowProcess ( ) const
overrideprotectedvirtual

Reimplemented from G4RunManagerKernel.

Definition at line 108 of file G4MTRunManagerKernel.cc.

109{
110 // Behavior is the same as base class (sequential mode)
111 // ShadowProcess pointer == process poitner
113}
virtual void SetupShadowProcess() const

◆ StartThread()

void G4MTRunManagerKernel::StartThread ( G4WorkerThread * context)
static

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

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

Definition at line 122 of file G4MTRunManagerKernel.cc.

123{
124 //!!!!!!!!!!!!!!!!!!!!!!!!!!
125 //!!!!!! IMPORTANT !!!!!!!!!
126 //!!!!!!!!!!!!!!!!!!!!!!!!!!
127 // Here is not sequential anymore and G4UserWorkerThreadInitialization is
128 // a shared user initialization class.
129 // This means this method cannot use data members of G4RunManagerKernel
130 // unless they are invariant ("read-only") and can be safely shared.
131 // All the rest that is not invariant should be incapsulated into
132 // the context (or, as for wThreadContext be G4ThreadLocal)
133 //!!!!!!!!!!!!!!!!!!!!!!!!!!
134 // #ifdef G4MULTITHREADED
135 // turnontpmalloc();
136 // #endif
138 wThreadContext = context;
140
141 //============================
142 // Step-0: Thread ID
143 //============================
144 // Initialise per-thread stream-output
145 // The following line is needed before we actually do IO initialisation
146 // because the constructor of UI manager resets the IO destination.
147 G4int thisID = wThreadContext->GetThreadId();
150
151 //============================
152 // Optimization: optional
153 //============================
154 // Enforce thread affinity if requested
155 wThreadContext->SetPinAffinity(masterRM->GetPinAffinity());
156
157 //============================
158 // Step-1: Random number engine
159 //============================
160 // RNG Engine needs to be initialised by "cloning" the master one.
161 const CLHEP::HepRandomEngine* masterEngine = masterRM->getMasterRandomEngine();
162 masterRM->GetUserWorkerThreadInitialization()->SetupRNGEngine(masterEngine);
163
164 //============================
165 // Step-2: Initialise worker thread
166 //============================
167 if (masterRM->GetUserWorkerInitialization() != nullptr) {
169 }
170 if (masterRM->GetUserActionInitialization() != nullptr) {
172 if (sv != nullptr) {
174 }
175 }
176 // Now initialise worker part of shared objects (geometry/physics)
177 wThreadContext->BuildGeometryAndPhysicsVector();
179 wrm->SetWorkerThread(wThreadContext);
180 G4AutoLock wrmm(&workerRMMutex);
181 workerRMvector->push_back(wrm);
182 wrmm.unlock();
183
184 //================================
185 // Step-3: Setup worker run manager
186 //================================
187 // Set the detector and physics list to the worker thread. Share with master
188 const G4VUserDetectorConstruction* detector = masterRM->GetUserDetectorConstruction();
189 wrm->G4RunManager::SetUserInitialization(const_cast<G4VUserDetectorConstruction*>(detector));
190 const G4VUserPhysicsList* physicslist = masterRM->GetUserPhysicsList();
191 wrm->SetUserInitialization(const_cast<G4VUserPhysicsList*>(physicslist));
192
193 //================================
194 // Step-4: Initialise worker run manager
195 //================================
196 if (masterRM->GetUserActionInitialization() != nullptr) {
198 }
199 if (masterRM->GetUserWorkerInitialization() != nullptr) {
201 }
202 wrm->Initialize();
203
204 //================================
205 // Step5: Loop over requests from the master thread
206 //================================
207 // This function should enter a loop processing new runs and actions
208 // requests from master. It should block until thread is ready
209 // to terminate
210 wrm->DoWork();
211
212 //===============================
213 // Step-6: Terminate worker thread
214 //===============================
215 if (masterRM->GetUserWorkerInitialization() != nullptr) {
217 }
218
219 wrmm.lock();
220 for (auto itrWrm = workerRMvector->cbegin(); itrWrm != workerRMvector->cend(); ++itrWrm) {
221 if ((*itrWrm) == wrm) {
222 workerRMvector->erase(itrWrm);
223 break;
224 }
225 }
226 wrmm.unlock();
227 delete wrm;
228
229 //===============================
230 // Step-7: Cleanup split classes
231 //===============================
232 wThreadContext->DestroyGeometryAndPhysicsVector();
233 wThreadContext = nullptr;
234
236}
G4int GetPinAffinity() const
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
static G4MTRunManager * GetMasterRunManager()
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
virtual void Initialize()
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
const G4VUserActionInitialization * GetUserActionInitialization() const
G4VUserActionInitialization * GetNonConstUserActionInitialization() const
const G4VUserPhysicsList * GetUserPhysicsList() const
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
void SetUpForAThread(G4int tId)
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
void SetWorkerThread(G4WorkerThread *wc)
void SetUserInitialization(G4VUserPhysicsList *userInit) override
G4int GetThreadId() const
static void BuildGeometryAndPhysicsVector()
static void DestroyGeometryAndPhysicsVector()
void SetPinAffinity(G4int aff) const
G4int WorkerThreadJoinsPool()
G4int WorkerThreadLeavesPool()
void G4SetThreadId(G4int aNewValue)

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