78 nworkers(2),forcedNwokers(-1),pinAffinity(0),
81 eventModuloDef(0),eventModulo(1),
82 nSeedsUsed(0),nSeedsFilled(0),
83 nSeedsMax(10000),nSeedsPerEvent(2)
88 "Another instance of a G4MTRunManager already exists.");
92 #ifndef G4MULTITHREADED
94 msg <<
"Geant4 code is compiled without multi-threading support"
95 <<
"(-DG4MULTITHREADED is set to off).\n";
96 msg <<
"G4MTRunManager can only be used in multi-threaded applications.";
101 if(numberOfStaticAllocators>0)
104 msg1 <<
"There are " << numberOfStaticAllocators
105 <<
" static G4Allocator objects detected.\n"
106 <<
"In multi-threaded mode, all G4Allocator objects must be dynamicly instantiated.";
122 char* env = getenv(
"G4FORCENUMBEROFTHREADS");
126 if(envS==
"MAX"||envS==
"max")
130 std::istringstream is(env);
138 msg2 <<
"Environment variable G4FORCENUMBEROFTHREADS has an invalid value <"
139 << envS <<
">. It has to be an integer or a word \"max\".\n"
140 <<
"G4FORCENUMBEROFTHREADS is ignored.";
148 <<
" by Environment variable G4FORCENUMBEROFTHREADS." <<
G4endl;
165 std::ostringstream os;
167 G4Random::saveEngineStatus(os.str().c_str());
175 msg <<
"Number of threads cannot be changed at this moment \n"
176 <<
"(old threads are still alive). Method ignored.";
177 G4Exception(
"G4MTRunManager::SetNumberOfThreads(G4int)",
184 <<
" by G4FORCENUMBEROFTHREADS shell variable.\n"
185 <<
"Method ignored.";
186 G4Exception(
"G4MTRunManager::SetNumberOfThreads(G4int)",
222 for ( std::vector<G4String>::const_iterator it = cmdCopy->begin() ;
223 it != cmdCopy->end(); ++it )
295 msgd <<
"Event modulo is reduced to " <<
eventModulo
296 <<
" to distribute events to all threads.";
297 G4Exception(
"G4MTRunManager::InitializeEventLoop()",
323 <<
"> of seedOncePerCommunication is invalid. It is reset to 0." ;
324 G4Exception(
"G4MTRunManager::InitializeEventLoop()",
326 seedOncePerCommunication = 0;
397 std::vector<G4VPhysicalVolume*>::iterator itrW
399 for(
size_t iWorld=0;iWorld<nWorlds;iWorld++)
442 "For multi-threaded version, define G4VUserPrimaryGeneratorAction in G4VUserActionInitialization.");
448 "For multi-threaded version, define G4UserEventAction in G4VUserActionInitialization.");
454 "For multi-threaded version, define G4UserStackingAction in G4VUserActionInitialization.");
460 "For multi-threaded version, define G4UserTrackingAction in G4VUserActionInitialization.");
466 "For multi-threaded version, define G4UserSteppingAction in G4VUserActionInitialization.");
491 s1 = helper->
GetSeed(idx_rndm);
492 s2 = helper->
GetSeed(idx_rndm+1);
517 for(
int i=0;i<nevRnd;i++)
540 #ifdef G4MULTITHREADED //protect here to prevent warning in compilation
565 G4cerr <<
"Run is not in progress. AbortRun() ignored." <<
G4endl;
623 "Pin affinity must be >0 or <0.");
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void TerminateEventLoop()
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
std::vector< G4String > GetCommandStack()
virtual void PrepareCommandsStack()
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
std::queue< G4long > G4SeedsQueue
virtual void Merge(const G4Run *)
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
static G4int seedOncePerCommunication
std::vector< G4String > uiCmdsForWorkers
void SetUpDecayChannels()
G4int numberOfEventProcessed
static void addWorld(G4int counter, G4VPhysicalVolume *w)
WorkerActionRequest nextActionRequest
virtual void RunTermination()
std::ostringstream G4ExceptionDescription
virtual void ThisWorkerEndEventLoop()
void SetNumberOfThreads(G4int n)
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
G4VUserActionInitialization * userActionInitialization
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
virtual G4bool InitializeSeeds(G4int)
virtual void ConstructScoringWorlds()
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void BuildForMaster() const
virtual void RunTermination()
virtual const T GetSeed(const G4int &sdId)
void SetActiveThreads(unsigned int val)
virtual void WaitForReadyWorkers()
void SetThreadId(G4int threadId)
std::vector< G4String > * GetCommandStack()
virtual void SetUserAction(G4UserRunAction *userAction)
#define G4MUTEX_INITIALIZER
void Refill(G4double *dbl, G4int nev)
G4MTBarrier beginOfEventLoopBarrier
virtual void WaitForEndEventLoopWorkers()
G4MTRunManagerKernel * MTkernel
virtual void TerminateOneEvent()
static G4UImanager * GetUIpointer()
virtual void TerminateWorkers()
static G4StateManager * GetStateManager()
static G4RunManagerKernel * GetMasterRunManagerKernel()
void Fill(G4double *dbl, G4int nev, G4int nev_tot, G4int nrpe)
G4GLOB_DLL std::ostream G4cout
void MergeRun(const G4Run *localRun)
static masterWorlds_t masterWorlds
static G4ScoringManager * GetScoringManagerIfExist()
static G4ScoringManager * masterScM
G4UserWorkerInitialization * userWorkerInitialization
G4String randomNumberStatusDir
G4MTBarrier processUIBarrier
virtual void ProcessOneEvent(G4int i_event)
virtual void ConstructScoringWorlds()
virtual void WaitForReadyWorkers()
static G4MTRunManager * GetMasterRunManager()
G4int G4GetNumberOfCores()
void SetPinAffinity(G4int n=1)
virtual WorkerActionRequest ThisWorkerWaitForNextAction()
virtual void ThisWorkerProcessCommandsStackDone()
virtual void SetUserInitialization(G4VUserPhysicsList *userPL)
virtual void AbortRun(G4bool softAbort=false)
virtual void RequestWorkersProcessCommandsStack()
G4ApplicationState GetCurrentState() const
virtual void NewActionRequest(WorkerActionRequest newRequest)
virtual void SetMaster(G4bool val=true)
void Merge(const G4ScoringManager *scMan)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
static G4TransportationManager * GetTransportationManager()
virtual void Initialize()
G4MTBarrier endOfEventLoopBarrier
virtual void ThisWorkerReady()
virtual void AbortEvent()
void SetRunIDCounter(G4int i)
virtual G4bool SetUpAnEvent(G4Event *, long &s1, long &s2, long &s3, G4bool reseedRequired=true)
virtual G4Thread * CreateAndStartWorker(G4WorkerThread *workerThreadContext)
virtual ~G4MTRunManager()
static G4TemplateRNGHelper< T > * GetInstance()
virtual void Initialize()
size_t GetNoWorlds() const
G4int numberOfEventToBeProcessed
G4int GetNumberOfStaticAllocators() const
G4RunManagerKernel * kernel
void BroadcastAbortRun(G4bool softAbort)
static G4MTRunManagerKernel * GetMTMasterRunManagerKernel()
G4MTBarrier nextActionRequestBarrier
size_t GetNumberActiveThreads() const
virtual void JoinWorker(G4Thread *aThread)
void SetNumberThreads(G4int numnberThreads)
void MergeScores(const G4ScoringManager *localScoringManager)
CLHEP::HepRandomEngine * masterRNGEngine
void SetMasterUIManager(G4bool val)
virtual void StoreRNGStatus(const G4String &filenamePrefix)
G4GLOB_DLL std::ostream G4cerr
virtual void SetUserAction(G4UserRunAction *userAction)
virtual void CreateAndStartWorkers()
static G4MTRunManager * fMasterRM