Geant4  10.02.p03
G4MTRunManager Class Reference

#include <G4MTRunManager.hh>

Inheritance diagram for G4MTRunManager:
Collaboration diagram for G4MTRunManager:

Public Types

enum  WorkerActionRequest { UNDEFINED, NEXTITERATION, 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 ()
 
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 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 G4UserWorkerThreadInitializationGetUserWorkerThreadInitialization () const
 
const G4UserRunActionGetUserRunAction () const
 
const G4VUserPrimaryGeneratorActionGetUserPrimaryGeneratorAction () 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
 
- 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
 

Private Types

typedef std::list< G4Thread * > G4ThreadsList
 

Private Attributes

G4int nworkers
 
G4int forcedNwokers
 
G4int pinAffinity
 
G4ThreadsList threads
 
std::vector< G4StringuiCmdsForWorkers
 
CLHEP::HepRandomEnginemasterRNGEngine
 
G4MTRunManagerKernelMTkernel
 

Static Private Attributes

static G4ScoringManagermasterScM = 0
 
static masterWorlds_t masterWorlds = G4MTRunManager::masterWorlds_t()
 
static G4MTRunManagerfMasterRM = 0
 

Detailed Description

Definition at line 50 of file G4MTRunManager.hh.

Member Typedef Documentation

◆ G4ThreadsList

typedef std::list<G4Thread*> G4MTRunManager::G4ThreadsList
private

Definition at line 112 of file G4MTRunManager.hh.

◆ masterWorlds_t

Definition at line 153 of file G4MTRunManager.hh.

Member Enumeration Documentation

◆ WorkerActionRequest

Enumerator
UNDEFINED 
NEXTITERATION 
ENDWORKER 

Definition at line 192 of file G4MTRunManager.hh.

192  {
193  UNDEFINED ,
194  NEXTITERATION , // There is another set of UI commands to be executed
195  ENDWORKER // Terminate thread, work finished
196  };

Constructor & Destructor Documentation

◆ G4MTRunManager()

G4MTRunManager::G4MTRunManager ( )

Definition at line 84 of file G4MTRunManager.cc.

86  masterRNGEngine(0),
90  nSeedsMax(10000),nSeedsPerEvent(2)
91 {
92  if ( fMasterRM )
93  {
94  G4Exception("G4MTRunManager::G4MTRunManager", "Run0035",FatalException,
95  "Another instance of a G4MTRunManager already exists.");
96  }
97  fMasterRM = this;
98  MTkernel = static_cast<G4MTRunManagerKernel*>(kernel);
99 #ifndef G4MULTITHREADED
101  msg << "Geant4 code is compiled without multi-threading support"
102  << "(-DG4MULTITHREADED is set to off).\n";
103  msg << "G4MTRunManager can only be used in multi-threaded applications.";
104  G4Exception("G4MTRunManager::G4MTRunManager","Run0035",FatalException,msg);
105 #endif
106 
107  G4int numberOfStaticAllocators = kernel->GetNumberOfStaticAllocators();
108  if(numberOfStaticAllocators>0)
109  {
111  msg1 << "There are " << numberOfStaticAllocators
112  << " static G4Allocator objects detected.\n"
113  << "In multi-threaded mode, all G4Allocator objects must be dynamicly instantiated.";
114  G4Exception("G4MTRunManager::G4MTRunManager","Run1035",FatalException,msg1);
115  }
118 
119  //Check if a default RandomNumberGenerator has been created by user,
120  // if not create default one
121  //Note this call forces creation of defaults if not already there
122  //G4Random::getTheEngine(); //User did not specify RNG, create defaults
123  //Now remember the master instance of the RNG Engine
124  masterRNGEngine = G4Random::getTheEngine();
125 #if defined (WIN32)
126  InitializeWindowsConditions();
127 #endif
128 
130  randDbl = new double[nSeedsPerEvent*nSeedsMax];
131 
132  char* env = getenv("G4FORCENUMBEROFTHREADS");
133  if(env)
134  {
135  G4String envS = env;
136  if(envS=="MAX"||envS=="max")
138  else
139  {
140  std::istringstream is(env);
141  G4int val = -1;
142  is >> val;
143  if(val>0)
144  { forcedNwokers = val; }
145  else
146  {
148  msg2 << "Environment variable G4FORCENUMBEROFTHREADS has an invalid value <"
149  << envS << ">. It has to be an integer or a word \"max\".\n"
150  << "G4FORCENUMBEROFTHREADS is ignored.";
151  G4Exception("G4MTRunManager::G4MTRunManager","Run1039",JustWarning,msg2);
152  }
153  }
154  if(forcedNwokers>0)
155  {
157  G4cout << "### Number of threads is forced to " << forcedNwokers
158  << " by Environment variable G4FORCENUMBEROFTHREADS." << G4endl;
159  }
160  }
161 }
WorkerActionRequest nextActionRequest
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
int G4int
Definition: G4Types.hh:78
G4MTRunManagerKernel * MTkernel
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
static G4ScoringManager * GetScoringManagerIfExist()
static G4ScoringManager * masterScM
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:133
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
CLHEP::HepRandomEngine * masterRNGEngine
void SetMasterUIManager(G4bool val)
Definition: G4UImanager.hh:258
static G4MTRunManager * fMasterRM
Here is the call graph for this function:

◆ ~G4MTRunManager()

G4MTRunManager::~G4MTRunManager ( )
virtual

Definition at line 163 of file G4MTRunManager.cc.

164 {
165  //TODO: Currently does not work due to concurrent deletion of something
166  // that is shared:
167  //G4ProcessTable::DeleteMessenger from ~G4RunManager
168  //G4cout<<"Destroy MTRunManager"<<G4endl;//ANDREA
170  delete [] randDbl;
171 }
virtual void TerminateWorkers()
Here is the call graph for this function:

Member Function Documentation

◆ AbortEvent()

void G4MTRunManager::AbortEvent ( )
virtual

Reimplemented from G4RunManager.

Definition at line 576 of file G4MTRunManager.cc.

577 {
578  // nothing to do in the master thread
579 }
Here is the caller graph for this function:

◆ AbortRun()

void G4MTRunManager::AbortRun ( G4bool  softAbort = false)
virtual

Reimplemented from G4RunManager.

Definition at line 560 of file G4MTRunManager.cc.

561 {
562  // This method is valid only for GeomClosed or EventProc state
563  G4ApplicationState currentState =
565  if(currentState==G4State_GeomClosed || currentState==G4State_EventProc)
566  {
567  runAborted = true;
568  MTkernel->BroadcastAbortRun(softAbort);
569  }
570  else
571  {
572  G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
573  }
574 }
G4bool runAborted
G4MTRunManagerKernel * MTkernel
static G4StateManager * GetStateManager()
#define G4endl
Definition: G4ios.hh:61
void BroadcastAbortRun(G4bool softAbort)
G4ApplicationState GetCurrentState() const
G4ApplicationState
G4GLOB_DLL std::ostream G4cerr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addWorld()

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

Definition at line 156 of file G4MTRunManager.hh.

156 { masterWorlds.insert( std::make_pair(counter,w) ); }
static masterWorlds_t masterWorlds
Here is the caller graph for this function:

◆ ConstructScoringWorlds()

void G4MTRunManager::ConstructScoringWorlds ( )
virtual

Reimplemented from G4RunManager.

Definition at line 399 of file G4MTRunManager.cc.

400 {
402  //Call base class stuff...
404 
405  masterWorlds.clear();
407  std::vector<G4VPhysicalVolume*>::iterator itrW
409  for(size_t iWorld=0;iWorld<nWorlds;iWorld++)
410  {
411  addWorld(iWorld,*itrW);
412  itrW++;
413  }
414 }
static void addWorld(G4int counter, G4VPhysicalVolume *w)
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
size_t GetNoWorlds() const
static masterWorlds_t masterWorlds
static G4ScoringManager * GetScoringManagerIfExist()
static G4ScoringManager * masterScM
virtual void ConstructScoringWorlds()
static G4TransportationManager * GetTransportationManager()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateAndStartWorkers()

void G4MTRunManager::CreateAndStartWorkers ( )
protectedvirtual

Reimplemented in tbbMasterRunManager.

Definition at line 245 of file G4MTRunManager.cc.

246 {
247  //Now loop on requested number of workers
248  //This will also start the workers
249  //Currently we do not allow to change the
250  //number of threads: threads area created once
251  if ( threads.size() == 0 ) {
252  for ( G4int nw = 0 ; nw<nworkers; ++nw) {
253  //Create a new worker and remember it
254  G4WorkerThread* context = new G4WorkerThread;
255  context->SetNumberThreads(nworkers);
256  context->SetThreadId(nw);
258  threads.push_back(thread);
259  }
260  }
261  //Signal to threads they can start a new run
263 }
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
void SetThreadId(G4int threadId)
int G4int
Definition: G4Types.hh:78
G4int G4Thread
Definition: G4Threading.hh:174
G4ThreadsList threads
virtual void NewActionRequest(WorkerActionRequest newRequest)
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:

◆ GetCommandStack()

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

Definition at line 239 of file G4MTRunManager.cc.

240 {
241  G4AutoLock l(&cmdHandlingMutex);
242  return uiCmdsForWorkers;
243 }
std::vector< G4String > uiCmdsForWorkers
Here is the caller graph for this function:

◆ GetEventModulo()

G4int G4MTRunManager::GetEventModulo ( ) const
inline

Definition at line 221 of file G4MTRunManager.hh.

221 { return eventModuloDef; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMasterRandomEngine()

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

Definition at line 157 of file G4MTRunManager.hh.

157 { return masterRNGEngine; }
CLHEP::HepRandomEngine * masterRNGEngine
Here is the caller graph for this function:

◆ GetMasterRunManager()

G4MTRunManager * G4MTRunManager::GetMasterRunManager ( )
static

Definition at line 65 of file G4MTRunManager.cc.

66 {
68  return fMasterRM;
72 }
static G4MTRunManager * fMasterRM
Here is the caller graph for this function:

◆ GetMasterRunManagerKernel()

G4RunManagerKernel * G4MTRunManager::GetMasterRunManagerKernel ( )
static

Definition at line 74 of file G4MTRunManager.cc.

75 {
76  return fMasterRM->kernel;
77 }
G4RunManagerKernel * kernel
static G4MTRunManager * fMasterRM
Here is the caller graph for this function:

◆ GetMasterScoringManager()

static G4ScoringManager* G4MTRunManager::GetMasterScoringManager ( )
inlinestatic

Definition at line 154 of file G4MTRunManager.hh.

154 { return masterScM; }
static G4ScoringManager * masterScM
Here is the caller graph for this function:

◆ GetMasterWorlds()

static masterWorlds_t& G4MTRunManager::GetMasterWorlds ( )
inlinestatic

Definition at line 155 of file G4MTRunManager.hh.

155 { return masterWorlds; }
static masterWorlds_t masterWorlds
Here is the caller graph for this function:

◆ GetMTMasterRunManagerKernel()

G4MTRunManagerKernel * G4MTRunManager::GetMTMasterRunManagerKernel ( )
static

Definition at line 79 of file G4MTRunManager.cc.

80 {
81  return fMasterRM->MTkernel;
82 }
G4MTRunManagerKernel * MTkernel
static G4MTRunManager * fMasterRM

◆ GetNumberOfThreads()

G4int G4MTRunManager::GetNumberOfThreads ( ) const
inline

Definition at line 56 of file G4MTRunManager.hh.

56 { return nworkers; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPinAffinity()

G4int G4MTRunManager::GetPinAffinity ( ) const
inline

Definition at line 58 of file G4MTRunManager.hh.

58 { return pinAffinity; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Initialize()

void G4MTRunManager::Initialize ( void  )
virtual

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

Reimplemented from G4RunManager.

Definition at line 205 of file G4MTRunManager.cc.

206 {
208 
209  // make sure all worker threads are set up.
210  BeamOn(0);
211  SetRunIDCounter(0);
213 }
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:
Here is the caller graph for this function:

◆ InitializeEventLoop()

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

Reimplemented from G4RunManager.

Definition at line 266 of file G4MTRunManager.cc.

267 {
269  numberOfEventToBeProcessed = n_event;
271 
272  if(!fakeRun)
273  {
274  nSeedsUsed = 0;
275  nSeedsFilled = 0;
276 
277  if(verboseLevel>0)
278  { timer->Start(); }
279 
280  n_select_msg = n_select;
281  if(macroFile!=0)
282  {
283  if(n_select_msg<0) n_select_msg = n_event;
284  msgText = "/control/execute ";
285  msgText += macroFile;
286  selectMacro = macroFile;
287  }
288  else
289  {
290  n_select_msg = -1;
291  selectMacro = "";
292  }
293 
294  //initialize seeds
295  //If user did not implement InitializeSeeds,
296  // use default: nSeedsPerEvent seeds per event
297  if( eventModuloDef > 0 )
298  {
301  {
303  if(eventModulo<1) eventModulo =1;
305  msgd << "Event modulo is reduced to " << eventModulo
306  << " to distribute events to all threads.";
307  G4Exception("G4MTRunManager::InitializeEventLoop()",
308  "Run10035", JustWarning, msgd);
309  }
310  }
311  else
312  {
313  eventModulo = int(std::sqrt(double(numberOfEventToBeProcessed/nworkers)));
314  if(eventModulo<1) eventModulo =1;
315  }
316  if ( InitializeSeeds(n_event) == false && n_event>0 )
317  {
320  {
321  case 0:
322  nSeedsFilled = n_event;
323  break;
324  case 1:
326  break;
327  case 2:
328  nSeedsFilled = n_event/eventModulo + 1;
329  break;
330  default:
332  msgd << "Parameter value <" << seedOncePerCommunication
333  << "> of seedOncePerCommunication is invalid. It is reset to 0." ;
334  G4Exception("G4MTRunManager::InitializeEventLoop()",
335  "Run10036", JustWarning, msgd);
336  seedOncePerCommunication = 0;
337  nSeedsFilled = n_event;
338  }
339 
340  // Generates up to nSeedsMax seed pairs only.
343  helper->Fill(randDbl,nSeedsFilled,n_event,nSeedsPerEvent);
344  }
345  }
346 
347  //Now initialize workers. Check if user defined a WorkerThreadInitialization
350 
351  //Prepare UI commands for threads
353 
354  //Start worker threads
356 
357  // We need a barrier here. Wait for workers to start event loop.
358  //This will return only when all workers have started processing events.
360 }
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
G4MTRunManagerKernel * MTkernel
void Fill(G4double *dbl, G4int nev, G4int nev_tot, G4int nrpe)
Definition: G4RNGHelper.hh:81
virtual void WaitForReadyWorkers()
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
CLHEP::HepRandomEngine * masterRNGEngine
G4int verboseLevel
virtual void CreateAndStartWorkers()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeSeeds()

virtual G4bool G4MTRunManager::InitializeSeeds ( G4int  )
inlineprotectedvirtual

Definition at line 92 of file G4MTRunManager.hh.

92 { return false; };
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MergeRun()

void G4MTRunManager::MergeRun ( const G4Run localRun)

Definition at line 485 of file G4MTRunManager.cc.

486 {
487  G4AutoLock l(&runMergerMutex);
488  if(currentRun) currentRun->Merge(localRun);
489 }
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:

◆ MergeScores()

void G4MTRunManager::MergeScores ( const G4ScoringManager localScoringManager)

Definition at line 479 of file G4MTRunManager.cc.

480 {
481  G4AutoLock l(&scorerMergerMutex);
482  if(masterScM) masterScM->Merge(localScoringManager);
483 }
static G4ScoringManager * masterScM
void Merge(const G4ScoringManager *scMan)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NewActionRequest()

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

Reimplemented in tbbMasterRunManager.

Definition at line 830 of file G4MTRunManager.cc.

831 {
832  //Wait for all workers to be ready to accept a new action request
833  while (true)
834  {
835 #ifndef WIN32
836  G4AutoLock l(&numberOfReadyWorkersForNewActionMutex);
837 #else
838  EnterCriticalSection( &cs3 );
839 #endif
840  //Check the number of workers that are ready for next action
841  G4int activethreads = threads.size();
842  if ( numberOfReadyWorkersForNewAction == activethreads )
843  {
844  //Ok, exit the loop
845  break;
846  }
847  //Wait for the number of workers ready for new action to change
848 #ifdef WIN32
849  G4CONDITIONWAIT(&numberOfReadyWorkersForNewActionChangedCondition,
850  &cs3);
851  LeaveCriticalSection( &cs3 );
852 #else
853  G4CONDITIONWAIT(&numberOfReadyWorkersForNewActionChangedCondition,
854  &numberOfReadyWorkersForNewActionMutex);
855 #endif
856  }
857  //Now set the new action to the shared resource
858  G4AutoLock l(&nextActionRequestMutex);
859  nextActionRequest = newRequest;
860  l.unlock();
861  //Reset counter of workers ready-for-new-action in preparation of next call
862  G4AutoLock l2(&numberOfReadyWorkersForNewActionMutex);
863  numberOfReadyWorkersForNewAction = 0;
864  //l2.unlock(); //<----- This thread needs to have control on mutex associated
865  //to condition variable (report from valgrind --tool=drd)
866  //see: http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Fapis%2Fusers_73.htm
867  //Now signal all workers that there is a new action to be performed
868  G4CONDTIONBROADCAST(&requestChangeActionForWorker);
869 }
WorkerActionRequest nextActionRequest
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:192
int G4int
Definition: G4Types.hh:78
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:191
G4ThreadsList threads
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrepareCommandsStack()

void G4MTRunManager::PrepareCommandsStack ( )
protectedvirtual

Definition at line 228 of file G4MTRunManager.cc.

228  {
229  G4AutoLock l(&cmdHandlingMutex);
230  uiCmdsForWorkers.clear();
231  std::vector<G4String>* cmdCopy = G4UImanager::GetUIpointer()->GetCommandStack();
232  for ( std::vector<G4String>::const_iterator it = cmdCopy->begin() ;
233  it != cmdCopy->end(); ++it )
234  uiCmdsForWorkers.push_back(*it);
235  cmdCopy->clear();
236  delete cmdCopy;
237 }
std::vector< G4String > uiCmdsForWorkers
std::vector< G4String > * GetCommandStack()
Definition: G4UImanager.cc:709
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessOneEvent()

void G4MTRunManager::ProcessOneEvent ( G4int  i_event)
virtual

Reimplemented from G4RunManager.

Definition at line 219 of file G4MTRunManager.cc.

220 {
221  //Nothing to do
222 }
Here is the caller graph for this function:

◆ RefillSeeds()

void G4MTRunManager::RefillSeeds ( )
protected

Definition at line 362 of file G4MTRunManager.cc.

363 {
365  G4int nFill = 0;
367  {
368  case 0:
370  break;
371  case 1:
372  nFill = nworkers - nSeedsFilled;
373  break;
374  case 2:
375  default:
376  nFill = (numberOfEventToBeProcessed - nSeedsFilled*eventModulo)/eventModulo + 1;
377  }
378  // Generates up to nSeedsMax seed pairs only.
379  if(nFill>nSeedsMax) nFill=nSeedsMax;
381  helper->Refill(randDbl,nFill);
382  nSeedsFilled += nFill;
383 //G4cout<<"helper->Refill() for "<<nFill<<" events."<<G4endl;
384 }
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
CLHEP::HepRandomEngine * masterRNGEngine
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RunTermination()

void G4MTRunManager::RunTermination ( )
virtual

Reimplemented from G4RunManager.

Reimplemented in tbbMasterRunManager.

Definition at line 386 of file G4MTRunManager.cc.

387 {
388  //Wait for all worker threads to have finished the run
389  //i.e. wait for them to return from RunTermination()
390  //This guarantee that userrunaction for workers has been called
391 
392  // Wait now for all threads to finish event-loop
394  //Now call base-class methof
397 }
virtual void TerminateEventLoop()
virtual void RunTermination()
virtual void WaitForEndEventLoopWorkers()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SeedOncePerCommunication()

static G4int G4MTRunManager::SeedOncePerCommunication ( )
inlinestatic

Definition at line 244 of file G4MTRunManager.hh.

244 { return seedOncePerCommunication; }
static G4int seedOncePerCommunication
Here is the caller graph for this function:

◆ SetEventModulo()

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

Definition at line 220 of file G4MTRunManager.hh.

220 { eventModuloDef = i; }

◆ SetNumberOfThreads()

void G4MTRunManager::SetNumberOfThreads ( G4int  n)

Definition at line 180 of file G4MTRunManager.cc.

181 {
182  if ( threads.size() != 0 )
183  {
185  msg << "Number of threads cannot be changed at this moment \n"
186  << "(old threads are still alive). Method ignored.";
187  G4Exception("G4MTRunManager::SetNumberOfThreads(G4int)",
188  "Run0035", JustWarning, msg);
189  }
190  else if ( forcedNwokers > 0 )
191  {
193  msg << "Number of threads is forced to " << forcedNwokers
194  << " by G4FORCENUMBEROFTHREADS shell variable.\n"
195  << "Method ignored.";
196  G4Exception("G4MTRunManager::SetNumberOfThreads(G4int)",
197  "Run0035", JustWarning, msg);
198  }
199  else
200  {
201  nworkers = n;
202  }
203 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
Char_t n[5]
G4ThreadsList threads
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:
Here is the caller graph for this function:

◆ SetPinAffinity()

void G4MTRunManager::SetPinAffinity ( G4int  n = 1)

Definition at line 897 of file G4MTRunManager.cc.

898 {
899  if ( n == 0 )
900  {
901  G4Exception("G4MTRunManager::SetPinAffinity",
902  "Run0035",FatalException,
903  "Pin affinity must be >0 or <0.");
904  }
905  pinAffinity = n;
906  return;
907 }
Char_t n[5]
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:
Here is the caller graph for this function:

◆ SetSeedOncePerCommunication()

static void G4MTRunManager::SetSeedOncePerCommunication ( G4int  val)
inlinestatic

Definition at line 245 of file G4MTRunManager.hh.

245 { seedOncePerCommunication = val; }
static G4int seedOncePerCommunication
Here is the caller graph for this function:

◆ SetUpAnEvent()

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

Definition at line 491 of file G4MTRunManager.cc.

492 {
493  G4AutoLock l(&setUpEventMutex);
495  {
497  if(reseedRequired)
498  {
500  G4int idx_rndm = nSeedsPerEvent*nSeedsUsed;
501  s1 = helper->GetSeed(idx_rndm);
502  s2 = helper->GetSeed(idx_rndm+1);
503  if(nSeedsPerEvent==3) s3 = helper->GetSeed(idx_rndm+2);
504  nSeedsUsed++;
505  if(nSeedsUsed==nSeedsFilled) RefillSeeds();
506  }
508  return true;
509  }
510  return false;
511 }
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:

◆ SetUpNEvents()

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

Definition at line 513 of file G4MTRunManager.cc.

514 {
515  G4AutoLock l(&setUpEventMutex);
517  {
518  G4int nev = eventModulo;
522  if(reseedRequired)
523  {
525  G4int nevRnd = nev;
526  if(seedOncePerCommunication>0) nevRnd = 1;
527  for(int i=0;i<nevRnd;i++)
528  {
529  seedsQueue->push(helper->GetSeed(nSeedsPerEvent*nSeedsUsed));
530  seedsQueue->push(helper->GetSeed(nSeedsPerEvent*nSeedsUsed+1));
531  if(nSeedsPerEvent==3)
532  seedsQueue->push(helper->GetSeed(nSeedsPerEvent*nSeedsUsed+2));
533  nSeedsUsed++;
534  if(nSeedsUsed==nSeedsFilled) RefillSeeds();
535  }
536  }
537  numberOfEventProcessed += nev;
538  return nev;
539  }
540  return 0;
541 }
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:

◆ SetUserAction() [1/6]

void G4MTRunManager::SetUserAction ( G4UserRunAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 443 of file G4MTRunManager.cc.

444 {
445  G4RunManager::SetUserAction(userAction);
446  userAction->SetMaster();
447 }
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:

◆ SetUserAction() [2/6]

void G4MTRunManager::SetUserAction ( G4VUserPrimaryGeneratorAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 449 of file G4MTRunManager.cc.

450 {
451  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
452  "For multi-threaded version, define G4VUserPrimaryGeneratorAction in G4VUserActionInitialization.");
453 }
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:

◆ SetUserAction() [3/6]

void G4MTRunManager::SetUserAction ( G4UserEventAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 455 of file G4MTRunManager.cc.

456 {
457  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
458  "For multi-threaded version, define G4UserEventAction in G4VUserActionInitialization.");
459 }
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:

◆ SetUserAction() [4/6]

void G4MTRunManager::SetUserAction ( G4UserStackingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 461 of file G4MTRunManager.cc.

462 {
463  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
464  "For multi-threaded version, define G4UserStackingAction in G4VUserActionInitialization.");
465 }
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:

◆ SetUserAction() [5/6]

void G4MTRunManager::SetUserAction ( G4UserTrackingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 467 of file G4MTRunManager.cc.

468 {
469  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
470  "For multi-threaded version, define G4UserTrackingAction in G4VUserActionInitialization.");
471 }
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:

◆ SetUserAction() [6/6]

void G4MTRunManager::SetUserAction ( G4UserSteppingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 473 of file G4MTRunManager.cc.

474 {
475  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
476  "For multi-threaded version, define G4UserSteppingAction in G4VUserActionInitialization.");
477 }
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:

◆ SetUserInitialization() [1/5]

void G4MTRunManager::SetUserInitialization ( G4VUserPhysicsList userPL)
virtual

Reimplemented from G4RunManager.

Definition at line 432 of file G4MTRunManager.cc.

433 {
435  //Needed for MT, to be moved in kernel
436 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetUserInitialization() [2/5]

void G4MTRunManager::SetUserInitialization ( G4VUserDetectorConstruction userDC)
virtual

Reimplemented from G4RunManager.

Definition at line 438 of file G4MTRunManager.cc.

439 {
441 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
Here is the call graph for this function:

◆ SetUserInitialization() [3/5]

void G4MTRunManager::SetUserInitialization ( G4UserWorkerInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 416 of file G4MTRunManager.cc.

417 {
418  userWorkerInitialization = userInit;
419 }
G4UserWorkerInitialization * userWorkerInitialization

◆ SetUserInitialization() [4/5]

void G4MTRunManager::SetUserInitialization ( G4UserWorkerThreadInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 421 of file G4MTRunManager.cc.

422 {
424 }
G4UserWorkerThreadInitialization * userWorkerThreadInitialization

◆ SetUserInitialization() [5/5]

void G4MTRunManager::SetUserInitialization ( G4VUserActionInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 426 of file G4MTRunManager.cc.

427 {
428  userActionInitialization = userInit;
430 }
G4VUserActionInitialization * userActionInitialization
Here is the call graph for this function:

◆ StoreRNGStatus()

void G4MTRunManager::StoreRNGStatus ( const G4String filenamePrefix)
protectedvirtual

Reimplemented from G4RunManager.

Definition at line 173 of file G4MTRunManager.cc.

174 {
175  std::ostringstream os;
176  os << randomNumberStatusDir << "G4Master_"<<fn <<".rndm";
177  G4Random::saveEngineStatus(os.str().c_str());
178 }
G4String randomNumberStatusDir
Here is the caller graph for this function:

◆ TerminateOneEvent()

void G4MTRunManager::TerminateOneEvent ( )
virtual

Reimplemented from G4RunManager.

Definition at line 223 of file G4MTRunManager.cc.

224 {
225  //Nothing to do
226 }
Here is the caller graph for this function:

◆ TerminateWorkers()

void G4MTRunManager::TerminateWorkers ( )
protectedvirtual

Reimplemented in tbbMasterRunManager.

Definition at line 543 of file G4MTRunManager.cc.

544 {
546  //Now join threads.
547 #ifdef G4MULTITHREADED //protect here to prevent warning in compilation
548  while ( ! threads.empty() )
549  {
550  G4Thread* t = * ( threads.begin() );
551  threads.pop_front();
553  //G4THREADJOIN(*t);
554  delete t;
555  }
556 #endif
557  threads.clear();
558 }
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4int G4Thread
Definition: G4Threading.hh:174
G4ThreadsList threads
virtual void NewActionRequest(WorkerActionRequest newRequest)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ThisWorkerEndEventLoop()

void G4MTRunManager::ThisWorkerEndEventLoop ( )
virtual

Reimplemented in tbbMasterRunManager.

Definition at line 810 of file G4MTRunManager.cc.

811 {
812  //Increament number of workers in end of evnet loop by 1
813 #ifndef WIN32
814  G4AutoLock l(&numberOfEndOfEventLoopWorkersMutex);
815 #else
816  EnterCriticalSection( &cs2 );
817 #endif
818  ++numberOfEndOfEventLoopWorkers;
819  //Signale this number has changed
820  G4CONDTIONBROADCAST(&numWorkersEndEventLoopChangedCondition);
821  //Wait for condition to exit eventloop
822 #ifdef WIN32
823  G4CONDITIONWAIT(&endEventLoopCondition,&cs2);
824  LeaveCriticalSection( &cs2 );
825 #else
826  G4CONDITIONWAIT(&endEventLoopCondition,&numberOfEndOfEventLoopWorkersMutex);
827 #endif
828 }
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:192
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:191
Here is the caller graph for this function:

◆ ThisWorkerReady()

void G4MTRunManager::ThisWorkerReady ( )
virtual

Reimplemented in tbbMasterRunManager.

Definition at line 748 of file G4MTRunManager.cc.

749 {
750  //Increament number of active worker by 1
751 #ifndef WIN32
752  G4AutoLock lockLoop(&numberOfReadyWorkersMutex);
753 #else
754  EnterCriticalSection( &cs1 );
755 #endif
756  ++numberOfReadyWorkers;
757  //Signal the number of workers has changed
758  G4CONDTIONBROADCAST(&numWorkersBeginEventLoopChangeCondition);
759  //Wait for condition to start eventloop
760 #ifdef WIN32
761  G4CONDITIONWAIT(&beginEventLoopCondition,&cs1);
762  LeaveCriticalSection( &cs1 );
763 #else
764  G4CONDITIONWAIT(&beginEventLoopCondition,&numberOfReadyWorkersMutex);
765 #endif
766  //Protects access to shared resource, guarantees we do not call this method
767  //while someone else is modifying its content (e.g. creating a new particle)
768  //G4PDefManager& pdm = const_cast<G4PDefManager&>(G4ParticleDefinition::GetSubInstanceManager());
769  //pdm.Lock();
770  //pdm.NewSubInstances();
771  //pdm.UnLock();
772  //const_cast<G4PDefManager&>(G4ParticleDefinition::GetSubInstanceManager()).NewSubInstances();
773  // I believe this is not necessary and safe to remove (Makoto)
774  //G4ParticleTable::GetParticleTable()->WorkerG4ParticleTable();
775 }
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:192
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:191
Here is the caller graph for this function:

◆ ThisWorkerWaitForNextAction()

G4MTRunManager::WorkerActionRequest G4MTRunManager::ThisWorkerWaitForNextAction ( )
virtual

Reimplemented in tbbMasterRunManager.

Definition at line 871 of file G4MTRunManager.cc.

872 {
873  //This worker is ready to receive a new action request,
874  //increment counter by 1
875  #ifndef WIN32
876  G4AutoLock l(&numberOfReadyWorkersForNewActionMutex);
877 #else
878  EnterCriticalSection( &cs3 );
879 #endif
880  ++numberOfReadyWorkersForNewAction;
881  //Singal the sahred resource has changed to the master
882  G4CONDTIONBROADCAST(&numberOfReadyWorkersForNewActionChangedCondition);
883  //Wait for condition that a new aciton is ready
884 #ifdef WIN32
885  G4CONDITIONWAIT(&requestChangeActionForWorker,&cs3);
886  LeaveCriticalSection( &cs3 );
887 #else
888  G4CONDITIONWAIT(&requestChangeActionForWorker,&numberOfReadyWorkersForNewActionMutex);
889 #endif
890  //Ok, if I am here it means that a new action has been requested by the master
891  //reads it value that is now read-only, so no mutex is needed, but you never know...
892  G4AutoLock l2(&nextActionRequestMutex);
894  return result;
895 }
WorkerActionRequest nextActionRequest
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:192
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:191
Here is the caller graph for this function:

◆ WaitForEndEventLoopWorkers()

void G4MTRunManager::WaitForEndEventLoopWorkers ( )
protectedvirtual

Reimplemented in tbbMasterRunManager.

Definition at line 778 of file G4MTRunManager.cc.

779 {
780  while (true)
781  {
782 #ifndef WIN32
783  G4AutoLock l(&numberOfEndOfEventLoopWorkersMutex);
784 #else
785  EnterCriticalSection( &cs2 );
786 #endif
787  G4int activethreads = threads.size();
788  if ( numberOfEndOfEventLoopWorkers == activethreads )
789  {
790  break;
791  }
792 #ifdef WIN32
793  G4CONDITIONWAIT(&numWorkersEndEventLoopChangedCondition,
794  &cs2);
795  LeaveCriticalSection( &cs2 );
796 #else
797  G4CONDITIONWAIT(&numWorkersEndEventLoopChangedCondition,
798  &numberOfEndOfEventLoopWorkersMutex);
799 #endif
800  }
801  //Now number of workers that reached end of event loop is as expected
802  //Reset number of workers in ready for work state so a new run can start
803  G4AutoLock l(&numberOfReadyWorkersMutex);
804  numberOfReadyWorkers = 0;
805  //Signal workers they can end event-loop
806  G4AutoLock l2(&numberOfEndOfEventLoopWorkersMutex);
807  G4CONDTIONBROADCAST(&endEventLoopCondition);
808 }
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:192
int G4int
Definition: G4Types.hh:78
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:191
G4ThreadsList threads
Here is the caller graph for this function:

◆ WaitForReadyWorkers()

void G4MTRunManager::WaitForReadyWorkers ( )
protectedvirtual

Reimplemented in tbbMasterRunManager.

Definition at line 692 of file G4MTRunManager.cc.

693 {
694  while (true) //begin barrier
695  {
696 #ifndef WIN32
697  G4AutoLock lockLoop(&numberOfReadyWorkersMutex);
698 #else
699  EnterCriticalSection( &cs1 );
700 #endif
701  //Check number of workers ready to begin
702  G4int activethreads = threads.size();
703  if (numberOfReadyWorkers == activethreads )
704  {
705  //Ok, interrupt the loop
706  break;
707  }
708  //Wait for the number of workers to be changed
709 #ifdef WIN32
710  G4CONDITIONWAIT(&numWorkersBeginEventLoopChangeCondition,
711  &cs1);
712  LeaveCriticalSection( &cs1 );
713 #else
714  G4CONDITIONWAIT(&numWorkersBeginEventLoopChangeCondition,
715  &numberOfReadyWorkersMutex);
716 #endif
717  }
718  //Now number of workers is as expected.
737 
738  //Prepare to wait for workers to end eventloop
739  //Reset number of workers in "EndOfEventLoop"
740  G4AutoLock l(&numberOfEndOfEventLoopWorkersMutex);
741  numberOfEndOfEventLoopWorkers = 0;
742 
743  //signal workers they can start the event-loop
744  G4AutoLock l2(&numberOfReadyWorkersMutex);
745  G4CONDTIONBROADCAST(&beginEventLoopCondition);
746 }
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:192
int G4int
Definition: G4Types.hh:78
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:191
G4ThreadsList threads
Here is the caller graph for this function:

Member Data Documentation

◆ eventModulo

G4int G4MTRunManager::eventModulo
protected

Definition at line 210 of file G4MTRunManager.hh.

◆ eventModuloDef

G4int G4MTRunManager::eventModuloDef
protected

Definition at line 209 of file G4MTRunManager.hh.

◆ fMasterRM

G4MTRunManager * G4MTRunManager::fMasterRM = 0
staticprivate

Definition at line 163 of file G4MTRunManager.hh.

◆ forcedNwokers

G4int G4MTRunManager::forcedNwokers
private

Definition at line 107 of file G4MTRunManager.hh.

◆ masterRNGEngine

CLHEP::HepRandomEngine* G4MTRunManager::masterRNGEngine
private

Definition at line 118 of file G4MTRunManager.hh.

◆ masterScM

G4ScoringManager * G4MTRunManager::masterScM = 0
staticprivate

Definition at line 160 of file G4MTRunManager.hh.

◆ masterWorlds

G4MTRunManager::masterWorlds_t G4MTRunManager::masterWorlds = G4MTRunManager::masterWorlds_t()
staticprivate

Definition at line 161 of file G4MTRunManager.hh.

◆ MTkernel

G4MTRunManagerKernel* G4MTRunManager::MTkernel
private

Definition at line 164 of file G4MTRunManager.hh.

◆ nextActionRequest

WorkerActionRequest G4MTRunManager::nextActionRequest
protected

Definition at line 205 of file G4MTRunManager.hh.

◆ nSeedsFilled

G4int G4MTRunManager::nSeedsFilled
protected

Definition at line 212 of file G4MTRunManager.hh.

◆ nSeedsMax

G4int G4MTRunManager::nSeedsMax
protected

Definition at line 213 of file G4MTRunManager.hh.

◆ nSeedsPerEvent

G4int G4MTRunManager::nSeedsPerEvent
protected

Definition at line 214 of file G4MTRunManager.hh.

◆ nSeedsUsed

G4int G4MTRunManager::nSeedsUsed
protected

Definition at line 211 of file G4MTRunManager.hh.

◆ numberOfEventToBeProcessed

G4int G4MTRunManager::numberOfEventToBeProcessed
protected

Definition at line 134 of file G4MTRunManager.hh.

◆ nworkers

G4int G4MTRunManager::nworkers
private

Definition at line 105 of file G4MTRunManager.hh.

◆ pinAffinity

G4int G4MTRunManager::pinAffinity
private

Definition at line 109 of file G4MTRunManager.hh.

◆ randDbl

double* G4MTRunManager::randDbl
protected

Definition at line 215 of file G4MTRunManager.hh.

◆ seedOncePerCommunication

G4int G4MTRunManager::seedOncePerCommunication = 0
staticprotected

Definition at line 228 of file G4MTRunManager.hh.

◆ threads

G4ThreadsList G4MTRunManager::threads
private

Definition at line 113 of file G4MTRunManager.hh.

◆ uiCmdsForWorkers

std::vector<G4String> G4MTRunManager::uiCmdsForWorkers
private

Definition at line 116 of file G4MTRunManager.hh.


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