Geant4 10.7.0
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 WorkerUpdateWorldVolume ()
 
void UpdateRegion ()
 
void DumpRegion (const G4String &rname) const
 
void DumpRegion (G4Region *region=0) const
 
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
 
G4RegiondefaultRegionForParallelWorld
 
G4bool geometryNeedsToBeClosed
 

Detailed Description

Definition at line 65 of file G4MTRunManagerKernel.hh.

Constructor & Destructor Documentation

◆ G4MTRunManagerKernel()

G4MTRunManagerKernel::G4MTRunManagerKernel ( )

Definition at line 39 of file G4MTRunManagerKernel.cc.

41{
42 // This version of the constructor should never be called in sequential mode!
43#ifndef G4MULTITHREADED
45 msg << "Geant4 code is compiled without multi-threading support "
46 "(-DG4MULTITHREADED "
47 "is set to off).";
48 msg << " This type of RunManager can only be used in mult-threaded "
49 "applications.";
50 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0109",
51 FatalException, msg);
52#endif
53 G4AutoLock l(&workerRMMutex);
54 if(!workerRMvector)
55 workerRMvector = new std::vector<G4WorkerRunManager*>;
56 l.unlock();
57 // Set flag that a MT-type kernel has been instantiated
59}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
void SetMultithreadedApplication(G4bool value)
Definition: G4Threading.cc:129

◆ ~G4MTRunManagerKernel()

G4MTRunManagerKernel::~G4MTRunManagerKernel ( )
virtual

Definition at line 61 of file G4MTRunManagerKernel.cc.

62{
63 G4AutoLock l(&workerRMMutex);
64 if(workerRMvector)
65 {
66 if(workerRMvector->size() > 0)
67 {
69 msg << "G4MTRunManagerKernel is to be deleted while "
70 << workerRMvector->size() << " G4WorkerRunManager are still alive.";
71 G4Exception("G4RunManagerKernel::~G4RunManagerKernel()", "Run10035",
72 FatalException, msg);
73 }
74 delete workerRMvector;
75 workerRMvector = 0;
76 }
77}

Member Function Documentation

◆ BroadcastAbortRun()

void G4MTRunManagerKernel::BroadcastAbortRun ( G4bool  softAbort)

Definition at line 269 of file G4MTRunManagerKernel.cc.

270{
271 G4AutoLock wrmm(&workerRMMutex);
272 std::vector<G4WorkerRunManager*>::iterator itr = workerRMvector->begin();
273 for(; itr != workerRMvector->end(); itr++)
274 {
275 (*itr)->AbortRun(softAbort);
276 }
277}

Referenced by G4MTRunManager::AbortRun().

◆ GetWorkerThread()

G4WorkerThread * G4MTRunManagerKernel::GetWorkerThread ( )
static

Definition at line 109 of file G4MTRunManagerKernel.cc.

110{
111 return wThreadContext;
112}

◆ SetUpDecayChannels()

void G4MTRunManagerKernel::SetUpDecayChannels ( )

Definition at line 250 of file G4MTRunManagerKernel.cc.

251{
254 pItr->reset();
255 while((*pItr)())
256 {
257 G4DecayTable* dt = pItr->value()->GetDecayTable();
258 if(dt)
259 {
260 G4int nCh = dt->entries();
261 for(G4int i = 0; i < nCh; i++)
262 {
263 dt->GetDecayChannel(i)->GetDaughter(0);
264 }
265 }
266 }
267}
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 79 of file G4MTRunManagerKernel.cc.

80{
81 // Behavior is the same as base class (sequential mode)
82 // ShadowProcess pointer == process poitner
84}
virtual void SetupShadowProcess() const

◆ StartThread()

void G4MTRunManagerKernel::StartThread ( G4WorkerThread context)
static

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

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

Definition at line 114 of file G4MTRunManagerKernel.cc.

115{
116 //!!!!!!!!!!!!!!!!!!!!!!!!!!
117 //!!!!!! IMPORTANT !!!!!!!!!
118 //!!!!!!!!!!!!!!!!!!!!!!!!!!
119 // Here is not sequential anymore and G4UserWorkerThreadInitialization is
120 // a shared user initialization class
121 // This means this method cannot use data memebers of G4RunManagerKernel
122 // unless they are invariant ("read-only") and can be safely shared.
123 // All the rest that is not invariant should be incapsualted into
124 // the context (or, as for wThreadContext be G4ThreadLocal)
125 //!!!!!!!!!!!!!!!!!!!!!!!!!!
126 //#ifdef G4MULTITHREADED
127 // turnontpmalloc();
128 //#endif
130 wThreadContext = context;
132
133 //============================
134 // Step-0: Thread ID
135 //============================
136 // Initliazie per-thread stream-output
137 // The following line is needed before we actually do IO initialization
138 // becasue the constructor of UI manager resets the IO destination.
139 G4int thisID = wThreadContext->GetThreadId();
142
143 //============================
144 // Optimization: optional
145 //============================
146 // Enforce thread affinity if requested
147 wThreadContext->SetPinAffinity(masterRM->GetPinAffinity());
148
149 //============================
150 // Step-1: Random number engine
151 //============================
152 // RNG Engine needs to be initialized by "cloning" the master one.
153 const CLHEP::HepRandomEngine* masterEngine =
154 masterRM->getMasterRandomEngine();
155 masterRM->GetUserWorkerThreadInitialization()->SetupRNGEngine(masterEngine);
156
157 //============================
158 // Step-2: Initialize worker thread
159 //============================
160 if(masterRM->GetUserWorkerInitialization())
161 {
163 }
164 if(masterRM->GetUserActionInitialization())
165 {
168 if(sv)
169 {
171 }
172 }
173 // Now initialize worker part of shared objects (geometry/physics)
174 wThreadContext->BuildGeometryAndPhysicsVector();
175 G4WorkerRunManager* wrm =
177 wrm->SetWorkerThread(wThreadContext);
178 G4AutoLock wrmm(&workerRMMutex);
179 workerRMvector->push_back(wrm);
180 wrmm.unlock();
181
182 //================================
183 // Step-3: Setup worker run manager
184 //================================
185 // Set the detector and physics list to the worker thread. Share with master
186 const G4VUserDetectorConstruction* detector =
187 masterRM->GetUserDetectorConstruction();
188 wrm->G4RunManager::SetUserInitialization(
189 const_cast<G4VUserDetectorConstruction*>(detector));
190 const G4VUserPhysicsList* physicslist = masterRM->GetUserPhysicsList();
191 wrm->SetUserInitialization(const_cast<G4VUserPhysicsList*>(physicslist));
192
193 //================================
194 // Step-4: Initialize worker run manager
195 //================================
196 if(masterRM->GetUserActionInitialization())
197 {
199 }
200 if(masterRM->GetUserWorkerInitialization())
201 {
203 }
204 wrm->Initialize();
205
206 //================================
207 // Step5: Loop over requests from the master thread
208 //================================
209 // This function should enter a loop processing new runs and actions
210 // requests from master. It should block until thread is ready
211 // to terminate
212 wrm->DoWork();
213
214 //===============================
215 // Step-6: Terminate worker thread
216 //===============================
217 if(masterRM->GetUserWorkerInitialization())
218 {
220 }
221
222 wrmm.lock();
223 std::vector<G4WorkerRunManager*>::iterator itrWrm = workerRMvector->begin();
224 for(; itrWrm != workerRMvector->end(); itrWrm++)
225 {
226 if((*itrWrm) == wrm)
227 {
228 workerRMvector->erase(itrWrm);
229 break;
230 }
231 }
232 wrmm.unlock();
233 delete wrm;
234
235 //===============================
236 // Step-7: Cleanup split classes
237 //===============================
238 wThreadContext->DestroyGeometryAndPhysicsVector();
239 wThreadContext = 0;
240
242}
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:832
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)
Sets the worker context.
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: