Geant4 11.1.1
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 ()
 
virtual ~G4MTRunManagerKernel ()
 
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
 
- 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 ()
 

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 74 of file G4MTRunManagerKernel.cc.

76{
77 // This version of the constructor should never be called in sequential mode!
78#ifndef G4MULTITHREADED
80 msg << "Geant4 code is compiled without multi-threading support "
81 "(-DG4MULTITHREADED "
82 "is set to off).";
83 msg << " This type of RunManager can only be used in mult-threaded "
84 "applications.";
85 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0109",
86 FatalException, msg);
87#endif
88 G4AutoLock l(&workerRMMutex);
89 if(workerRMvector == nullptr)
90 workerRMvector = new std::vector<G4WorkerRunManager*>;
91 l.unlock();
92 // Set flag that a MT-type kernel has been instantiated
94}
@ 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

◆ ~G4MTRunManagerKernel()

G4MTRunManagerKernel::~G4MTRunManagerKernel ( )
virtual

Definition at line 97 of file G4MTRunManagerKernel.cc.

98{
99 G4AutoLock l(&workerRMMutex);
100 if(workerRMvector != nullptr)
101 {
102 if(workerRMvector->size() > 0)
103 {
105 msg << "G4MTRunManagerKernel is to be deleted while "
106 << workerRMvector->size() << " G4WorkerRunManager are still alive.";
107 G4Exception("G4RunManagerKernel::~G4RunManagerKernel()", "Run10035",
108 FatalException, msg);
109 }
110 delete workerRMvector;
111 workerRMvector = nullptr;
112 }
113}

Member Function Documentation

◆ BroadcastAbortRun()

void G4MTRunManagerKernel::BroadcastAbortRun ( G4bool  softAbort)

Definition at line 280 of file G4MTRunManagerKernel.cc.

281{
282 G4AutoLock wrmm(&workerRMMutex);
283
284 for(auto itr = workerRMvector->cbegin(); itr != workerRMvector->cend(); ++itr)
285 {
286 (*itr)->AbortRun(softAbort);
287 }
288}

Referenced by G4MTRunManager::AbortRun().

◆ GetWorkerThread()

G4WorkerThread * G4MTRunManagerKernel::GetWorkerThread ( )
static

Definition at line 124 of file G4MTRunManagerKernel.cc.

125{
126 return wThreadContext;
127}

◆ SetUpDecayChannels()

void G4MTRunManagerKernel::SetUpDecayChannels ( )

Definition at line 261 of file G4MTRunManagerKernel.cc.

262{
264 pItr->reset();
265 while((*pItr)())
266 {
267 G4DecayTable* dt = pItr->value()->GetDecayTable();
268 if(dt != nullptr)
269 {
270 G4int nCh = dt->entries();
271 for(G4int i = 0; i < nCh; ++i)
272 {
273 dt->GetDecayChannel(i)->GetDaughter(0);
274 }
275 }
276 }
277}
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
protectedvirtual

Reimplemented from G4RunManagerKernel.

Definition at line 116 of file G4MTRunManagerKernel.cc.

117{
118 // Behavior is the same as base class (sequential mode)
119 // ShadowProcess pointer == process poitner
121}
virtual void SetupShadowProcess() const

◆ StartThread()

void G4MTRunManagerKernel::StartThread ( G4WorkerThread context)
static

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

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

Definition at line 130 of file G4MTRunManagerKernel.cc.

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

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