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

#include <G4MTRunManager.hh>

Inheritance diagram for G4MTRunManager:
G4RunManager tbbMasterRunManager

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
 
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 TerminateEventLoop ()
 
virtual void ConstructScoringWorlds ()
 
virtual void InitializePhysics ()
 
virtual void RunTermination ()
 
virtual G4bool SetUpAnEvent (G4Event *, long &s1, long &s2, long &s3)
 
virtual G4int SetUpNEvents (G4Event *, G4SeedsQueue *seedsQueue)
 
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 G4bool ConfirmBeamOnCondition ()
 
virtual void RunInitialization ()
 
virtual void DoEventLoop (G4int n_event, const char *macroFile=0, G4int n_select=-1)
 
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
 

Static Public Member Functions

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

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 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::vector< 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
 

Detailed Description

Definition at line 50 of file G4MTRunManager.hh.

Member Typedef Documentation

Definition at line 149 of file G4MTRunManager.hh.

Member Enumeration Documentation

Enumerator
UNDEFINED 
NEXTITERATION 
ENDWORKER 

Definition at line 188 of file G4MTRunManager.hh.

188  {
189  UNDEFINED ,
190  NEXTITERATION , // There is another set of UI commands to be executed
191  ENDWORKER // Terminate thread, work finished
192  };

Constructor & Destructor Documentation

G4MTRunManager::G4MTRunManager ( )

Definition at line 83 of file G4MTRunManager.cc.

References FatalException, G4cout, G4endl, G4Exception(), G4Threading::G4GetNumberOfCores(), G4RunManagerKernel::GetNumberOfStaticAllocators(), G4ScoringManager::GetScoringManagerIfExist(), G4UImanager::GetUIpointer(), JustWarning, G4RunManager::kernel, nSeedsMax, nSeedsPerEvent, numberOfEventToBeProcessed, randDbl, and G4UImanager::SetMasterUIManager().

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

Definition at line 162 of file G4MTRunManager.cc.

References randDbl, and TerminateWorkers().

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

Member Function Documentation

void G4MTRunManager::AbortEvent ( )
virtual

Reimplemented from G4RunManager.

Definition at line 546 of file G4MTRunManager.cc.

547 {
548  // nothing to do in the master thread
549 }
void G4MTRunManager::AbortRun ( G4bool  softAbort = false)
virtual

Reimplemented from G4RunManager.

Definition at line 530 of file G4MTRunManager.cc.

References G4MTRunManagerKernel::BroadcastAbortRun(), G4cerr, G4endl, G4State_EventProc, G4State_GeomClosed, G4StateManager::GetCurrentState(), G4StateManager::GetStateManager(), and G4RunManager::runAborted.

531 {
532  // This method is valid only for GeomClosed or EventProc state
533  G4ApplicationState currentState =
535  if(currentState==G4State_GeomClosed || currentState==G4State_EventProc)
536  {
537  runAborted = true;
538  MTkernel->BroadcastAbortRun(softAbort);
539  }
540  else
541  {
542  G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
543  }
544 }
G4bool runAborted
static G4StateManager * GetStateManager()
G4ApplicationState GetCurrentState() const
#define G4endl
Definition: G4ios.hh:61
void BroadcastAbortRun(G4bool softAbort)
G4ApplicationState
G4GLOB_DLL std::ostream G4cerr
static void G4MTRunManager::addWorld ( G4int  counter,
G4VPhysicalVolume w 
)
inlinestatic

Definition at line 152 of file G4MTRunManager.hh.

Referenced by ConstructScoringWorlds().

152 { masterWorlds.insert( std::make_pair(counter,w) ); }
void G4MTRunManager::ConstructScoringWorlds ( )
virtual

Reimplemented from G4RunManager.

Definition at line 366 of file G4MTRunManager.cc.

References addWorld(), G4RunManager::ConstructScoringWorlds(), G4TransportationManager::GetNoWorlds(), G4ScoringManager::GetScoringManagerIfExist(), G4TransportationManager::GetTransportationManager(), and G4TransportationManager::GetWorldsIterator().

367 {
369  //Call base class stuff...
371 
372  masterWorlds.clear();
374  std::vector<G4VPhysicalVolume*>::iterator itrW
376  for(size_t iWorld=0;iWorld<nWorlds;iWorld++)
377  {
378  addWorld(iWorld,*itrW);
379  itrW++;
380  }
381 }
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
void G4MTRunManager::CreateAndStartWorkers ( )
protectedvirtual

Reimplemented in tbbMasterRunManager.

Definition at line 244 of file G4MTRunManager.cc.

References G4UserWorkerThreadInitialization::CreateAndStartWorker(), NewActionRequest(), NEXTITERATION, G4WorkerThread::SetNumberThreads(), G4WorkerThread::SetThreadId(), and G4RunManager::userWorkerThreadInitialization.

Referenced by InitializeEventLoop().

245 {
246  //Now loop on requested number of workers
247  //This will also start the workers
248  //Currently we do not allow to change the
249  //number of threads: threads area created once
250  if ( threads.size() == 0 ) {
251  for ( G4int nw = 0 ; nw<nworkers; ++nw) {
252  //Create a new worker and remember it
254  context->SetNumberThreads(nworkers);
255  context->SetThreadId(nw);
257  threads.push_back(thread);
258  }
259  }
260  //Signal to threads they can start a new run
262 }
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
void SetThreadId(G4int threadId)
int G4int
Definition: G4Types.hh:78
G4int G4Thread
Definition: G4Threading.hh:157
virtual void NewActionRequest(WorkerActionRequest newRequest)
const XML_Char * context
virtual G4Thread * CreateAndStartWorker(G4WorkerThread *workerThreadContext)
void SetNumberThreads(G4int numnberThreads)
std::vector< G4String > G4MTRunManager::GetCommandStack ( )

Definition at line 238 of file G4MTRunManager.cc.

Referenced by tbbTask::execute(), and G4MTRunManagerKernel::StartThread().

239 {
240  G4AutoLock l(&cmdHandlingMutex);
241  return uiCmdsForWorkers;
242 }
G4int G4MTRunManager::GetEventModulo ( ) const
inline

Definition at line 217 of file G4MTRunManager.hh.

References eventModuloDef.

Referenced by G4WorkerRunManager::GenerateEvent().

217 { return eventModuloDef; }
const CLHEP::HepRandomEngine* G4MTRunManager::getMasterRandomEngine ( ) const
inline

Definition at line 153 of file G4MTRunManager.hh.

Referenced by tbbTask::execute(), and G4MTRunManagerKernel::StartThread().

153 { return masterRNGEngine; }
G4MTRunManager * G4MTRunManager::GetMasterRunManager ( )
static
G4RunManagerKernel * G4MTRunManager::GetMasterRunManagerKernel ( )
static

Definition at line 73 of file G4MTRunManager.cc.

References G4RunManager::kernel.

Referenced by G4WorkerRunManager::InitializeGeometry().

74 {
75  return fMasterRM->kernel;
76 }
G4RunManagerKernel * kernel
static G4ScoringManager* G4MTRunManager::GetMasterScoringManager ( )
inlinestatic

Definition at line 150 of file G4MTRunManager.hh.

Referenced by G4WorkerRunManager::ConstructScoringWorlds(), and G4WorkerRunManager::G4WorkerRunManager().

150 { return masterScM; }
static masterWorlds_t& G4MTRunManager::GetMasterWorlds ( )
inlinestatic

Definition at line 151 of file G4MTRunManager.hh.

Referenced by G4RunManagerKernel::WorkerDefineWorldVolume(), and G4RunManagerKernel::WorkerUpdateWorldVolume().

151 { return masterWorlds; }
G4MTRunManagerKernel * G4MTRunManager::GetMTMasterRunManagerKernel ( )
static

Definition at line 78 of file G4MTRunManager.cc.

79 {
80  return fMasterRM->MTkernel;
81 }
G4int G4MTRunManager::GetNumberOfThreads ( ) const
inline

Definition at line 56 of file G4MTRunManager.hh.

Referenced by main().

56 { return nworkers; }
void G4MTRunManager::Initialize ( void  )
virtual

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

Reimplemented from G4RunManager.

Definition at line 204 of file G4MTRunManager.cc.

References G4RunManager::BeamOn(), G4RunManager::Initialize(), and G4RunManager::SetRunIDCounter().

Referenced by main().

205 {
207 
208  // make sure all worker threads are set up.
209  BeamOn(0);
210  SetRunIDCounter(0);
211  ///G4UImanager::GetUIpointer()->SetIgnoreCmdNotFound(true);
212 }
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
void SetRunIDCounter(G4int i)
virtual void Initialize()
void G4MTRunManager::InitializeEventLoop ( G4int  n_event,
const char *  macroFile = 0,
G4int  n_select = -1 
)
virtual

Reimplemented from G4RunManager.

Definition at line 265 of file G4MTRunManager.cc.

References CreateAndStartWorkers(), eventModulo, eventModuloDef, G4RunManager::fakeRun, G4TemplateRNGHelper< T >::Fill(), CLHEP::HepRandomEngine::flatArray(), G4Exception(), G4TemplateRNGHelper< T >::GetInstance(), InitializeSeeds(), int(), JustWarning, G4RunManager::msgText, G4RunManager::n_select_msg, nSeedsFilled, nSeedsMax, nSeedsPerEvent, nSeedsUsed, G4RunManager::numberOfEventProcessed, numberOfEventToBeProcessed, PrepareCommandsStack(), randDbl, G4RunManager::selectMacro, G4MTRunManagerKernel::SetUpDecayChannels(), G4Timer::Start(), G4RunManager::timer, G4RunManager::userWorkerThreadInitialization, G4RunManager::verboseLevel, and WaitForReadyWorkers().

266 {
267  MTkernel->SetUpDecayChannels();
268  numberOfEventToBeProcessed = n_event;
270 
271  if(!fakeRun)
272  {
273  nSeedsUsed = 0;
274  nSeedsFilled = 0;
275 
276  if(verboseLevel>0)
277  { timer->Start(); }
278 
279  n_select_msg = n_select;
280  if(macroFile!=0)
281  {
282  if(n_select_msg<0) n_select_msg = n_event;
283  msgText = "/control/execute ";
284  msgText += macroFile;
285  selectMacro = macroFile;
286  }
287  else
288  {
289  n_select_msg = -1;
290  selectMacro = "";
291  }
292 
293  //initialize seeds
294  //If user did not implement InitializeSeeds,
295  // use default: nSeedsPerEvent seeds per event
296  if( eventModuloDef > 0 )
297  {
300  {
302  if(eventModulo<1) eventModulo =1;
304  msgd << "Event modulo is reduced to " << eventModulo
305  << " to distribute events to all threads.";
306  G4Exception("G4MTRunManager::InitializeEventLoop()",
307  "Run10035", JustWarning, msgd);
308  }
309  }
310  else
311  {
312  eventModulo = int(std::sqrt(double(numberOfEventToBeProcessed/nworkers)));
313  if(eventModulo<1) eventModulo =1;
314  }
315  if ( InitializeSeeds(n_event) == false && n_event>0 )
316  {
318  nSeedsFilled = n_event;
319  // Generates up to nSeedsMax seed pairs only.
321  masterRNGEngine->flatArray(nSeedsPerEvent*nSeedsFilled,randDbl);
322  helper->Fill(randDbl,nSeedsFilled,n_event,nSeedsPerEvent);
323  }
324  }
325 
326  //Now initialize workers. Check if user defined a WorkerThreadInitialization
329 
330  //Prepare UI commands for threads
332 
333  //Start worker threads
335 
336  // We need a barrier here. Wait for workers to start event loop.
337  //This will return only when all workers have started processing events.
339 }
G4Timer * timer
static G4TemplateRNGHelper * GetInstance()
Definition: G4RNGHelper.hh:52
virtual void PrepareCommandsStack()
G4int n_select_msg
void Fill(double *dbl, int nev, int nev_tot, int nrpe)
Definition: G4RNGHelper.hh:95
G4int numberOfEventProcessed
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
virtual G4bool InitializeSeeds(G4int)
G4String msgText
virtual void WaitForReadyWorkers()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4String selectMacro
G4int numberOfEventToBeProcessed
void Start()
virtual void flatArray(const int size, double *vect)=0
G4int verboseLevel
virtual void CreateAndStartWorkers()
void G4MTRunManager::InitializePhysics ( )
virtual

Reimplemented from G4RunManager.

Definition at line 523 of file G4MTRunManager.cc.

References G4CascadeInterface::Initialize(), and G4RunManager::InitializePhysics().

524 {
526  //BERTINI, this is needed to create pseudo-particles, to be removed
528 }
virtual void InitializePhysics()
virtual G4bool G4MTRunManager::InitializeSeeds ( G4int  )
inlineprotectedvirtual

Definition at line 90 of file G4MTRunManager.hh.

Referenced by InitializeEventLoop().

90 { return false; };
void G4MTRunManager::MergeRun ( const G4Run localRun)

Definition at line 452 of file G4MTRunManager.cc.

References G4RunManager::currentRun, and G4Run::Merge().

Referenced by G4WorkerRunManager::MergePartialResults().

453 {
454  G4AutoLock l(&runMergerMutex);
455  if(currentRun) currentRun->Merge(localRun);
456 }
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4Run * currentRun
void G4MTRunManager::MergeScores ( const G4ScoringManager localScoringManager)

Definition at line 446 of file G4MTRunManager.cc.

References G4ScoringManager::Merge().

Referenced by G4WorkerRunManager::MergePartialResults().

447 {
448  G4AutoLock l(&scorerMergerMutex);
449  if(masterScM) masterScM->Merge(localScoringManager);
450 }
void Merge(const G4ScoringManager *scMan)
void G4MTRunManager::NewActionRequest ( G4MTRunManager::WorkerActionRequest  newRequest)
protectedvirtual

Reimplemented in tbbMasterRunManager.

Definition at line 800 of file G4MTRunManager.cc.

References G4CONDITIONWAIT, G4CONDTIONBROADCAST, nextActionRequest, and G4TemplateAutoLock< M, L, U >::unlock().

Referenced by CreateAndStartWorkers(), and TerminateWorkers().

801 {
802  //Wait for all workers to be ready to accept a new action request
803  while (true)
804  {
805 #ifndef WIN32
806  G4AutoLock l(&numberOfReadyWorkersForNewActionMutex);
807 #else
808  EnterCriticalSection( &cs3 );
809 #endif
810  //Check the number of workers that are ready for next action
811  G4int activethreads = threads.size();
812  if ( numberOfReadyWorkersForNewAction == activethreads )
813  {
814  //Ok, exit the loop
815  break;
816  }
817  //Wait for the number of workers ready for new action to change
818 #ifdef WIN32
819  G4CONDITIONWAIT(&numberOfReadyWorkersForNewActionChangedCondition,
820  &cs3);
821  LeaveCriticalSection( &cs3 );
822 #else
823  G4CONDITIONWAIT(&numberOfReadyWorkersForNewActionChangedCondition,
824  &numberOfReadyWorkersForNewActionMutex);
825 #endif
826  }
827  //Now set the new action to the shared resource
828  G4AutoLock l(&nextActionRequestMutex);
829  nextActionRequest = newRequest;
830  l.unlock();
831  //Reset counter of workers ready-for-new-action in preparation of next call
832  G4AutoLock l2(&numberOfReadyWorkersForNewActionMutex);
833  numberOfReadyWorkersForNewAction = 0;
834  //l2.unlock(); //<----- This thread needs to have control on mutex associated
835  //to condition variable (report from valgrind --tool=drd)
836  //see: http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Fapis%2Fusers_73.htm
837  //Now signal all workers that there is a new action to be performed
838  G4CONDTIONBROADCAST(&requestChangeActionForWorker);
839 }
WorkerActionRequest nextActionRequest
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:173
int G4int
Definition: G4Types.hh:78
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:172
void G4MTRunManager::PrepareCommandsStack ( )
protectedvirtual

Definition at line 227 of file G4MTRunManager.cc.

References G4UImanager::GetCommandStack(), and G4UImanager::GetUIpointer().

Referenced by InitializeEventLoop().

227  {
228  G4AutoLock l(&cmdHandlingMutex);
229  uiCmdsForWorkers.clear();
230  std::vector<G4String>* cmdCopy = G4UImanager::GetUIpointer()->GetCommandStack();
231  for ( std::vector<G4String>::const_iterator it = cmdCopy->begin() ;
232  it != cmdCopy->end(); ++it )
233  uiCmdsForWorkers.push_back(*it);
234  cmdCopy->clear();
235  delete cmdCopy;
236 }
std::vector< G4String > * GetCommandStack()
Definition: G4UImanager.cc:682
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
void G4MTRunManager::ProcessOneEvent ( G4int  i_event)
virtual

Reimplemented from G4RunManager.

Definition at line 218 of file G4MTRunManager.cc.

219 {
220  //Nothing to do
221 }
void G4MTRunManager::RefillSeeds ( )
protected

Definition at line 341 of file G4MTRunManager.cc.

References CLHEP::HepRandomEngine::flatArray(), G4TemplateRNGHelper< T >::GetInstance(), nSeedsFilled, nSeedsMax, nSeedsPerEvent, numberOfEventToBeProcessed, randDbl, and G4TemplateRNGHelper< T >::Refill().

Referenced by SetUpAnEvent(), and SetUpNEvents().

342 {
345  // Generates up to nSeedsMax seed pairs only.
346  if(nFill>nSeedsMax) nFill=nSeedsMax;
347  masterRNGEngine->flatArray(nSeedsPerEvent*nFill,randDbl);
348  helper->Refill(randDbl,nFill);
349  nSeedsFilled += nFill;
350 //G4cout<<"helper->Refill() for "<<nFill<<" events."<<G4endl;
351 }
static G4TemplateRNGHelper * GetInstance()
Definition: G4RNGHelper.hh:52
int G4int
Definition: G4Types.hh:78
void Refill(double *dbl, int nev)
Definition: G4RNGHelper.hh:106
G4int numberOfEventToBeProcessed
virtual void flatArray(const int size, double *vect)=0
void G4MTRunManager::RunTermination ( )
virtual

Reimplemented from G4RunManager.

Reimplemented in tbbMasterRunManager.

Definition at line 353 of file G4MTRunManager.cc.

References G4RunManager::RunTermination(), and WaitForEndEventLoopWorkers().

Referenced by tbbMasterRunManager::RunTermination().

354 {
355  //Wait for all worker threads to have finished the run
356  //i.e. wait for them to return from RunTermination()
357  //This guarantee that userrunaction for workers has been called
358 
359  // Wait now for all threads to finish event-loop
361  //Now call base-class methof
363 }
virtual void RunTermination()
virtual void WaitForEndEventLoopWorkers()
void G4MTRunManager::SetEventModulo ( G4int  i = 1)
inline

Definition at line 216 of file G4MTRunManager.hh.

References eventModuloDef.

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

Definition at line 179 of file G4MTRunManager.cc.

References G4Exception(), JustWarning, and n.

Referenced by main().

180 {
181  if ( threads.size() != 0 )
182  {
184  msg << "Number of threads cannot be changed at this moment \n"
185  << "(old threads are still alive). Method ignored.";
186  G4Exception("G4MTRunManager::SetNumberOfThreads(G4int)",
187  "Run0035", JustWarning, msg);
188  }
189  else if ( forcedNwokers > 0 )
190  {
192  msg << "Number of threads is forced to " << forcedNwokers
193  << " by G4FORCENUMBEROFWORKERS shell variable.\n"
194  << "Method ignored.";
195  G4Exception("G4MTRunManager::SetNumberOfThreads(G4int)",
196  "Run0035", JustWarning, msg);
197  }
198  else
199  {
200  nworkers = n;
201  }
202 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
const G4int n
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool G4MTRunManager::SetUpAnEvent ( G4Event evt,
long &  s1,
long &  s2,
long &  s3 
)
virtual

Definition at line 458 of file G4MTRunManager.cc.

References G4TemplateRNGHelper< T >::GetInstance(), G4TemplateRNGHelper< T >::GetSeed(), nSeedsFilled, nSeedsPerEvent, nSeedsUsed, G4RunManager::numberOfEventProcessed, numberOfEventToBeProcessed, RefillSeeds(), and G4Event::SetEventID().

Referenced by G4WorkerRunManager::GenerateEvent().

459 {
460  G4AutoLock l(&setUpEventMutex);
462  {
465  G4int idx_rndm = nSeedsPerEvent*nSeedsUsed;
466  s1 = helper->GetSeed(idx_rndm);
467  s2 = helper->GetSeed(idx_rndm+1);
468  if(nSeedsPerEvent==3) s3 = helper->GetSeed(idx_rndm+2);
470  nSeedsUsed++;
471  if(nSeedsUsed==nSeedsFilled) RefillSeeds();
472  return true;
473  }
474  return false;
475 }
static G4TemplateRNGHelper * GetInstance()
Definition: G4RNGHelper.hh:52
G4int numberOfEventProcessed
virtual const T GetSeed(const G4int &sdId)
Definition: G4RNGHelper.hh:77
int G4int
Definition: G4Types.hh:78
G4int numberOfEventToBeProcessed
void SetEventID(G4int i)
Definition: G4Event.hh:114
G4int G4MTRunManager::SetUpNEvents ( G4Event evt,
G4SeedsQueue seedsQueue 
)
virtual

Definition at line 477 of file G4MTRunManager.cc.

References eventModulo, G4TemplateRNGHelper< T >::GetInstance(), G4TemplateRNGHelper< T >::GetSeed(), nSeedsFilled, nSeedsPerEvent, nSeedsUsed, G4RunManager::numberOfEventProcessed, numberOfEventToBeProcessed, RefillSeeds(), G4RunManager::runAborted, and G4Event::SetEventID().

Referenced by G4WorkerRunManager::GenerateEvent().

478 {
479  G4AutoLock l(&setUpEventMutex);
481  {
482  G4int nev = eventModulo;
487  for(int i=0;i<nev;i++)
488  {
489  seedsQueue->push(helper->GetSeed(nSeedsPerEvent*nSeedsUsed));
490  seedsQueue->push(helper->GetSeed(nSeedsPerEvent*nSeedsUsed+1));
491  if(nSeedsPerEvent==3)
492  seedsQueue->push(helper->GetSeed(nSeedsPerEvent*nSeedsUsed+2));
493  nSeedsUsed++;
494  if(nSeedsUsed==nSeedsFilled) RefillSeeds();
495  }
496  numberOfEventProcessed += nev;
497  return nev;
498  }
499  return 0;
500 }
static G4TemplateRNGHelper * GetInstance()
Definition: G4RNGHelper.hh:52
G4int numberOfEventProcessed
virtual const T GetSeed(const G4int &sdId)
Definition: G4RNGHelper.hh:77
int G4int
Definition: G4Types.hh:78
G4bool runAborted
G4int numberOfEventToBeProcessed
void SetEventID(G4int i)
Definition: G4Event.hh:114
void G4MTRunManager::SetUserAction ( G4UserRunAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 410 of file G4MTRunManager.cc.

References G4UserRunAction::SetMaster(), and G4RunManager::SetUserAction().

Referenced by G4TheMTRayTracer::RestoreUserActions(), and G4TheMTRayTracer::StoreUserActions().

411 {
412  G4RunManager::SetUserAction(userAction);
413  userAction->SetMaster();
414 }
void SetMaster(G4bool val=true)
virtual void SetUserAction(G4UserRunAction *userAction)
void G4MTRunManager::SetUserAction ( G4VUserPrimaryGeneratorAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 416 of file G4MTRunManager.cc.

References FatalException, and G4Exception().

417 {
418  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
419  "For multi-threaded version, define G4VUserPrimaryGeneratorAction in G4VUserActionInitialization.");
420 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void G4MTRunManager::SetUserAction ( G4UserEventAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 422 of file G4MTRunManager.cc.

References FatalException, and G4Exception().

423 {
424  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
425  "For multi-threaded version, define G4UserEventAction in G4VUserActionInitialization.");
426 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void G4MTRunManager::SetUserAction ( G4UserStackingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 428 of file G4MTRunManager.cc.

References FatalException, and G4Exception().

429 {
430  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
431  "For multi-threaded version, define G4UserStackingAction in G4VUserActionInitialization.");
432 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void G4MTRunManager::SetUserAction ( G4UserTrackingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 434 of file G4MTRunManager.cc.

References FatalException, and G4Exception().

435 {
436  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
437  "For multi-threaded version, define G4UserTrackingAction in G4VUserActionInitialization.");
438 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void G4MTRunManager::SetUserAction ( G4UserSteppingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 440 of file G4MTRunManager.cc.

References FatalException, and G4Exception().

441 {
442  G4Exception("G4MTRunManager::SetUserAction()", "Run3011", FatalException,
443  "For multi-threaded version, define G4UserSteppingAction in G4VUserActionInitialization.");
444 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void G4MTRunManager::SetUserInitialization ( G4VUserPhysicsList userPL)
virtual

Reimplemented from G4RunManager.

Definition at line 399 of file G4MTRunManager.cc.

References G4RunManager::SetUserInitialization().

Referenced by main(), G4TheMTRayTracer::RestoreUserActions(), and G4TheMTRayTracer::StoreUserActions().

400 {
402  //Needed for MT, to be moved in kernel
403 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void G4MTRunManager::SetUserInitialization ( G4VUserDetectorConstruction userDC)
virtual

Reimplemented from G4RunManager.

Definition at line 405 of file G4MTRunManager.cc.

References G4RunManager::SetUserInitialization().

406 {
408 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void G4MTRunManager::SetUserInitialization ( G4UserWorkerInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 383 of file G4MTRunManager.cc.

References G4RunManager::userWorkerInitialization.

384 {
385  userWorkerInitialization = userInit;
386 }
G4UserWorkerInitialization * userWorkerInitialization
void G4MTRunManager::SetUserInitialization ( G4UserWorkerThreadInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 388 of file G4MTRunManager.cc.

References G4RunManager::userWorkerThreadInitialization.

389 {
391 }
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
void G4MTRunManager::SetUserInitialization ( G4VUserActionInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 393 of file G4MTRunManager.cc.

References G4VUserActionInitialization::BuildForMaster(), and G4RunManager::userActionInitialization.

394 {
395  userActionInitialization = userInit;
397 }
G4VUserActionInitialization * userActionInitialization
void G4MTRunManager::StoreRNGStatus ( const G4String filenamePrefix)
protectedvirtual

Reimplemented from G4RunManager.

Definition at line 172 of file G4MTRunManager.cc.

References G4RunManager::randomNumberStatusDir.

173 {
174  std::ostringstream os;
175  os << randomNumberStatusDir << "G4Master_"<<fn <<".rndm";
176  G4Random::saveEngineStatus(os.str().c_str());
177 }
G4String randomNumberStatusDir
void G4MTRunManager::TerminateEventLoop ( )
virtual

Reimplemented from G4RunManager.

Definition at line 214 of file G4MTRunManager.cc.

215 {
216  //Nothing to do
217 }
void G4MTRunManager::TerminateOneEvent ( )
virtual

Reimplemented from G4RunManager.

Definition at line 222 of file G4MTRunManager.cc.

223 {
224  //Nothing to do
225 }
void G4MTRunManager::TerminateWorkers ( )
protectedvirtual

Reimplemented in tbbMasterRunManager.

Definition at line 502 of file G4MTRunManager.cc.

References ENDWORKER, G4UserWorkerThreadInitialization::JoinWorker(), NewActionRequest(), and G4RunManager::userWorkerThreadInitialization.

Referenced by ~G4MTRunManager().

503 {
505  //Now join threads.
506 #ifdef G4MULTITHREADED //protect here to prevent warning in compilation
507  while ( ! threads.empty() )
508  {
509  G4Thread* t = * ( threads.begin() );
510  threads.pop_front();
512  //G4THREADJOIN(*t);
513  delete t;
514  }
515 #endif
516  threads.clear();
517 }
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4int G4Thread
Definition: G4Threading.hh:157
virtual void NewActionRequest(WorkerActionRequest newRequest)
void G4MTRunManager::ThisWorkerEndEventLoop ( )
virtual

Reimplemented in tbbMasterRunManager.

Definition at line 780 of file G4MTRunManager.cc.

References G4CONDITIONWAIT, and G4CONDTIONBROADCAST.

Referenced by G4WorkerRunManager::RunTermination().

781 {
782  //Increament number of workers in end of evnet loop by 1
783 #ifndef WIN32
784  G4AutoLock l(&numberOfEndOfEventLoopWorkersMutex);
785 #else
786  EnterCriticalSection( &cs2 );
787 #endif
788  ++numberOfEndOfEventLoopWorkers;
789  //Signale this number has changed
790  G4CONDTIONBROADCAST(&numWorkersEndEventLoopChangedCondition);
791  //Wait for condition to exit eventloop
792 #ifdef WIN32
793  G4CONDITIONWAIT(&endEventLoopCondition,&cs2);
794  LeaveCriticalSection( &cs2 );
795 #else
796  G4CONDITIONWAIT(&endEventLoopCondition,&numberOfEndOfEventLoopWorkersMutex);
797 #endif
798 }
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:173
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:172
void G4MTRunManager::ThisWorkerReady ( )
virtual

Reimplemented in tbbMasterRunManager.

Definition at line 718 of file G4MTRunManager.cc.

References G4CONDITIONWAIT, and G4CONDTIONBROADCAST.

Referenced by G4WorkerRunManager::RunInitialization().

719 {
720  //Increament number of active worker by 1
721 #ifndef WIN32
722  G4AutoLock lockLoop(&numberOfReadyWorkersMutex);
723 #else
724  EnterCriticalSection( &cs1 );
725 #endif
726  ++numberOfReadyWorkers;
727  //Signal the number of workers has changed
728  G4CONDTIONBROADCAST(&numWorkersBeginEventLoopChangeCondition);
729  //Wait for condition to start eventloop
730 #ifdef WIN32
731  G4CONDITIONWAIT(&beginEventLoopCondition,&cs1);
732  LeaveCriticalSection( &cs1 );
733 #else
734  G4CONDITIONWAIT(&beginEventLoopCondition,&numberOfReadyWorkersMutex);
735 #endif
736  //Protects access to shared resource, guarantees we do not call this method
737  //while someone else is modifying its content (e.g. creating a new particle)
738  //G4PDefManager& pdm = const_cast<G4PDefManager&>(G4ParticleDefinition::GetSubInstanceManager());
739  //pdm.Lock();
740  //pdm.NewSubInstances();
741  //pdm.UnLock();
742  //const_cast<G4PDefManager&>(G4ParticleDefinition::GetSubInstanceManager()).NewSubInstances();
743  // I believe this is not necessary and safe to remove (Makoto)
744  //G4ParticleTable::GetParticleTable()->WorkerG4ParticleTable();
745 }
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:173
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:172
G4MTRunManager::WorkerActionRequest G4MTRunManager::ThisWorkerWaitForNextAction ( )
virtual

Reimplemented in tbbMasterRunManager.

Definition at line 841 of file G4MTRunManager.cc.

References G4CONDITIONWAIT, G4CONDTIONBROADCAST, and nextActionRequest.

Referenced by G4MTRunManagerKernel::StartThread().

842 {
843  //This worker is ready to receive a new action request,
844  //increment counter by 1
845  #ifndef WIN32
846  G4AutoLock l(&numberOfReadyWorkersForNewActionMutex);
847 #else
848  EnterCriticalSection( &cs3 );
849 #endif
850  ++numberOfReadyWorkersForNewAction;
851  //Singal the sahred resource has changed to the master
852  G4CONDTIONBROADCAST(&numberOfReadyWorkersForNewActionChangedCondition);
853  //Wait for condition that a new aciton is ready
854 #ifdef WIN32
855  G4CONDITIONWAIT(&requestChangeActionForWorker,&cs3);
856  LeaveCriticalSection( &cs3 );
857 #else
858  G4CONDITIONWAIT(&requestChangeActionForWorker,&numberOfReadyWorkersForNewActionMutex);
859 #endif
860  //Ok, if I am here it means that a new action has been requested by the master
861  //reads it value that is now read-only, so no mutex is needed, but you never know...
862  G4AutoLock l2(&nextActionRequestMutex);
864  return result;
865 }
WorkerActionRequest nextActionRequest
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:173
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:172
void G4MTRunManager::WaitForEndEventLoopWorkers ( )
protectedvirtual

Reimplemented in tbbMasterRunManager.

Definition at line 748 of file G4MTRunManager.cc.

References G4CONDITIONWAIT, and G4CONDTIONBROADCAST.

Referenced by RunTermination().

749 {
750  while (true)
751  {
752 #ifndef WIN32
753  G4AutoLock l(&numberOfEndOfEventLoopWorkersMutex);
754 #else
755  EnterCriticalSection( &cs2 );
756 #endif
757  G4int activethreads = threads.size();
758  if ( numberOfEndOfEventLoopWorkers == activethreads )
759  {
760  break;
761  }
762 #ifdef WIN32
763  G4CONDITIONWAIT(&numWorkersEndEventLoopChangedCondition,
764  &cs2);
765  LeaveCriticalSection( &cs2 );
766 #else
767  G4CONDITIONWAIT(&numWorkersEndEventLoopChangedCondition,
768  &numberOfEndOfEventLoopWorkersMutex);
769 #endif
770  }
771  //Now number of workers that reached end of event loop is as expected
772  //Reset number of workers in ready for work state so a new run can start
773  G4AutoLock l(&numberOfReadyWorkersMutex);
774  numberOfReadyWorkers = 0;
775  //Signal workers they can end event-loop
776  G4AutoLock l2(&numberOfEndOfEventLoopWorkersMutex);
777  G4CONDTIONBROADCAST(&endEventLoopCondition);
778 }
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:173
int G4int
Definition: G4Types.hh:78
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:172
void G4MTRunManager::WaitForReadyWorkers ( )
protectedvirtual

Reimplemented in tbbMasterRunManager.

Definition at line 662 of file G4MTRunManager.cc.

References G4CONDITIONWAIT, and G4CONDTIONBROADCAST.

Referenced by InitializeEventLoop().

663 {
664  while (true) //begin barrier
665  {
666 #ifndef WIN32
667  G4AutoLock lockLoop(&numberOfReadyWorkersMutex);
668 #else
669  EnterCriticalSection( &cs1 );
670 #endif
671  //Check number of workers ready to begin
672  G4int activethreads = threads.size();
673  if (numberOfReadyWorkers == activethreads )
674  {
675  //Ok, interrupt the loop
676  break;
677  }
678  //Wait for the number of workers to be changed
679 #ifdef WIN32
680  G4CONDITIONWAIT(&numWorkersBeginEventLoopChangeCondition,
681  &cs1);
682  LeaveCriticalSection( &cs1 );
683 #else
684  G4CONDITIONWAIT(&numWorkersBeginEventLoopChangeCondition,
685  &numberOfReadyWorkersMutex);
686 #endif
687  }
688  //Now number of workers is as expected.
689 ////// static G4bool createIsomerOnlyOnce = false;
690 ////// if(!createIsomerOnlyOnce)
691 ////// {
692 ////// createIsomerOnlyOnce = true;
693 ////// G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon();
694 ////// if(gion)
695 ////// {
696 ////// ////G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
697 ////// G4int gionId = gion->GetParticleDefinitionID();
698 ////// G4ParticleTable::G4PTblDicIterator* pItr = G4ParticleTable::GetParticleTable()->GetIterator();
699 ////// pItr->reset(false);
700 ////// while( (*pItr)() )
701 ////// {
702 ////// G4ParticleDefinition* particle = pItr->value();
703 ////// if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
704 ////// }
705 ////// }
706 ////// }
707 
708  //Prepare to wait for workers to end eventloop
709  //Reset number of workers in "EndOfEventLoop"
710  G4AutoLock l(&numberOfEndOfEventLoopWorkersMutex);
711  numberOfEndOfEventLoopWorkers = 0;
712 
713  //signal workers they can start the event-loop
714  G4AutoLock l2(&numberOfReadyWorkersMutex);
715  G4CONDTIONBROADCAST(&beginEventLoopCondition);
716 }
#define G4CONDTIONBROADCAST(cond)
Definition: G4Threading.hh:173
int G4int
Definition: G4Types.hh:78
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:172

Field Documentation

G4int G4MTRunManager::eventModulo
protected

Definition at line 206 of file G4MTRunManager.hh.

Referenced by InitializeEventLoop(), and SetUpNEvents().

G4int G4MTRunManager::eventModuloDef
protected

Definition at line 205 of file G4MTRunManager.hh.

Referenced by GetEventModulo(), InitializeEventLoop(), and SetEventModulo().

WorkerActionRequest G4MTRunManager::nextActionRequest
protected

Definition at line 201 of file G4MTRunManager.hh.

Referenced by NewActionRequest(), and ThisWorkerWaitForNextAction().

G4int G4MTRunManager::nSeedsFilled
protected

Definition at line 208 of file G4MTRunManager.hh.

Referenced by InitializeEventLoop(), RefillSeeds(), SetUpAnEvent(), and SetUpNEvents().

G4int G4MTRunManager::nSeedsMax
protected

Definition at line 209 of file G4MTRunManager.hh.

Referenced by G4MTRunManager(), InitializeEventLoop(), and RefillSeeds().

G4int G4MTRunManager::nSeedsPerEvent
protected
G4int G4MTRunManager::nSeedsUsed
protected

Definition at line 207 of file G4MTRunManager.hh.

Referenced by InitializeEventLoop(), SetUpAnEvent(), and SetUpNEvents().

G4int G4MTRunManager::numberOfEventToBeProcessed
protected
double* G4MTRunManager::randDbl
protected

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