124 "Another instance of a G4MTRunManager already exists.");
129#ifndef G4MULTITHREADED
131 msg <<
"Geant4 code is compiled without multi-threading support"
132 <<
"(-DG4MULTITHREADED is set to off).\n";
133 msg <<
"G4MTRunManager can only be used in multi-threaded applications.";
137 G4int numberOfStaticAllocators =
kernel->GetNumberOfStaticAllocators();
138 if (numberOfStaticAllocators > 0) {
140 msg1 <<
"There are " << numberOfStaticAllocators <<
" static G4Allocator objects detected.\n"
141 <<
"In multi-threaded mode, all G4Allocator objects must be dynamically "
157 char* env = std::getenv(
"G4FORCENUMBEROFTHREADS");
158 if (env !=
nullptr) {
160 if (envS ==
"MAX" || envS ==
"max") {
164 std::istringstream is(env);
172 msg2 <<
"Environment variable G4FORCENUMBEROFTHREADS has an invalid "
174 << envS <<
">. It has to be an integer or a word \"max\".\n"
175 <<
"G4FORCENUMBEROFTHREADS is ignored.";
183 <<
" by Environment variable G4FORCENUMBEROFTHREADS." <<
G4endl;
204 std::ostringstream os;
206 G4Random::saveEngineStatus(os.str().c_str());
215 G4cerr <<
"Warning from G4RunManager::rndmSaveThisRun():"
216 <<
" Random number status was not stored prior to this run." <<
G4endl
217 <<
"/random/setSavingFlag command must be issued. "
218 <<
"Command ignored." <<
G4endl;
224 std::ostringstream os;
225 os <<
"run" << runNumber <<
".rndm" <<
'\0';
230 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
238 "This method shall not be invoked !!");
246 msg <<
"Number of threads cannot be changed at this moment \n"
247 <<
"(old threads are still alive). Method ignored.";
253 <<
" by G4FORCENUMBEROFTHREADS shell variable.\n"
254 <<
"Method ignored.";
290 for (
const auto& it : *cmdCopy)
313 std::stringstream msg;
314 msg <<
"--> G4MTRunManager::CreateAndStartWorkers() --> "
315 <<
"Initializing workers...";
317 std::stringstream ss;
319 ss << std::setw(
G4int(msg.str().length())) <<
"";
320 G4cout <<
"\n" << ss.str() <<
"\n" << msg.str() <<
"\n" << ss.str() <<
"\n" <<
G4endl;
327 context->SetThreadId(nw);
352 if (macroFile !=
nullptr) {
372 msgd <<
"Event modulo is reduced to " <<
eventModulo
373 <<
" to distribute events to all threads.";
396 <<
"> of seedOncePerCommunication is invalid. It is reset to 0.";
472 for (
G4int iWorld = 0; iWorld < nWorlds; ++iWorld) {
514 if (userAction !=
nullptr) userAction->
SetMaster();
521 "For multi-threaded version, define G4VUserPrimaryGeneratorAction in "
522 "G4VUserActionInitialization.");
529 "For multi-threaded version, define G4UserEventAction in "
530 "G4VUserActionInitialization.");
537 "For multi-threaded version, define G4UserStackingAction in "
538 "G4VUserActionInitialization.");
545 "For multi-threaded version, define G4UserTrackingAction in "
546 "G4VUserActionInitialization.");
553 "For multi-threaded version, define G4UserSteppingAction in "
554 "G4VUserActionInitialization.");
561 if (
masterScM !=
nullptr && localScoringManager !=
nullptr)
masterScM->Merge(localScoringManager);
578 if (reseedRequired) {
581 s1 = helper->
GetSeed(idx_rndm);
582 s2 = helper->
GetSeed(idx_rndm + 1);
603 if (reseedRequired) {
607 for (
G4int i = 0; i < nevRnd; ++i) {
629#ifdef G4MULTITHREADED
647 MTkernel->BroadcastAbortRun(softAbort);
650 G4cerr <<
"Run is not in progress. AbortRun() ignored." <<
G4endl;
725 "Pin affinity must be >0 or <0.");
G4TemplateAutoLock< G4Mutex > G4AutoLock
Helper function for copying random state files in G4run.
G4bool G4CopyRandomState(const G4fs::path &source, const G4fs::path &dest, const G4String &callsite)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::queue< G4long > G4SeedsQueue
G4TemplateRNGHelper< G4long > G4RNGHelper
#define G4MUTEX_INITIALIZER
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
static G4int SeedOncePerCommunication()
virtual WorkerActionRequest ThisWorkerWaitForNextAction()
static void SetSeedOncePerCommunication(G4int val)
void AbortEvent() override
G4int numberOfEventToBeProcessed
void TerminateOneEvent() override
void SetUserAction(G4UserRunAction *userAction) override
G4MTRunManagerKernel * MTkernel
void RunTermination() override
void SetNumberOfThreads(G4int n) override
virtual G4bool InitializeSeeds(G4int)
virtual void WaitForReadyWorkers()
G4MTBarrier beginOfEventLoopBarrier
virtual void CreateAndStartWorkers()
virtual void ThisWorkerProcessCommandsStackDone()
~G4MTRunManager() override
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
CLHEP::HepRandomEngine * masterRNGEngine
static void addWorld(G4int counter, G4VPhysicalVolume *w)
virtual void PrepareCommandsStack()
static G4ScoringManager * GetMasterScoringManager()
static G4MTRUN_DLL G4ScoringManager * masterScM
static G4MTRUN_DLL G4MTRunManager * fMasterRM
virtual void ThisWorkerReady()
void Initialize() override
static G4MTRunManagerKernel * GetMTMasterRunManagerKernel()
std::vector< G4String > uiCmdsForWorkers
static G4int seedOncePerCommunication
void ProcessOneEvent(G4int i_event) override
virtual size_t GetNumberActiveThreads() const
static G4MTRunManager * GetMasterRunManager()
virtual void WaitForEndEventLoopWorkers()
void ConstructScoringWorlds() override
WorkerActionRequest nextActionRequest
void SetUserInitialization(G4VUserPhysicsList *userPL) override
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
virtual void RefillSeeds()
static G4ThreadId masterThreadId
G4MTBarrier processUIBarrier
static G4ThreadId GetMasterThreadId()
virtual void MergeRun(const G4Run *localRun)
G4MTBarrier endOfEventLoopBarrier
G4MTBarrier nextActionRequestBarrier
void AbortRun(G4bool softAbort=false) override
virtual void TerminateWorkers()
static masterWorlds_t & GetMasterWorlds()
virtual void RequestWorkersProcessCommandsStack()
void InitializeEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
static G4RunManagerKernel * GetMasterRunManagerKernel()
virtual void MergeScores(const G4ScoringManager *localScoringManager)
void rndmSaveThisRun() override
virtual void NewActionRequest(WorkerActionRequest newRequest)
void SetPinAffinity(G4int n=1)
void rndmSaveThisEvent() override
void StoreRNGStatus(const G4String &filenamePrefix) override
std::vector< G4String > GetCommandStack()
virtual G4bool SetUpAnEvent(G4Event *, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true)
virtual void ThisWorkerEndEventLoop()
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()
static G4ScoringManager * GetScoringManagerIfExist()
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
static G4TemplateRNGHelper< G4long > * 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::vector< G4String > * GetCommandStack()
void SetMasterUIManager(G4bool val)
void SetAlias(const char *aliasLine)
static G4UImanager * GetUIpointer()
virtual void SetMaster(G4bool val=true)
void SetNumberThreads(G4int numnberThreads)
G4int G4GetNumberOfCores()