Geant4  10.02.p03
G4MTRunManagerKernel Class Reference

#include <G4MTRunManagerKernel.hh>

Inheritance diagram for G4MTRunManagerKernel:
Collaboration 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 (void *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 ()
 
void PropagateGenericIonID ()
 

Static Private Attributes

static G4ThreadLocal G4WorkerThreadwThreadContext = 0
 
static std::vector< G4WorkerRunManager * > * workerRMvector = 0
 

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

39 {
40  //This version of the constructor should never be called in sequential mode!
41 #ifndef G4MULTITHREADED
43  msg<<"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
44  msg<<" This type of RunManager can only be used in mult-threaded applications.";
45  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0035",FatalException,msg);
46 #endif
47  G4AutoLock l(&workerRMMutex);
48  if(!workerRMvector) workerRMvector = new std::vector<G4WorkerRunManager*>;
49  l.unlock();
50  //Set flag that a MT-type kernel has been instantiated
52 }
void SetMultithreadedApplication(G4bool value)
Definition: G4Threading.cc:141
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
static std::vector< G4WorkerRunManager * > * workerRMvector
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
Here is the call graph for this function:

◆ ~G4MTRunManagerKernel()

G4MTRunManagerKernel::~G4MTRunManagerKernel ( )
virtual

Definition at line 54 of file G4MTRunManagerKernel.cc.

55 {
56  G4AutoLock l(&workerRMMutex);
57  if(workerRMvector)
58  {
59  if(workerRMvector->size()>0)
60  {
62  msg<<"G4MTRunManagerKernel is to be deleted while "
63  <<workerRMvector->size()<<" G4WorkerRunManager are still alive.";
64  G4Exception("G4RunManagerKernel::~G4RunManagerKernel()",
65  "Run10035",FatalException,msg);
66  }
67  delete workerRMvector;
68  workerRMvector = 0;
69  }
70 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
static std::vector< G4WorkerRunManager * > * workerRMvector
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
Here is the call graph for this function:

Member Function Documentation

◆ BroadcastAbortRun()

void G4MTRunManagerKernel::BroadcastAbortRun ( G4bool  softAbort)

Definition at line 244 of file G4MTRunManagerKernel.cc.

245 {
246  G4AutoLock wrmm(&workerRMMutex);
247  std::vector<G4WorkerRunManager*>::iterator itr = workerRMvector->begin();
248  for(;itr!=workerRMvector->end();itr++)
249  { (*itr)->AbortRun(softAbort); }
250 }
static std::vector< G4WorkerRunManager * > * workerRMvector
Here is the caller graph for this function:

◆ GetWorkerThread()

G4WorkerThread * G4MTRunManagerKernel::GetWorkerThread ( )
static

Definition at line 102 of file G4MTRunManagerKernel.cc.

103 { return wThreadContext; }
static G4ThreadLocal G4WorkerThread * wThreadContext

◆ SetUpDecayChannels()

void G4MTRunManagerKernel::SetUpDecayChannels ( )

Definition at line 227 of file G4MTRunManagerKernel.cc.

228 {
231  pItr->reset();
232  while((*pItr)())
233  {
234  G4DecayTable* dt = pItr->value()->GetDecayTable();
235  if(dt)
236  {
237  G4int nCh = dt->entries();
238  for(G4int i=0;i<nCh;i++)
239  { dt->GetDecayChannel(i)->GetDaughter(0); }
240  }
241  }
242 }
G4ParticleDefinition * GetDaughter(G4int anIndex)
int G4int
Definition: G4Types.hh:78
void reset(G4bool ifSkipIon=true)
G4int entries() const
static G4ParticleTable * GetParticleTable()
G4VDecayChannel * GetDecayChannel(G4int index) const
G4PTblDicIterator * GetIterator() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetupShadowProcess()

void G4MTRunManagerKernel::SetupShadowProcess ( ) const
protectedvirtual

Reimplemented from G4RunManagerKernel.

Definition at line 72 of file G4MTRunManagerKernel.cc.

73 {
74  //Behavior is the same as base class (sequential mode)
75  //ShadowProcess pointer == process poitner
77 }
virtual void SetupShadowProcess() const
Here is the call graph for this function:

◆ StartThread()

void * G4MTRunManagerKernel::StartThread ( void *  context)
static

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

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

Definition at line 105 of file G4MTRunManagerKernel.cc.

106 {
110  // Here is not sequential anymore and G4UserWorkerThreadInitialization is
111  // a shared user initialization class
112  // This means this method cannot use data memebers of G4RunManagerKernel
113  // unless they are invariant ("read-only") and can be safely shared.
114  // All the rest that is not invariant should be incapsualted into
115  // the context (or, as for wThreadContext be G4ThreadLocal)
117 //#ifdef G4MULTITHREADED
118 // turnontpmalloc();
119 //#endif
120 
121  wThreadContext = static_cast<G4WorkerThread*>(context);
123 
124 
125  //============================
126  //Step-0: Thread ID
127  //============================
128  //Initliazie per-thread stream-output
129  //The following line is needed before we actually do IO initialization
130  //becasue the constructor of UI manager resets the IO destination.
131  G4int thisID = wThreadContext->GetThreadId();
134 
135  //============================
136  //Optimization: optional
137  //============================
138  //Enforce thread affinity if requested
140 
141  //============================
142  //Step-1: Random number engine
143  //============================
144  //RNG Engine needs to be initialized by "cloning" the master one.
145  const CLHEP::HepRandomEngine* masterEngine = masterRM->getMasterRandomEngine();
146  masterRM->GetUserWorkerThreadInitialization()->SetupRNGEngine(masterEngine);
147 
148  //============================
149  //Step-2: Initialize worker thread
150  //============================
151  if(masterRM->GetUserWorkerInitialization())
153  if(masterRM->GetUserActionInitialization())
154  {
156  if ( sv ) { G4VSteppingVerbose::SetInstance(sv); }
157  }
158  //Now initialize worker part of shared objects (geometry/physics)
160  G4WorkerRunManager* wrm
163  G4AutoLock wrmm(&workerRMMutex);
164  workerRMvector->push_back(wrm);
165  wrmm.unlock();
166 
167  //================================
168  //Step-3: Setup worker run manager
169  //================================
170  // Set the detector and physics list to the worker thread. Share with master
171  const G4VUserDetectorConstruction* detector = masterRM->GetUserDetectorConstruction();
172  wrm->G4RunManager::SetUserInitialization(const_cast<G4VUserDetectorConstruction*>(detector));
173  const G4VUserPhysicsList* physicslist = masterRM->GetUserPhysicsList();
174  wrm->SetUserInitialization(const_cast<G4VUserPhysicsList*>(physicslist));
175 
176  //================================
177  //Step-4: Initialize worker run manager
178  //================================
179  if(masterRM->GetUserActionInitialization())
180  { masterRM->GetNonConstUserActionInitialization()->Build(); }
181  if(masterRM->GetUserWorkerInitialization())
182  { masterRM->GetUserWorkerInitialization()->WorkerStart(); }
183  wrm->Initialize();
184 
185  //================================
186  //Step5: Loop over requests from the master thread
187  //================================
188  //This function should enter a loop processing new runs and actions
189  //requests from master. It should block until thread is ready
190  //to terminate
191  wrm->DoWork();
192 
193  //===============================
194  //Step-6: Terminate worker thread
195  //===============================
196  if(masterRM->GetUserWorkerInitialization())
197  { masterRM->GetUserWorkerInitialization()->WorkerStop(); }
198 
199  wrmm.lock();
200  std::vector<G4WorkerRunManager*>::iterator itrWrm = workerRMvector->begin();
201  for(;itrWrm!=workerRMvector->end();itrWrm++)
202  {
203  if((*itrWrm)==wrm)
204  {
205  workerRMvector->erase(itrWrm);
206  break;
207  }
208  }
209  wrmm.unlock();
210  delete wrm;
211 
212  //===============================
213  //Step-7: Cleanup split classes
214  //===============================
216  wThreadContext = 0;
217 
218  return static_cast<void*>(0);
219 }
const G4VUserPhysicsList * GetUserPhysicsList() const
G4int GetPinAffinity() const
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:727
virtual G4VSteppingVerbose * InitializeSteppingVerbose() const
static std::vector< G4WorkerRunManager * > * workerRMvector
static void BuildGeometryAndPhysicsVector()
void G4SetThreadId(G4int aNewValue)
Definition: G4Threading.cc:137
virtual void SetUserInitialization(G4VUserPhysicsList *userInit)
int G4int
Definition: G4Types.hh:78
virtual G4WorkerRunManager * CreateWorkerRunManager() const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
static G4MTRunManager * GetMasterRunManager()
virtual void Build() const =0
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
static G4ThreadLocal G4WorkerThread * wThreadContext
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
void SetWorkerThread(G4WorkerThread *wc)
Sets the worker context.
void SetPinAffinity(G4int aff) const
static void SetInstance(G4VSteppingVerbose *Instance)
G4int GetThreadId() const
const G4VUserActionInitialization * GetUserActionInitialization() const
static void DestroyGeometryAndPhysicsVector()
virtual void Initialize()
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
G4VUserActionInitialization * GetNonConstUserActionInitialization() const
Here is the call graph for this function:

Member Data Documentation

◆ workerRMvector

std::vector< G4WorkerRunManager * > * G4MTRunManagerKernel::workerRMvector = 0
staticprivate

Definition at line 92 of file G4MTRunManagerKernel.hh.

◆ wThreadContext

G4ThreadLocal G4WorkerThread * G4MTRunManagerKernel::wThreadContext = 0
staticprivate

Definition at line 81 of file G4MTRunManagerKernel.hh.


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