Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4MTRunManager Class Reference

#include <G4MTRunManager.hh>

Inheritance diagram for G4MTRunManager:
Collaboration diagram for G4MTRunManager:

Public Types

enum  WorkerActionRequest { WorkerActionRequest::UNDEFINED, WorkerActionRequest::NEXTITERATION, WorkerActionRequest::PROCESSUI, WorkerActionRequest::ENDWORKER }
 
typedef std::map< G4int,
G4VPhysicalVolume * > 
masterWorlds_t
 
- Public Types inherited from G4RunManager
enum  RMType { sequentialRM, masterRM, workerRM }
 

Public Member Functions

 G4MTRunManager ()
 
virtual ~G4MTRunManager ()
 
void SetNumberOfThreads (G4int n)
 
G4int GetNumberOfThreads () const
 
void SetPinAffinity (G4int n=1)
 
G4int GetPinAffinity () const
 
virtual void Initialize ()
 
virtual void InitializeEventLoop (G4int n_event, const char *macroFile=0, G4int n_select=-1)
 
virtual void TerminateOneEvent ()
 
virtual void ProcessOneEvent (G4int i_event)
 
virtual void ConstructScoringWorlds ()
 
virtual void RunTermination ()
 
virtual G4bool SetUpAnEvent (G4Event *, long &s1, long &s2, long &s3, G4bool reseedRequired=true)
 
virtual G4int SetUpNEvents (G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
 
std::vector< G4StringGetCommandStack ()
 
size_t GetNumberActiveThreads () const
 
virtual void ThisWorkerReady ()
 
virtual void ThisWorkerEndEventLoop ()
 
const CLHEP::HepRandomEnginegetMasterRandomEngine () const
 
virtual void SetUserInitialization (G4VUserPhysicsList *userPL)
 
virtual void SetUserInitialization (G4VUserDetectorConstruction *userDC)
 
virtual void SetUserInitialization (G4UserWorkerInitialization *userInit)
 
virtual void SetUserInitialization (G4UserWorkerThreadInitialization *userInit)
 
virtual void SetUserInitialization (G4VUserActionInitialization *userInit)
 
virtual void SetUserAction (G4UserRunAction *userAction)
 
virtual void SetUserAction (G4VUserPrimaryGeneratorAction *userAction)
 
virtual void SetUserAction (G4UserEventAction *userAction)
 
virtual void SetUserAction (G4UserStackingAction *userAction)
 
virtual void SetUserAction (G4UserTrackingAction *userAction)
 
virtual void SetUserAction (G4UserSteppingAction *userAction)
 
void MergeScores (const G4ScoringManager *localScoringManager)
 
void MergeRun (const G4Run *localRun)
 
virtual void RequestWorkersProcessCommandsStack ()
 
virtual void ThisWorkerProcessCommandsStackDone ()
 
virtual WorkerActionRequest ThisWorkerWaitForNextAction ()
 
void SetEventModulo (G4int i=1)
 
G4int GetEventModulo () const
 
virtual void AbortRun (G4bool softAbort=false)
 
virtual void AbortEvent ()
 
- Public Member Functions inherited from G4RunManager
 G4RunManager ()
 
virtual ~G4RunManager ()
 
virtual void BeamOn (G4int n_event, const char *macroFile=0, G4int n_select=-1)
 
virtual void DefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
virtual void InitializeGeometry ()
 
virtual void InitializePhysics ()
 
virtual G4bool ConfirmBeamOnCondition ()
 
virtual void RunInitialization ()
 
virtual void DoEventLoop (G4int n_event, const char *macroFile=0, G4int n_select=-1)
 
virtual void TerminateEventLoop ()
 
virtual G4EventGenerateEvent (G4int i_event)
 
virtual void AnalyzeEvent (G4Event *anEvent)
 
void DumpRegion (const G4String &rname) const
 
void DumpRegion (G4Region *region=0) const
 
virtual void rndmSaveThisRun ()
 
virtual void rndmSaveThisEvent ()
 
virtual void RestoreRandomNumberStatus (const G4String &fileN)
 
const G4VUserDetectorConstructionGetUserDetectorConstruction () const
 
const G4VUserPhysicsListGetUserPhysicsList () const
 
const G4VUserActionInitializationGetUserActionInitialization () const
 
G4VUserActionInitializationGetNonConstUserActionInitialization () const
 
const G4UserWorkerInitializationGetUserWorkerInitialization () const
 
const
G4UserWorkerThreadInitialization
GetUserWorkerThreadInitialization () const
 
const G4UserRunActionGetUserRunAction () const
 
const
G4VUserPrimaryGeneratorAction
GetUserPrimaryGeneratorAction () const
 
const G4UserEventActionGetUserEventAction () const
 
const G4UserStackingActionGetUserStackingAction () const
 
const G4UserTrackingActionGetUserTrackingAction () const
 
const G4UserSteppingActionGetUserSteppingAction () const
 
void SetNumberOfAdditionalWaitingStacks (G4int iAdd)
 
const G4StringGetVersionString () const
 
void SetPrimaryTransformer (G4PrimaryTransformer *pt)
 
void StoreRandomNumberStatusToG4Event (G4int vl)
 
G4int GetFlagRandomNumberStatusToG4Event () const
 
void SetRandomNumberStore (G4bool flag)
 
G4bool GetRandomNumberStore () const
 
void SetRandomNumberStoreDir (const G4String &dir)
 
const G4StringGetRandomNumberStoreDir () const
 
const G4StringGetRandomNumberStatusForThisRun () const
 
const G4StringGetRandomNumberStatusForThisEvent () const
 
void SetRandomNumberStorePerEvent (G4bool flag)
 
G4bool GetRandomNumberStorePerEvent () const
 
void GeometryHasBeenModified (G4bool prop=true)
 
void ReinitializeGeometry (G4bool destroyFirst=false, G4bool prop=true)
 
void PhysicsHasBeenModified ()
 
void CutOffHasBeenModified ()
 
void ReOptimizeMotherOf (G4VPhysicalVolume *)
 
void ReOptimize (G4LogicalVolume *)
 
void SetVerboseLevel (G4int vl)
 
G4int GetVerboseLevel () const
 
G4int GetPrintProgress ()
 
void SetPrintProgress (G4int i)
 
void SetGeometryToBeOptimized (G4bool vl)
 
G4bool GetGeometryToBeOptimized ()
 
void SetNumberOfEventsToBeStored (G4int val)
 
const G4RunGetCurrentRun () const
 
G4RunGetNonConstCurrentRun () const
 
const G4EventGetCurrentEvent () const
 
const G4EventGetPreviousEvent (G4int i) const
 
void SetRunIDCounter (G4int i)
 
G4int GetNumberOfParallelWorld () const
 
void SetNumberOfEventsToBeProcessed (G4int val)
 
G4int GetNumberOfEventsToBeProcessed () const
 
G4int GetNumberOfSelectEvents () const
 
G4String GetSelectMacro () const
 
void SetDCtable (G4DCtable *DCtbl)
 
RMType GetRunManagerType () const
 
virtual void RestoreRndmEachEvent (G4bool)
 

Static Public Member Functions

static G4ScoringManagerGetMasterScoringManager ()
 
static masterWorlds_tGetMasterWorlds ()
 
static void addWorld (G4int counter, G4VPhysicalVolume *w)
 
static G4MTRunManagerGetMasterRunManager ()
 
static G4RunManagerKernelGetMasterRunManagerKernel ()
 
static G4MTRunManagerKernelGetMTMasterRunManagerKernel ()
 
static G4int SeedOncePerCommunication ()
 
static void SetSeedOncePerCommunication (G4int val)
 
- Static Public Member Functions inherited from G4RunManager
static G4RunManagerGetRunManager ()
 
static G4bool IfGeometryHasBeenDestroyed ()
 

Protected Member Functions

virtual G4bool InitializeSeeds (G4int)
 
virtual void PrepareCommandsStack ()
 
virtual void StoreRNGStatus (const G4String &filenamePrefix)
 
virtual void CreateAndStartWorkers ()
 
virtual void WaitForReadyWorkers ()
 
virtual void WaitForEndEventLoopWorkers ()
 
virtual void TerminateWorkers ()
 
virtual void NewActionRequest (WorkerActionRequest newRequest)
 
void RefillSeeds ()
 
- Protected Member Functions inherited from G4RunManager
void CleanUpPreviousEvents ()
 
void CleanUpUnnecessaryEvents (G4int keepNEvents)
 
void StackPreviousEvent (G4Event *anEvent)
 
 G4RunManager (RMType rmType)
 
void UpdateScoring ()
 
virtual void DeleteUserInitializations ()
 

Protected Attributes

G4int numberOfEventToBeProcessed
 
WorkerActionRequest nextActionRequest
 
G4int eventModuloDef
 
G4int eventModulo
 
G4int nSeedsUsed
 
G4int nSeedsFilled
 
G4int nSeedsMax
 
G4int nSeedsPerEvent
 
double * randDbl
 
G4MTBarrier beginOfEventLoopBarrier
 
G4MTBarrier endOfEventLoopBarrier
 
G4MTBarrier nextActionRequestBarrier
 
G4MTBarrier processUIBarrier
 
- Protected Attributes inherited from G4RunManager
G4RunManagerKernelkernel
 
G4EventManagereventManager
 
G4VUserDetectorConstructionuserDetector
 
G4VUserPhysicsListphysicsList
 
G4VUserActionInitializationuserActionInitialization
 
G4UserWorkerInitializationuserWorkerInitialization
 
G4UserWorkerThreadInitializationuserWorkerThreadInitialization
 
G4UserRunActionuserRunAction
 
G4VUserPrimaryGeneratorActionuserPrimaryGeneratorAction
 
G4UserEventActionuserEventAction
 
G4UserStackingActionuserStackingAction
 
G4UserTrackingActionuserTrackingAction
 
G4UserSteppingActionuserSteppingAction
 
G4bool geometryInitialized
 
G4bool physicsInitialized
 
G4bool runAborted
 
G4bool initializedAtLeastOnce
 
G4bool geometryToBeOptimized
 
G4int runIDCounter
 
G4int verboseLevel
 
G4int printModulo
 
G4Timertimer
 
G4DCtableDCtable
 
G4RuncurrentRun
 
G4EventcurrentEvent
 
std::list< G4Event * > * previousEvents
 
G4int n_perviousEventsToBeStored
 
G4int numberOfEventToBeProcessed
 
G4bool storeRandomNumberStatus
 
G4int storeRandomNumberStatusToG4Event
 
G4String randomNumberStatusDir
 
G4String randomNumberStatusForThisRun
 
G4String randomNumberStatusForThisEvent
 
G4bool rngStatusEventsFlag
 
G4VPhysicalVolumecurrentWorld
 
G4int nParallelWorlds
 
G4String msgText
 
G4int n_select_msg
 
G4int numberOfEventProcessed
 
G4String selectMacro
 
G4bool fakeRun
 
RMType runManagerType
 

Static Protected Attributes

static G4int seedOncePerCommunication = 0
 
- Static Protected Attributes inherited from G4RunManager
static G4bool fGeometryHasBeenDestroyed = false
 

Detailed Description

Definition at line 51 of file G4MTRunManager.hh.

Member Typedef Documentation

Definition at line 159 of file G4MTRunManager.hh.

Member Enumeration Documentation

Enumerator
UNDEFINED 
NEXTITERATION 
PROCESSUI 
ENDWORKER 

Definition at line 198 of file G4MTRunManager.hh.

198  {
199  UNDEFINED ,
200  NEXTITERATION , // There is another set of UI commands to be executed
201  PROCESSUI, // Process UI commands w/o a /run/beamOn
202  ENDWORKER // Terminate thread, work finished
203  };

Constructor & Destructor Documentation

G4MTRunManager::G4MTRunManager ( )

Definition at line 77 of file G4MTRunManager.cc.

78  nworkers(2),forcedNwokers(-1),pinAffinity(0),
79  masterRNGEngine(0),
83  nSeedsMax(10000),nSeedsPerEvent(2)
84 {
85  if ( fMasterRM )
86  {
87  G4Exception("G4MTRunManager::G4MTRunManager", "Run0110",FatalException,
88  "Another instance of a G4MTRunManager already exists.");
89  }
90  fMasterRM = this;
91  MTkernel = static_cast<G4MTRunManagerKernel*>(kernel);
92 #ifndef G4MULTITHREADED
94  msg << "Geant4 code is compiled without multi-threading support"
95  << "(-DG4MULTITHREADED is set to off).\n";
96  msg << "G4MTRunManager can only be used in multi-threaded applications.";
97  G4Exception("G4MTRunManager::G4MTRunManager","Run0111",FatalException,msg);
98 #endif
99 
100  G4int numberOfStaticAllocators = kernel->GetNumberOfStaticAllocators();
101  if(numberOfStaticAllocators>0)
102  {
104  msg1 << "There are " << numberOfStaticAllocators
105  << " static G4Allocator objects detected.\n"
106  << "In multi-threaded mode, all G4Allocator objects must be dynamicly instantiated.";
107  G4Exception("G4MTRunManager::G4MTRunManager","Run1035",FatalException,msg1);
108  }
111 
112  //Check if a default RandomNumberGenerator has been created by user,
113  // if not create default one
114  //Note this call forces creation of defaults if not already there
115  //G4Random::getTheEngine(); //User did not specify RNG, create defaults
116  //Now remember the master instance of the RNG Engine
117  masterRNGEngine = G4Random::getTheEngine();
118 
120  randDbl = new double[nSeedsPerEvent*nSeedsMax];
121 
122  char* env = getenv("G4FORCENUMBEROFTHREADS");
123  if(env)
124  {
125  G4String envS = env;
126  if(envS=="MAX"||envS=="max")
127  { forcedNwokers = G4Threading::G4GetNumberOfCores(); }
128  else
129  {
130  std::istringstream is(env);
131  G4int val = -1;
132  is >> val;
133  if(val>0)
134  { forcedNwokers = val; }
135  else
136  {
138  msg2 << "Environment variable G4FORCENUMBEROFTHREADS has an invalid value <"
139  << envS << ">. It has to be an integer or a word \"max\".\n"
140  << "G4FORCENUMBEROFTHREADS is ignored.";
141  G4Exception("G4MTRunManager::G4MTRunManager","Run1039",JustWarning,msg2);
142  }
143  }
144  if(forcedNwokers>0)
145  {
146  nworkers = forcedNwokers;
147  G4cout << "### Number of threads is forced to " << forcedNwokers
148  << " by Environment variable G4FORCENUMBEROFTHREADS." << G4endl;
149  }
150  }
151 }
WorkerActionRequest nextActionRequest
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4GLOB_DLL std::ostream G4cout
static G4ScoringManager * GetScoringManagerIfExist()
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:143
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int numberOfEventToBeProcessed
#define G4endl
Definition: G4ios.hh:61
G4int GetNumberOfStaticAllocators() const
G4RunManagerKernel * kernel
void SetMasterUIManager(G4bool val)
Definition: G4UImanager.hh:258

Here is the call graph for this function:

G4MTRunManager::~G4MTRunManager ( )
virtual

Definition at line 153 of file G4MTRunManager.cc.

154 {
155  //TODO: Currently does not work due to concurrent deletion of something
156  // that is shared:
157  //G4ProcessTable::DeleteMessenger from ~G4RunManager
158  //G4cout<<"Destroy MTRunManager"<<G4endl;//ANDREA
160  delete [] randDbl;
161 }
virtual void TerminateWorkers()

Here is the call graph for this function:

Member Function Documentation

void G4MTRunManager::AbortEvent ( )
virtual

Reimplemented from G4RunManager.

Definition at line 569 of file G4MTRunManager.cc.

570 {
571  // nothing to do in the master thread
572 }
void G4MTRunManager::AbortRun ( G4bool  softAbort = false)
virtual

Reimplemented from G4RunManager.

Definition at line 553 of file G4MTRunManager.cc.

554 {
555  // This method is valid only for GeomClosed or EventProc state
556  G4ApplicationState currentState =
558  if(currentState==G4State_GeomClosed || currentState==G4State_EventProc)
559  {
560  runAborted = true;
561  MTkernel->BroadcastAbortRun(softAbort);
562  }
563  else
564  {
565  G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
566  }
567 }
G4bool runAborted
static G4StateManager * GetStateManager()
G4ApplicationState GetCurrentState() const
#define G4endl
Definition: G4ios.hh:61
void BroadcastAbortRun(G4bool softAbort)
G4ApplicationState
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

static void G4MTRunManager::addWorld ( G4int  counter,
G4VPhysicalVolume w 
)
inlinestatic

Definition at line 162 of file G4MTRunManager.hh.

162 { masterWorlds.insert( std::make_pair(counter,w) ); }

Here is the caller graph for this function:

void G4MTRunManager::ConstructScoringWorlds ( )
virtual

Reimplemented from G4RunManager.

Definition at line 389 of file G4MTRunManager.cc.

390 {
392  //Call base class stuff...
394 
395  masterWorlds.clear();
397  std::vector<G4VPhysicalVolume*>::iterator itrW
399  for(size_t iWorld=0;iWorld<nWorlds;iWorld++)
400  {
401  addWorld(iWorld,*itrW);
402  itrW++;
403  }
404 }
static void addWorld(G4int counter, G4VPhysicalVolume *w)
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
static G4ScoringManager * GetScoringManagerIfExist()
virtual void ConstructScoringWorlds()
static G4TransportationManager * GetTransportationManager()
size_t GetNoWorlds() const

Here is the call graph for this function:

void G4MTRunManager::CreateAndStartWorkers ( )
protectedvirtual

Definition at line 235 of file G4MTRunManager.cc.

236 {
237  //Now loop on requested number of workers
238  //This will also start the workers
239  //Currently we do not allow to change the
240  //number of threads: threads area created once
241  if ( threads.size() == 0 ) {
242  for ( G4int nw = 0 ; nw<nworkers; ++nw) {
243  //Create a new worker and remember it
245  context->SetNumberThreads(nworkers);
246  context->SetThreadId(nw);
248  threads.push_back(thread);
249  }
250  }
251  //Signal to threads they can start a new run
253 }
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
void SetThreadId(G4int threadId)
int G4int
Definition: G4Types.hh:78
G4int G4Thread
Definition: G4Threading.hh:174
virtual void NewActionRequest(WorkerActionRequest newRequest)
const XML_Char * context
Definition: expat.h:434
virtual G4Thread * CreateAndStartWorker(G4WorkerThread *workerThreadContext)
void SetNumberThreads(G4int numnberThreads)

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< G4String > G4MTRunManager::GetCommandStack ( )

Definition at line 229 of file G4MTRunManager.cc.

230 {
231  G4AutoLock l(&cmdHandlingMutex);
232  return uiCmdsForWorkers;
233 }

Here is the caller graph for this function:

G4int G4MTRunManager::GetEventModulo ( ) const
inline

Definition at line 233 of file G4MTRunManager.hh.

233 { return eventModuloDef; }

Here is the caller graph for this function:

const CLHEP::HepRandomEngine* G4MTRunManager::getMasterRandomEngine ( ) const
inline

Definition at line 163 of file G4MTRunManager.hh.

163 { return masterRNGEngine; }

Here is the caller graph for this function:

G4MTRunManager * G4MTRunManager::GetMasterRunManager ( )
static

Definition at line 58 of file G4MTRunManager.cc.

59 {
61  return fMasterRM;
65 }

Here is the caller graph for this function:

G4RunManagerKernel * G4MTRunManager::GetMasterRunManagerKernel ( )
static

Definition at line 67 of file G4MTRunManager.cc.

68 {
69  return fMasterRM->kernel;
70 }
G4RunManagerKernel * kernel

Here is the caller graph for this function:

static G4ScoringManager* G4MTRunManager::GetMasterScoringManager ( )
inlinestatic

Definition at line 160 of file G4MTRunManager.hh.

160 { return masterScM; }

Here is the caller graph for this function:

static masterWorlds_t& G4MTRunManager::GetMasterWorlds ( )
inlinestatic

Definition at line 161 of file G4MTRunManager.hh.

161 { return masterWorlds; }

Here is the caller graph for this function:

G4MTRunManagerKernel * G4MTRunManager::GetMTMasterRunManagerKernel ( )
static

Definition at line 72 of file G4MTRunManager.cc.

73 {
74  return fMasterRM->MTkernel;
75 }
size_t G4MTRunManager::GetNumberActiveThreads ( ) const
inline

Definition at line 104 of file G4MTRunManager.hh.

104 { return threads.size(); }

Here is the caller graph for this function:

G4int G4MTRunManager::GetNumberOfThreads ( ) const
inline

Definition at line 57 of file G4MTRunManager.hh.

57 { return nworkers; }
G4int G4MTRunManager::GetPinAffinity ( ) const
inline

Definition at line 59 of file G4MTRunManager.hh.

59 { return pinAffinity; }

Here is the caller graph for this function:

void G4MTRunManager::Initialize ( void  )
virtual

G4UImanager::GetUIpointer()->SetIgnoreCmdNotFound(true);

Reimplemented from G4RunManager.

Definition at line 195 of file G4MTRunManager.cc.

196 {
198 
199  // make sure all worker threads are set up.
200  BeamOn(0);
201  SetRunIDCounter(0);
203 }
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
void SetRunIDCounter(G4int i)
virtual void Initialize()

Here is the call graph for this function:

void G4MTRunManager::InitializeEventLoop ( G4int  n_event,
const char *  macroFile = 0,
G4int  n_select = -1 
)
virtual

Reimplemented from G4RunManager.

Definition at line 256 of file G4MTRunManager.cc.

257 {
258  MTkernel->SetUpDecayChannels();
259  numberOfEventToBeProcessed = n_event;
261 
262  if(!fakeRun)
263  {
264  nSeedsUsed = 0;
265  nSeedsFilled = 0;
266 
267  if(verboseLevel>0)
268  { timer->Start(); }
269 
270  n_select_msg = n_select;
271  if(macroFile!=0)
272  {
273  if(n_select_msg<0) n_select_msg = n_event;
274  msgText = "/control/execute ";
275  msgText += macroFile;
276  selectMacro = macroFile;
277  }
278  else
279  {
280  n_select_msg = -1;
281  selectMacro = "";
282  }
283 
284  //initialize seeds
285  //If user did not implement InitializeSeeds,
286  // use default: nSeedsPerEvent seeds per event
287  if( eventModuloDef > 0 )
288  {
291  {
293  if(eventModulo<1) eventModulo =1;
295  msgd << "Event modulo is reduced to " << eventModulo
296  << " to distribute events to all threads.";
297  G4Exception("G4MTRunManager::InitializeEventLoop()",
298  "Run10035", JustWarning, msgd);
299  }
300  }
301  else
302  {
303  eventModulo = int(std::sqrt(double(numberOfEventToBeProcessed/nworkers)));
304  if(eventModulo<1) eventModulo =1;
305  }
306  if ( InitializeSeeds(n_event) == false && n_event>0 )
307  {
310  {
311  case 0:
312  nSeedsFilled = n_event;
313  break;
314  case 1:
315  nSeedsFilled = nworkers;
316  break;
317  case 2:
318  nSeedsFilled = n_event/eventModulo + 1;
319  break;
320  default:
322  msgd << "Parameter value <" << seedOncePerCommunication
323  << "> of seedOncePerCommunication is invalid. It is reset to 0." ;
324  G4Exception("G4MTRunManager::InitializeEventLoop()",
325  "Run10036", JustWarning, msgd);
326  seedOncePerCommunication = 0;
327  nSeedsFilled = n_event;
328  }
329 
330  // Generates up to nSeedsMax seed pairs only.
332  masterRNGEngine->flatArray(nSeedsPerEvent*nSeedsFilled,randDbl);
333  helper->Fill(randDbl,nSeedsFilled,n_event,nSeedsPerEvent);
334  }
335  }
336 
337  //Now initialize workers. Check if user defined a WorkerThreadInitialization
340 
341  //Prepare UI commands for threads
343 
344  //Start worker threads
346 
347  // We need a barrier here. Wait for workers to start event loop.
348  //This will return only when all workers have started processing events.
350 }
G4Timer * timer
virtual void PrepareCommandsStack()
static G4int seedOncePerCommunication
G4int n_select_msg
G4int numberOfEventProcessed
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
virtual G4bool InitializeSeeds(G4int)
G4String msgText
void Fill(G4double *dbl, G4int nev, G4int nev_tot, G4int nrpe)
Definition: G4RNGHelper.hh:81
virtual void WaitForReadyWorkers()
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4String selectMacro
static G4TemplateRNGHelper< T > * GetInstance()
Definition: G4RNGHelper.cc:37
G4int numberOfEventToBeProcessed
void Start()
virtual void flatArray(const int size, double *vect)=0
G4int verboseLevel
virtual void CreateAndStartWorkers()

Here is the call graph for this function:

virtual G4bool G4MTRunManager::InitializeSeeds ( G4int  )
inlineprotectedvirtual

Definition at line 93 of file G4MTRunManager.hh.

93 { return false; };

Here is the caller graph for this function:

void G4MTRunManager::MergeRun ( const G4Run localRun)

Definition at line 475 of file G4MTRunManager.cc.

476 {
477  G4AutoLock l(&runMergerMutex);
478  if(currentRun) currentRun->Merge(localRun);
479 }
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4Run * currentRun

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::MergeScores ( const G4ScoringManager localScoringManager)

Definition at line 469 of file G4MTRunManager.cc.

470 {
471  G4AutoLock l(&scorerMergerMutex);
472  if(masterScM) masterScM->Merge(localScoringManager);
473 }
void Merge(const G4ScoringManager *scMan)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::NewActionRequest ( G4MTRunManager::WorkerActionRequest  newRequest)
protectedvirtual

Definition at line 594 of file G4MTRunManager.cc.

594  {
596  //nextActionRequest is a shared resource, but there is no
597  //data-race thanks to the barrier: all threads are waiting
598  nextActionRequest = newRequest;
600 }
WorkerActionRequest nextActionRequest
void ReleaseBarrier()
Definition: G4MTBarrier.cc:97
void Wait()
Definition: G4MTBarrier.cc:73
G4MTBarrier nextActionRequestBarrier
size_t GetNumberActiveThreads() const

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::PrepareCommandsStack ( )
protectedvirtual

Definition at line 218 of file G4MTRunManager.cc.

218  {
219  G4AutoLock l(&cmdHandlingMutex);
220  uiCmdsForWorkers.clear();
221  std::vector<G4String>* cmdCopy = G4UImanager::GetUIpointer()->GetCommandStack();
222  for ( std::vector<G4String>::const_iterator it = cmdCopy->begin() ;
223  it != cmdCopy->end(); ++it )
224  uiCmdsForWorkers.push_back(*it);
225  cmdCopy->clear();
226  delete cmdCopy;
227 }
std::vector< G4String > * GetCommandStack()
Definition: G4UImanager.cc:710
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::ProcessOneEvent ( G4int  i_event)
virtual

Reimplemented from G4RunManager.

Definition at line 209 of file G4MTRunManager.cc.

210 {
211  //Nothing to do
212 }
void G4MTRunManager::RefillSeeds ( )
protected

Definition at line 352 of file G4MTRunManager.cc.

353 {
355  G4int nFill = 0;
357  {
358  case 0:
360  break;
361  case 1:
362  nFill = nworkers - nSeedsFilled;
363  break;
364  case 2:
365  default:
366  nFill = (numberOfEventToBeProcessed - nSeedsFilled*eventModulo)/eventModulo + 1;
367  }
368  // Generates up to nSeedsMax seed pairs only.
369  if(nFill>nSeedsMax) nFill=nSeedsMax;
370  masterRNGEngine->flatArray(nSeedsPerEvent*nFill,randDbl);
371  helper->Refill(randDbl,nFill);
372  nSeedsFilled += nFill;
373 //G4cout<<"helper->Refill() for "<<nFill<<" events."<<G4endl;
374 }
static G4int seedOncePerCommunication
int G4int
Definition: G4Types.hh:78
void Refill(G4double *dbl, G4int nev)
Definition: G4RNGHelper.hh:92
static G4TemplateRNGHelper< T > * GetInstance()
Definition: G4RNGHelper.cc:37
G4int numberOfEventToBeProcessed
virtual void flatArray(const int size, double *vect)=0

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::RequestWorkersProcessCommandsStack ( )
virtual

Definition at line 607 of file G4MTRunManager.cc.

607  {
612 }
virtual void PrepareCommandsStack()
void SetActiveThreads(unsigned int val)
Definition: G4MTBarrier.hh:142
virtual void WaitForReadyWorkers()
Definition: G4MTBarrier.cc:104
G4MTBarrier processUIBarrier
virtual void NewActionRequest(WorkerActionRequest newRequest)
size_t GetNumberActiveThreads() const

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::RunTermination ( )
virtual

Reimplemented from G4RunManager.

Definition at line 376 of file G4MTRunManager.cc.

377 {
378  //Wait for all worker threads to have finished the run
379  //i.e. wait for them to return from RunTermination()
380  //This guarantee that userrunaction for workers has been called
381 
382  // Wait now for all threads to finish event-loop
384  //Now call base-class methof
387 }
virtual void TerminateEventLoop()
virtual void RunTermination()
virtual void WaitForEndEventLoopWorkers()

Here is the call graph for this function:

static G4int G4MTRunManager::SeedOncePerCommunication ( )
inlinestatic

Definition at line 256 of file G4MTRunManager.hh.

256 { return seedOncePerCommunication; }
static G4int seedOncePerCommunication

Here is the caller graph for this function:

void G4MTRunManager::SetEventModulo ( G4int  i = 1)
inline

Definition at line 232 of file G4MTRunManager.hh.

232 { eventModuloDef = i; }
void G4MTRunManager::SetNumberOfThreads ( G4int  n)

Definition at line 170 of file G4MTRunManager.cc.

171 {
172  if ( threads.size() != 0 )
173  {
175  msg << "Number of threads cannot be changed at this moment \n"
176  << "(old threads are still alive). Method ignored.";
177  G4Exception("G4MTRunManager::SetNumberOfThreads(G4int)",
178  "Run0112", JustWarning, msg);
179  }
180  else if ( forcedNwokers > 0 )
181  {
183  msg << "Number of threads is forced to " << forcedNwokers
184  << " by G4FORCENUMBEROFTHREADS shell variable.\n"
185  << "Method ignored.";
186  G4Exception("G4MTRunManager::SetNumberOfThreads(G4int)",
187  "Run0113", JustWarning, msg);
188  }
189  else
190  {
191  nworkers = n;
192  }
193 }
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:

void G4MTRunManager::SetPinAffinity ( G4int  n = 1)

Definition at line 617 of file G4MTRunManager.cc.

618 {
619  if ( n == 0 )
620  {
621  G4Exception("G4MTRunManager::SetPinAffinity",
622  "Run0114",FatalException,
623  "Pin affinity must be >0 or <0.");
624  }
625  pinAffinity = n;
626  return;
627 }
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:

static void G4MTRunManager::SetSeedOncePerCommunication ( G4int  val)
inlinestatic

Definition at line 257 of file G4MTRunManager.hh.

257 { seedOncePerCommunication = val; }
static G4int seedOncePerCommunication

Here is the caller graph for this function:

G4bool G4MTRunManager::SetUpAnEvent ( G4Event evt,
long &  s1,
long &  s2,
long &  s3,
G4bool  reseedRequired = true 
)
virtual

Definition at line 481 of file G4MTRunManager.cc.

482 {
483  G4AutoLock l(&setUpEventMutex);
485  {
487  if(reseedRequired)
488  {
490  G4int idx_rndm = nSeedsPerEvent*nSeedsUsed;
491  s1 = helper->GetSeed(idx_rndm);
492  s2 = helper->GetSeed(idx_rndm+1);
493  if(nSeedsPerEvent==3) s3 = helper->GetSeed(idx_rndm+2);
494  nSeedsUsed++;
495  if(nSeedsUsed==nSeedsFilled) RefillSeeds();
496  }
498  return true;
499  }
500  return false;
501 }
G4int numberOfEventProcessed
virtual const T GetSeed(const G4int &sdId)
Definition: G4RNGHelper.hh:62
int G4int
Definition: G4Types.hh:78
static G4TemplateRNGHelper< T > * GetInstance()
Definition: G4RNGHelper.cc:37
G4int numberOfEventToBeProcessed
void SetEventID(G4int i)
Definition: G4Event.hh:115

Here is the call graph for this function:

Here is the caller graph for this function:

G4int G4MTRunManager::SetUpNEvents ( G4Event evt,
G4SeedsQueue seedsQueue,
G4bool  reseedRequired = true 
)
virtual

Definition at line 503 of file G4MTRunManager.cc.

504 {
505  G4AutoLock l(&setUpEventMutex);
507  {
508  G4int nev = eventModulo;
512  if(reseedRequired)
513  {
515  G4int nevRnd = nev;
516  if(seedOncePerCommunication>0) nevRnd = 1;
517  for(int i=0;i<nevRnd;i++)
518  {
519  seedsQueue->push(helper->GetSeed(nSeedsPerEvent*nSeedsUsed));
520  seedsQueue->push(helper->GetSeed(nSeedsPerEvent*nSeedsUsed+1));
521  if(nSeedsPerEvent==3)
522  seedsQueue->push(helper->GetSeed(nSeedsPerEvent*nSeedsUsed+2));
523  nSeedsUsed++;
524  if(nSeedsUsed==nSeedsFilled) RefillSeeds();
525  }
526  }
527  numberOfEventProcessed += nev;
528  return nev;
529  }
530  return 0;
531 }
static G4int seedOncePerCommunication
G4int numberOfEventProcessed
virtual const T GetSeed(const G4int &sdId)
Definition: G4RNGHelper.hh:62
int G4int
Definition: G4Types.hh:78
G4bool runAborted
static G4TemplateRNGHelper< T > * GetInstance()
Definition: G4RNGHelper.cc:37
G4int numberOfEventToBeProcessed
void SetEventID(G4int i)
Definition: G4Event.hh:115

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::SetUserAction ( G4UserRunAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 433 of file G4MTRunManager.cc.

434 {
435  G4RunManager::SetUserAction(userAction);
436  userAction->SetMaster();
437 }
virtual void SetMaster(G4bool val=true)
virtual void SetUserAction(G4UserRunAction *userAction)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::SetUserAction ( G4VUserPrimaryGeneratorAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 439 of file G4MTRunManager.cc.

440 {
441  G4Exception("G4MTRunManager::SetUserAction()", "Run0123", FatalException,
442  "For multi-threaded version, define G4VUserPrimaryGeneratorAction in G4VUserActionInitialization.");
443 }
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:

void G4MTRunManager::SetUserAction ( G4UserEventAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 445 of file G4MTRunManager.cc.

446 {
447  G4Exception("G4MTRunManager::SetUserAction()", "Run0124", FatalException,
448  "For multi-threaded version, define G4UserEventAction in G4VUserActionInitialization.");
449 }
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:

void G4MTRunManager::SetUserAction ( G4UserStackingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 451 of file G4MTRunManager.cc.

452 {
453  G4Exception("G4MTRunManager::SetUserAction()", "Run0125", FatalException,
454  "For multi-threaded version, define G4UserStackingAction in G4VUserActionInitialization.");
455 }
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:

void G4MTRunManager::SetUserAction ( G4UserTrackingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 457 of file G4MTRunManager.cc.

458 {
459  G4Exception("G4MTRunManager::SetUserAction()", "Run0126", FatalException,
460  "For multi-threaded version, define G4UserTrackingAction in G4VUserActionInitialization.");
461 }
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:

void G4MTRunManager::SetUserAction ( G4UserSteppingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 463 of file G4MTRunManager.cc.

464 {
465  G4Exception("G4MTRunManager::SetUserAction()", "Run0127", FatalException,
466  "For multi-threaded version, define G4UserSteppingAction in G4VUserActionInitialization.");
467 }
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:

void G4MTRunManager::SetUserInitialization ( G4VUserPhysicsList userPL)
virtual

Reimplemented from G4RunManager.

Definition at line 422 of file G4MTRunManager.cc.

423 {
425  //Needed for MT, to be moved in kernel
426 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::SetUserInitialization ( G4VUserDetectorConstruction userDC)
virtual

Reimplemented from G4RunManager.

Definition at line 428 of file G4MTRunManager.cc.

429 {
431 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)

Here is the call graph for this function:

void G4MTRunManager::SetUserInitialization ( G4UserWorkerInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 406 of file G4MTRunManager.cc.

407 {
408  userWorkerInitialization = userInit;
409 }
G4UserWorkerInitialization * userWorkerInitialization
void G4MTRunManager::SetUserInitialization ( G4UserWorkerThreadInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 411 of file G4MTRunManager.cc.

412 {
414 }
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
void G4MTRunManager::SetUserInitialization ( G4VUserActionInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 416 of file G4MTRunManager.cc.

417 {
418  userActionInitialization = userInit;
420 }
G4VUserActionInitialization * userActionInitialization

Here is the call graph for this function:

void G4MTRunManager::StoreRNGStatus ( const G4String filenamePrefix)
protectedvirtual

Reimplemented from G4RunManager.

Definition at line 163 of file G4MTRunManager.cc.

164 {
165  std::ostringstream os;
166  os << randomNumberStatusDir << "G4Master_"<<fn <<".rndm";
167  G4Random::saveEngineStatus(os.str().c_str());
168 }
G4String randomNumberStatusDir
void G4MTRunManager::TerminateOneEvent ( )
virtual

Reimplemented from G4RunManager.

Definition at line 213 of file G4MTRunManager.cc.

214 {
215  //Nothing to do
216 }
void G4MTRunManager::TerminateWorkers ( )
protectedvirtual

Definition at line 533 of file G4MTRunManager.cc.

534 {
535  //Force workers to execute (if any) all UI commands left in the stack
537  //Ask workers to exit
539  //Now join threads.
540 #ifdef G4MULTITHREADED //protect here to prevent warning in compilation
541  while ( ! threads.empty() )
542  {
543  G4Thread* t = * ( threads.begin() );
544  threads.pop_front();
546  //G4THREADJOIN(*t);
547  delete t;
548  }
549 #endif
550  threads.clear();
551 }
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4int G4Thread
Definition: G4Threading.hh:174
virtual void RequestWorkersProcessCommandsStack()
virtual void NewActionRequest(WorkerActionRequest newRequest)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::ThisWorkerEndEventLoop ( )
virtual

Definition at line 590 of file G4MTRunManager.cc.

590  {
592 }
void ThisWorkerReady()
Definition: G4MTBarrier.cc:51
G4MTBarrier endOfEventLoopBarrier

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::ThisWorkerProcessCommandsStackDone ( )
virtual

Definition at line 614 of file G4MTRunManager.cc.

614  {
616 }
void ThisWorkerReady()
Definition: G4MTBarrier.cc:51
G4MTBarrier processUIBarrier

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::ThisWorkerReady ( )
virtual

Definition at line 580 of file G4MTRunManager.cc.

580  {
582 }
void ThisWorkerReady()
Definition: G4MTBarrier.cc:51
G4MTBarrier beginOfEventLoopBarrier

Here is the call graph for this function:

Here is the caller graph for this function:

G4MTRunManager::WorkerActionRequest G4MTRunManager::ThisWorkerWaitForNextAction ( )
virtual

Definition at line 602 of file G4MTRunManager.cc.

602  {
604  return nextActionRequest;
605 }
WorkerActionRequest nextActionRequest
void ThisWorkerReady()
Definition: G4MTBarrier.cc:51
G4MTBarrier nextActionRequestBarrier

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::WaitForEndEventLoopWorkers ( )
protectedvirtual

Definition at line 584 of file G4MTRunManager.cc.

584  {
588 }
G4MTBarrier beginOfEventLoopBarrier
void ResetCounter()
Definition: G4MTBarrier.cc:111
void ReleaseBarrier()
Definition: G4MTBarrier.cc:97
G4MTBarrier endOfEventLoopBarrier
void Wait()
Definition: G4MTBarrier.cc:73
size_t GetNumberActiveThreads() const

Here is the call graph for this function:

Here is the caller graph for this function:

void G4MTRunManager::WaitForReadyWorkers ( )
protectedvirtual

Definition at line 574 of file G4MTRunManager.cc.

574  {
578 }
G4MTBarrier beginOfEventLoopBarrier
void ResetCounter()
Definition: G4MTBarrier.cc:111
void ReleaseBarrier()
Definition: G4MTBarrier.cc:97
G4MTBarrier endOfEventLoopBarrier
void Wait()
Definition: G4MTBarrier.cc:73
size_t GetNumberActiveThreads() const

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

G4MTBarrier G4MTRunManager::beginOfEventLoopBarrier
protected

Definition at line 260 of file G4MTRunManager.hh.

G4MTBarrier G4MTRunManager::endOfEventLoopBarrier
protected

Definition at line 261 of file G4MTRunManager.hh.

G4int G4MTRunManager::eventModulo
protected

Definition at line 222 of file G4MTRunManager.hh.

G4int G4MTRunManager::eventModuloDef
protected

Definition at line 221 of file G4MTRunManager.hh.

WorkerActionRequest G4MTRunManager::nextActionRequest
protected

Definition at line 217 of file G4MTRunManager.hh.

G4MTBarrier G4MTRunManager::nextActionRequestBarrier
protected

Definition at line 262 of file G4MTRunManager.hh.

G4int G4MTRunManager::nSeedsFilled
protected

Definition at line 224 of file G4MTRunManager.hh.

G4int G4MTRunManager::nSeedsMax
protected

Definition at line 225 of file G4MTRunManager.hh.

G4int G4MTRunManager::nSeedsPerEvent
protected

Definition at line 226 of file G4MTRunManager.hh.

G4int G4MTRunManager::nSeedsUsed
protected

Definition at line 223 of file G4MTRunManager.hh.

G4int G4MTRunManager::numberOfEventToBeProcessed
protected

Definition at line 140 of file G4MTRunManager.hh.

G4MTBarrier G4MTRunManager::processUIBarrier
protected

Definition at line 263 of file G4MTRunManager.hh.

double* G4MTRunManager::randDbl
protected

Definition at line 227 of file G4MTRunManager.hh.

G4int G4MTRunManager::seedOncePerCommunication = 0
staticprotected

Definition at line 240 of file G4MTRunManager.hh.


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