121 "Another instance of a G4MTRunManager already exists.");
126#ifndef G4MULTITHREADED
128 msg <<
"Geant4 code is compiled without multi-threading support"
129 <<
"(-DG4MULTITHREADED is set to off).\n";
130 msg <<
"G4MTRunManager can only be used in multi-threaded applications.";
135 if(numberOfStaticAllocators > 0)
138 msg1 <<
"There are " << numberOfStaticAllocators
139 <<
" static G4Allocator objects detected.\n"
140 <<
"In multi-threaded mode, all G4Allocator objects must be dynamically "
153 masterRNGEngine = G4Random::getTheEngine();
158 char* env = std::getenv(
"G4FORCENUMBEROFTHREADS");
162 if(envS ==
"MAX" || envS ==
"max")
168 std::istringstream is(env);
178 msg2 <<
"Environment variable G4FORCENUMBEROFTHREADS has an invalid "
180 << envS <<
">. It has to be an integer or a word \"max\".\n"
181 <<
"G4FORCENUMBEROFTHREADS is ignored.";
190 <<
" by Environment variable G4FORCENUMBEROFTHREADS." <<
G4endl;
207 std::ostringstream os;
209 G4Random::saveEngineStatus(os.str().c_str());
218 G4cerr <<
"Warning from G4RunManager::rndmSaveThisRun():"
219 <<
" Random number status was not stored prior to this run."
220 <<
G4endl <<
"/random/setSavingFlag command must be issued. "
221 <<
"Command ignored." <<
G4endl;
227 std::ostringstream os;
228 os <<
"run" << runNumber <<
".rndm" <<
'\0';
232 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
234 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
238 {
G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl; }
243 G4Exception(
"G4MTRunManager::rndmSaveThisEvent",
"RUN_RNDM001",
249 if(threads.size() != 0)
252 msg <<
"Number of threads cannot be changed at this moment \n"
253 <<
"(old threads are still alive). Method ignored.";
254 G4Exception(
"G4MTRunManager::SetNumberOfThreads(G4int)",
"Run0112",
261 <<
" by G4FORCENUMBEROFTHREADS shell variable.\n"
262 <<
"Method ignored.";
263 G4Exception(
"G4MTRunManager::SetNumberOfThreads(G4int)",
"Run0113",
298 uiCmdsForWorkers.clear();
299 std::vector<G4String>* cmdCopy =
301 for(std::vector<G4String>::const_iterator it = cmdCopy->begin();
302 it != cmdCopy->end(); ++it)
303 uiCmdsForWorkers.push_back(*it);
311 return uiCmdsForWorkers;
320 if(threads.size() == 0)
324 std::stringstream msg;
325 msg <<
"--> G4MTRunManager::CreateAndStartWorkers() --> "
326 <<
"Initializing workers...";
328 std::stringstream ss;
330 ss << std::setw(msg.str().length()) <<
"";
346 threads.push_back(thread);
397 msgd <<
"Event modulo is reduced to " <<
eventModulo
398 <<
" to distribute events to all threads.";
399 G4Exception(
"G4MTRunManager::InitializeEventLoop()",
"Run10035",
427 <<
"> of seedOncePerCommunication is invalid. It is reset to 0.";
428 G4Exception(
"G4MTRunManager::InitializeEventLoop()",
"Run10036",
508 std::vector<G4VPhysicalVolume*>::iterator itrW =
510 for(
size_t iWorld = 0; iWorld < nWorlds; iWorld++)
558 "For multi-threaded version, define G4VUserPrimaryGeneratorAction in "
559 "G4VUserActionInitialization.");
565 "For multi-threaded version, define G4UserEventAction in "
566 "G4VUserActionInitialization.");
572 "For multi-threaded version, define G4UserStackingAction in "
573 "G4VUserActionInitialization.");
579 "For multi-threaded version, define G4UserTrackingAction in "
580 "G4VUserActionInitialization.");
586 "For multi-threaded version, define G4UserSteppingAction in "
587 "G4VUserActionInitialization.");
615 s1 = helper->
GetSeed(idx_rndm);
616 s2 = helper->
GetSeed(idx_rndm + 1);
618 s3 = helper->
GetSeed(idx_rndm + 2);
647 for(
int i = 0; i < nevRnd; i++)
673#ifdef G4MULTITHREADED
674 while(!threads.empty())
698 G4cerr <<
"Run is not in progress. AbortRun() ignored." <<
G4endl;
765 "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()
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
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
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
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
G4RunManagerKernel * kernel
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()
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()