126 "Another instance of a G4MTRunManager already exists.");
131#ifndef G4MULTITHREADED
133 msg <<
"Geant4 code is compiled without multi-threading support"
134 <<
"(-DG4MULTITHREADED is set to off).\n";
135 msg <<
"G4MTRunManager can only be used in multi-threaded applications.";
140 if(numberOfStaticAllocators > 0)
144 <<
"There are " << numberOfStaticAllocators
145 <<
" static G4Allocator objects detected.\n"
146 <<
"In multi-threaded mode, all G4Allocator objects must be dynamically "
159 masterRNGEngine = G4Random::getTheEngine();
163 char* env = std::getenv(
"G4FORCENUMBEROFTHREADS");
167 if(envS ==
"MAX" || envS ==
"max")
173 std::istringstream is(env);
183 msg2 <<
"Environment variable G4FORCENUMBEROFTHREADS has an invalid "
185 << envS <<
">. It has to be an integer or a word \"max\".\n"
186 <<
"G4FORCENUMBEROFTHREADS is ignored.";
196 <<
" by Environment variable G4FORCENUMBEROFTHREADS." <<
G4endl; }
215 std::ostringstream os;
217 G4Random::saveEngineStatus(os.str().c_str());
228 G4cerr <<
"Warning from G4RunManager::rndmSaveThisRun():"
229 <<
" Random number status was not stored prior to this run."
230 <<
G4endl <<
"/random/setSavingFlag command must be issued. "
231 <<
"Command ignored." <<
G4endl;
237 std::ostringstream os;
238 os <<
"run" << runNumber <<
".rndm" <<
'\0';
242 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
244 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
249 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
256 G4Exception(
"G4MTRunManager::rndmSaveThisEvent",
"RUN_RNDM001",
263 if(threads.size() != 0)
266 msg <<
"Number of threads cannot be changed at this moment \n"
267 <<
"(old threads are still alive). Method ignored.";
268 G4Exception(
"G4MTRunManager::SetNumberOfThreads(G4int)",
"Run0112",
275 <<
" by G4FORCENUMBEROFTHREADS shell variable.\n"
276 <<
"Method ignored.";
277 G4Exception(
"G4MTRunManager::SetNumberOfThreads(G4int)",
"Run0113",
313 uiCmdsForWorkers.clear();
314 std::vector<G4String>* cmdCopy =
316 for(
auto it = cmdCopy->cbegin(); it != cmdCopy->cend(); ++it)
317 uiCmdsForWorkers.push_back(*it);
326 return uiCmdsForWorkers;
336 if(threads.size() == 0)
341 std::stringstream msg;
342 msg <<
"--> G4MTRunManager::CreateAndStartWorkers() --> "
343 <<
"Initializing workers...";
345 std::stringstream ss;
347 ss << std::setw(
G4int(msg.str().length())) <<
"";
363 threads.push_back(thread);
415 msgd <<
"Event modulo is reduced to " <<
eventModulo
416 <<
" to distribute events to all threads.";
417 G4Exception(
"G4MTRunManager::InitializeEventLoop()",
"Run10035",
445 <<
"> of seedOncePerCommunication is invalid. It is reset to 0.";
446 G4Exception(
"G4MTRunManager::InitializeEventLoop()",
"Run10036",
529 for(
G4int iWorld = 0; iWorld < nWorlds; ++iWorld)
584 "For multi-threaded version, define G4VUserPrimaryGeneratorAction in "
585 "G4VUserActionInitialization.");
592 "For multi-threaded version, define G4UserEventAction in "
593 "G4VUserActionInitialization.");
600 "For multi-threaded version, define G4UserStackingAction in "
601 "G4VUserActionInitialization.");
608 "For multi-threaded version, define G4UserTrackingAction in "
609 "G4VUserActionInitialization.");
616 "For multi-threaded version, define G4UserSteppingAction in "
617 "G4VUserActionInitialization.");
624 if(
masterScM !=
nullptr && localScoringManager !=
nullptr)
632 if(
currentRun !=
nullptr && localRun !=
nullptr)
648 s1 = helper->
GetSeed(idx_rndm);
649 s2 = helper->
GetSeed(idx_rndm + 1);
651 s3 = helper->
GetSeed(idx_rndm + 2);
681 for(
G4int i = 0; i < nevRnd; ++i)
708#ifdef G4MULTITHREADED
709 while(!threads.empty())
734 G4cerr <<
"Run is not in progress. AbortRun() ignored." <<
G4endl;
812 "Pin affinity must be >0 or <0.");
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::queue< G4long > G4SeedsQueue
#define G4MUTEX_INITIALIZER
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
virtual void flatArray(const int size, double *vect)=0
virtual void WaitForReadyWorkers()
void SetActiveThreads(unsigned int val)
void BroadcastAbortRun(G4bool softAbort)
void SetUpDecayChannels()
static G4int SeedOncePerCommunication()
virtual void SetUserAction(G4UserRunAction *userAction)
virtual WorkerActionRequest ThisWorkerWaitForNextAction()
static void SetSeedOncePerCommunication(G4int val)
virtual void AbortEvent()
G4int numberOfEventToBeProcessed
virtual void ProcessOneEvent(G4int i_event)
virtual void TerminateOneEvent()
virtual void rndmSaveThisEvent()
virtual void SetUserInitialization(G4VUserPhysicsList *userPL)
virtual G4bool InitializeSeeds(G4int)
virtual void WaitForReadyWorkers()
G4MTBarrier beginOfEventLoopBarrier
virtual void CreateAndStartWorkers()
virtual void SetNumberOfThreads(G4int n)
virtual ~G4MTRunManager()
virtual void ThisWorkerProcessCommandsStackDone()
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
virtual G4bool SetUpAnEvent(G4Event *, long &s1, long &s2, long &s3, G4bool reseedRequired=true)
static void addWorld(G4int counter, G4VPhysicalVolume *w)
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void PrepareCommandsStack()
static G4ScoringManager * GetMasterScoringManager()
static G4MTRUN_DLL G4ScoringManager * masterScM
virtual void Initialize()
static G4MTRUN_DLL G4MTRunManager * fMasterRM
virtual void ThisWorkerReady()
static G4MTRunManagerKernel * GetMTMasterRunManagerKernel()
static G4int seedOncePerCommunication
virtual void RunTermination()
static G4MTRUN_DLL masterWorlds_t masterWorlds
virtual size_t GetNumberActiveThreads() const
virtual void ConstructScoringWorlds()
static G4MTRunManager * GetMasterRunManager()
virtual void StoreRNGStatus(const G4String &filenamePrefix)
virtual void WaitForEndEventLoopWorkers()
WorkerActionRequest nextActionRequest
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
virtual void AbortRun(G4bool softAbort=false)
virtual void RefillSeeds()
virtual void rndmSaveThisRun()
static G4ThreadId masterThreadId
G4MTBarrier processUIBarrier
static G4ThreadId GetMasterThreadId()
void MergeRun(const G4Run *localRun)
G4MTBarrier endOfEventLoopBarrier
G4MTBarrier nextActionRequestBarrier
virtual void TerminateWorkers()
static masterWorlds_t & GetMasterWorlds()
virtual void RequestWorkersProcessCommandsStack()
static G4RunManagerKernel * GetMasterRunManagerKernel()
void MergeScores(const G4ScoringManager *localScoringManager)
virtual void NewActionRequest(WorkerActionRequest newRequest)
void SetPinAffinity(G4int n=1)
std::vector< G4String > GetCommandStack()
virtual void ThisWorkerEndEventLoop()
G4int GetNumberOfStaticAllocators() const
G4UserWorkerInitialization * userWorkerInitialization
virtual void Initialize()
void SetRunIDCounter(G4int i)
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4int numberOfEventProcessed
G4RunManagerKernel * kernel
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
virtual void RunTermination()
G4VUserActionInitialization * userActionInitialization
G4String randomNumberStatusDir
virtual void TerminateEventLoop()
virtual void SetUserAction(G4UserRunAction *userAction)
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4bool storeRandomNumberStatus
virtual void ConstructScoringWorlds()
virtual void Merge(const G4Run *)
void Merge(const G4ScoringManager *scMan)
static G4ScoringManager * GetScoringManagerIfExist()
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
static G4TemplateRNGHelper< T > * GetInstance()
virtual const T GetSeed(const G4int &sdId)
void Fill(G4double *dbl, G4int nev, G4int nev_tot, G4int nrpe)
void Refill(G4double *dbl, G4int nev)
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
std::size_t GetNoWorlds() const
std::vector< G4String > * GetCommandStack()
G4int ApplyCommand(const char *aCommand)
void SetMasterUIManager(G4bool val)
static G4UImanager * GetUIpointer()
virtual void SetMaster(G4bool val=true)
virtual void JoinWorker(G4Thread *aThread)
virtual G4Thread * CreateAndStartWorker(G4WorkerThread *workerThreadContext)
virtual void BuildForMaster() const
void SetNumberThreads(G4int numnberThreads)
void SetThreadId(G4int threadId)
G4int G4GetNumberOfCores()