Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 voidStartThread (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 ()
 

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 ( )

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()","Run0109",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:151
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
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 ( )
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
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

void G4MTRunManagerKernel::BroadcastAbortRun ( G4bool  softAbort)

Definition at line 245 of file G4MTRunManagerKernel.cc.

246 {
247  G4AutoLock wrmm(&workerRMMutex);
248  std::vector<G4WorkerRunManager*>::iterator itr = workerRMvector->begin();
249  for(;itr!=workerRMvector->end();itr++)
250  { (*itr)->AbortRun(softAbort); }
251 }

Here is the caller graph for this function:

G4WorkerThread * G4MTRunManagerKernel::GetWorkerThread ( )
static

Definition at line 102 of file G4MTRunManagerKernel.cc.

103 { return wThreadContext; }
void G4MTRunManagerKernel::SetUpDecayChannels ( )

Definition at line 228 of file G4MTRunManagerKernel.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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:

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
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
139  wThreadContext->SetPinAffinity(masterRM->GetPinAffinity());
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)
159  wThreadContext->BuildGeometryAndPhysicsVector();
160  G4WorkerRunManager* wrm
162  wrm->SetWorkerThread(wThreadContext);
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  //===============================
215  wThreadContext->DestroyGeometryAndPhysicsVector();
216  wThreadContext = 0;
217 
219  return static_cast<void*>(0);
220 }
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:728
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
int WorkerThreadLeavesPool()
Definition: G4Threading.cc:153
static void BuildGeometryAndPhysicsVector()
void G4SetThreadId(G4int aNewValue)
Definition: G4Threading.cc:147
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
virtual G4WorkerRunManager * CreateWorkerRunManager() const
virtual void SetUserInitialization(G4VUserPhysicsList *userInit)
int G4int
Definition: G4Types.hh:78
void SetPinAffinity(G4int aff) const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
static G4MTRunManager * GetMasterRunManager()
virtual void Build() const =0
G4int GetPinAffinity() const
G4int GetThreadId() const
int WorkerThreadJoinsPool()
Definition: G4Threading.cc:154
const G4VUserActionInitialization * GetUserActionInitialization() const
void SetWorkerThread(G4WorkerThread *wc)
Sets the worker context.
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
static void SetInstance(G4VSteppingVerbose *Instance)
const XML_Char * context
Definition: expat.h:434
G4VUserActionInitialization * GetNonConstUserActionInitialization() const
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
virtual G4VSteppingVerbose * InitializeSteppingVerbose() const
static void DestroyGeometryAndPhysicsVector()
virtual void Initialize()
const G4VUserPhysicsList * GetUserPhysicsList() const

Here is the call graph for this function:


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