Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions
G4MTRunManagerKernel Class Reference

#include <G4MTRunManagerKernel.hh>

Inheritance diagram for G4MTRunManagerKernel:
G4RunManagerKernel

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 ()
 
G4EventManager * GetEventManager () const
 
G4StackManager * GetStackManager () const
 
G4TrackingManager * GetTrackingManager () const
 
void SetPrimaryTransformer (G4PrimaryTransformer *pt)
 
G4PrimaryTransformer * GetPrimaryTransformer () const
 
const G4String & GetVersionString () const
 
void SetVerboseLevel (G4int vl)
 
void SetGeometryToBeOptimized (G4bool vl)
 
G4int GetNumberOfParallelWorld () const
 
void SetNumberOfParallelWorld (G4int i)
 
G4VUserPhysicsList * GetPhysicsList () const
 
G4VPhysicalVolume * GetCurrentWorld () const
 
G4int GetNumberOfStaticAllocators () const
 

Static Public Member Functions

static void * StartThread (void *context)
 
static G4WorkerThread * GetWorkerThread ()
 
- Static Public Member Functions inherited from G4RunManagerKernel
static G4RunManagerKernel * GetRunManagerKernel ()
 

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

Additional Inherited Members

- Public Types inherited from G4RunManagerKernel
enum  RMKType { sequentialRMK, masterRMK, workerRMK }
 
- Protected Attributes inherited from G4RunManagerKernel
RMKType runManagerKernelType
 
G4Region * defaultRegion
 
G4Region * defaultRegionForParallelWorld
 
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.

References FatalException, and G4Exception().

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  if(!workerRMvector) workerRMvector = new std::vector<G4WorkerRunManager*>;
48 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4MTRunManagerKernel::~G4MTRunManagerKernel ( )
virtual

Definition at line 50 of file G4MTRunManagerKernel.cc.

References FatalException, and G4Exception().

51 {
52  if(!workerRMvector)
53  {
54  if(workerRMvector->size()>0)
55  {
57  msg<<"G4MTRunManagerKernel is to be deleted while "
58  <<workerRMvector->size()<<" G4WorkerRunManager are still alive.";
59  G4Exception("G4RunManagerKernel::~G4RunManagerKernel()",
60  "Run10035",FatalException,msg);
61  }
62  delete workerRMvector;
63  workerRMvector = 0;
64  }
65 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Member Function Documentation

void G4MTRunManagerKernel::BroadcastAbortRun ( G4bool  softAbort)

Definition at line 346 of file G4MTRunManagerKernel.cc.

Referenced by G4MTRunManager::AbortRun().

347 {
348  G4AutoLock wrmm(&workerRMMutex);
349  std::vector<G4WorkerRunManager*>::iterator itr = workerRMvector->begin();
350  for(;itr!=workerRMvector->end();itr++)
351  { (*itr)->AbortRun(softAbort); }
352 }
G4WorkerThread * G4MTRunManagerKernel::GetWorkerThread ( )
static

Definition at line 97 of file G4MTRunManagerKernel.cc.

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

Definition at line 329 of file G4MTRunManagerKernel.cc.

References G4DecayTable::entries(), G4VDecayChannel::GetDaughter(), G4DecayTable::GetDecayChannel(), G4ParticleTable::GetIterator(), G4ParticleTable::GetParticleTable(), G4ParticleTableIterator< K, V >::reset(), and G4ParticleTableIterator< K, V >::value().

Referenced by G4MTRunManager::InitializeEventLoop().

330 {
333  pItr->reset();
334  while((*pItr)())
335  {
336  G4DecayTable* dt = pItr->value()->GetDecayTable();
337  if(dt)
338  {
339  G4int nCh = dt->entries();
340  for(G4int i=0;i<nCh;i++)
341  { dt->GetDecayChannel(i)->GetDaughter(0); }
342  }
343  }
344 }
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
void G4MTRunManagerKernel::SetupShadowProcess ( ) const
protectedvirtual

Reimplemented from G4RunManagerKernel.

Definition at line 67 of file G4MTRunManagerKernel.cc.

References G4RunManagerKernel::SetupShadowProcess().

68 {
69  //Behavior is the same as base class (sequential mode)
70  //ShadowProcess pointer == process poitner
72 }
virtual void SetupShadowProcess() const
void * G4MTRunManagerKernel::StartThread ( void *  context)
static

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

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

Definition at line 100 of file G4MTRunManagerKernel.cc.

References G4UImanager::ApplyCommand(), G4RunManager::BeamOn(), G4VUserActionInitialization::Build(), G4WorkerThread::BuildGeometryAndPhysicsVector(), G4UserWorkerThreadInitialization::CreateWorkerRunManager(), G4WorkerThread::DestroyGeometryAndPhysicsVector(), G4MTRunManager::ENDWORKER, FatalException, G4Exception(), G4Threading::G4SetThreadId(), G4ThreadLocal, G4MTRunManager::GetCommandStack(), G4MTRunManager::getMasterRandomEngine(), G4MTRunManager::GetMasterRunManager(), G4RunManager::GetNonConstUserActionInitialization(), G4RunManager::GetNumberOfEventsToBeProcessed(), G4RunManager::GetNumberOfSelectEvents(), G4RunManager::GetSelectMacro(), G4WorkerThread::GetThreadId(), G4UImanager::GetUIpointer(), G4RunManager::GetUserActionInitialization(), G4RunManager::GetUserDetectorConstruction(), G4RunManager::GetUserPhysicsList(), G4RunManager::GetUserWorkerInitialization(), G4RunManager::GetUserWorkerThreadInitialization(), G4RunManager::Initialize(), G4VUserActionInitialization::InitializeSteppingVerbose(), G4TemplateAutoLock< M, L, U >::lock(), G4MTRunManager::NEXTITERATION, G4VSteppingVerbose::SetInstance(), G4UImanager::SetUpForAThread(), G4UserWorkerThreadInitialization::SetupRNGEngine(), G4WorkerRunManager::SetUserInitialization(), G4WorkerRunManager::SetWorkerThread(), G4MTRunManager::ThisWorkerWaitForNextAction(), G4TemplateAutoLock< M, L, U >::unlock(), G4WorkerThread::UpdateGeometryAndPhysicsVectorFromMaster(), G4UserWorkerInitialization::WorkerInitialize(), G4UserWorkerInitialization::WorkerStart(), and G4UserWorkerInitialization::WorkerStop().

101 {
102  //!!!!!!!!!!!!!!!!!!!!!!!!!!
103  //!!!!!! IMPORTANT !!!!!!!!!
104  //!!!!!!!!!!!!!!!!!!!!!!!!!!
105  // Here is not sequential anymore and G4UserWorkerThreadInitialization is
106  // a shared user initialization class
107  // This means this method cannot use data memebers of G4RunManagerKernel
108  // unless they are invariant ("read-only") and can be safely shared.
109  // All the rest that is not invariant should be incapsualted into
110  // the context (or, as for wThreadContext be G4ThreadLocal)
111  //!!!!!!!!!!!!!!!!!!!!!!!!!!
112 //#ifdef G4MULTITHREADED
113 // turnontpmalloc();
114 //#endif
115 
116  wThreadContext = static_cast<G4WorkerThread*>(context);
118 
119  //============================
120  //Step-0: Thread ID
121  //============================
122  //Initliazie per-thread stream-output
123  //The following line is needed before we actually do IO initialization
124  //becasue the constructor of UI manager resets the IO destination.
125  G4int thisID = wThreadContext->GetThreadId();
128 
129  //============================
130  //Step-1: Random number engine
131  //============================
132  //RNG Engine needs to be initialized by "cloning" the master one.
133  const CLHEP::HepRandomEngine* masterEngine = masterRM->getMasterRandomEngine();
134  masterRM->GetUserWorkerThreadInitialization()->SetupRNGEngine(masterEngine);
135 
136  //============================
137  //Step-2: Initialize worker thread
138  //============================
139  if(masterRM->GetUserWorkerInitialization())
141  if(masterRM->GetUserActionInitialization())
142  {
144  if ( sv ) { G4VSteppingVerbose::SetInstance(sv); }
145  }
146  //Now initialize worker part of shared objects (geometry/physics)
147  wThreadContext->BuildGeometryAndPhysicsVector();
148  G4WorkerRunManager* wrm
150  wrm->SetWorkerThread(wThreadContext);
151  G4AutoLock wrmm(&workerRMMutex);
152  workerRMvector->push_back(wrm);
153  wrmm.unlock();
154 
155  //================================
156  //Step-3: Setup worker run manager
157  //================================
158  // Set the detector and physics list to the worker thread. Share with master
159  const G4VUserDetectorConstruction* detector = masterRM->GetUserDetectorConstruction();
160  wrm->G4RunManager::SetUserInitialization(const_cast<G4VUserDetectorConstruction*>(detector));
161  const G4VUserPhysicsList* physicslist = masterRM->GetUserPhysicsList();
162  wrm->SetUserInitialization(const_cast<G4VUserPhysicsList*>(physicslist));
163 
164  //================================
165  //Step-4: Initialize worker run manager
166  //================================
167  if(masterRM->GetUserActionInitialization())
168  { masterRM->GetNonConstUserActionInitialization()->Build(); }
169  if(masterRM->GetUserWorkerInitialization())
170  { masterRM->GetUserWorkerInitialization()->WorkerStart(); }
171  wrm->Initialize();
172 
173  //================================
174  //Step5: Loop over requests from the master thread
175  //================================
177  while( nextAction != G4MTRunManager::ENDWORKER )
178  {
179  if( nextAction == G4MTRunManager::NEXTITERATION ) // start the next run
180  {
181  //The following code deals with changing materials between runs
182  static G4ThreadLocal G4bool skipInitialization = true;
183  if(skipInitialization)
184  {
185  // re-initialization is not necessary for the first run
186  skipInitialization = false;
187  }
188  else
189  {
190 // ReinitializeGeometry();
191  wThreadContext->UpdateGeometryAndPhysicsVectorFromMaster();
192  }
193 
194  // Execute UI commands stored in the masther UI manager
195  std::vector<G4String> cmds = masterRM->GetCommandStack();
196  G4UImanager* uimgr = G4UImanager::GetUIpointer(); //TLS instance
197  std::vector<G4String>::const_iterator it = cmds.begin();
198  for(;it!=cmds.end();it++)
199  { uimgr->ApplyCommand(*it); }
200  //Start this run
201  G4int numevents = masterRM->GetNumberOfEventsToBeProcessed();
202  G4String macroFile = masterRM->GetSelectMacro();
203  G4int numSelect = masterRM->GetNumberOfSelectEvents();
204  if ( macroFile == "" || macroFile == " " )
205  {
206  wrm->BeamOn(numevents,0,numSelect);
207  }
208  else
209  {
210  wrm->BeamOn(numevents,macroFile,numSelect);
211  }
212  }
213  else
214  {
216  d<<"Cannot continue, this worker has been requested an unknwon action: "
217  <<nextAction<<" expecting: ENDWORKER(=" <<G4MTRunManager::ENDWORKER
218  <<") or NEXTITERATION(="<<G4MTRunManager::NEXTITERATION<<")";
219  G4Exception("G4MTRunManagerKernel::StartThread","Run0035",FatalException,d);
220  }
221 
222  //Now wait for master thread to signal new action to be performed
223  nextAction = masterRM->ThisWorkerWaitForNextAction();
224  } //No more actions to perform
225 
226  //===============================
227  //Step-6: Terminate worker thread
228  //===============================
229  if(masterRM->GetUserWorkerInitialization())
230  { masterRM->GetUserWorkerInitialization()->WorkerStop(); }
231 
232  wrmm.lock();
233  std::vector<G4WorkerRunManager*>::iterator itrWrm = workerRMvector->begin();
234  for(;itrWrm!=workerRMvector->end();itrWrm++)
235  {
236  if((*itrWrm)==wrm)
237  {
238  workerRMvector->erase(itrWrm);
239  break;
240  }
241  }
242  wrmm.unlock();
243  delete wrm;
244  wThreadContext->DestroyGeometryAndPhysicsVector();
245  wThreadContext = 0;
246 
247  return static_cast<void*>(0);
248 }
std::vector< G4String > GetCommandStack()
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:700
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
static void UpdateGeometryAndPhysicsVectorFromMaster()
G4String GetSelectMacro() const
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
static void BuildGeometryAndPhysicsVector()
void G4SetThreadId(G4int aNewValue)
Definition: G4Threading.cc:105
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
virtual G4WorkerRunManager * CreateWorkerRunManager() const
#define G4ThreadLocal
Definition: tls.hh:52
virtual void SetUserInitialization(G4VUserPhysicsList *userInit)
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
bool G4bool
Definition: G4Types.hh:79
static G4MTRunManager * GetMasterRunManager()
virtual WorkerActionRequest ThisWorkerWaitForNextAction()
virtual void Build() const =0
G4int GetThreadId() const
G4int GetNumberOfEventsToBeProcessed() const
const G4VUserActionInitialization * GetUserActionInitialization() const
const XML_Char * context
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int GetNumberOfSelectEvents() const
void SetWorkerThread(G4WorkerThread *wc)
Sets the worker context.
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
static void SetInstance(G4VSteppingVerbose *Instance)
G4VUserActionInitialization * GetNonConstUserActionInitialization() const
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
virtual G4VSteppingVerbose * InitializeSteppingVerbose() const
static void DestroyGeometryAndPhysicsVector()
virtual void Initialize()
const G4VUserPhysicsList * GetUserPhysicsList() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419

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