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