80 ,
PTL::TaskRunManager(useTBB)
81 , eventGrainsize(grainsize)
82 , numberOfEventsPerTask(-1)
84 , masterRNGEngine(nullptr)
85 , workTaskGroup(nullptr)
96 if(numberOfStaticAllocators > 0)
99 msg1 <<
"There are " << numberOfStaticAllocators
100 <<
" static G4Allocator objects detected.\n"
101 <<
"In multi-threaded mode, all G4Allocator objects must "
102 <<
"be dynamicly instantiated.";
119 G4String _nthread_env = G4GetEnv<G4String>(
"G4FORCENUMBEROFTHREADS",
"");
120 for(
auto& itr : _nthread_env)
123 if(_nthread_env ==
"max")
125 else if(!_nthread_env.empty())
127 std::stringstream ss;
128 G4int _nthread_val = -1;
142 G4int _useTBB = G4GetEnv<G4int>(
"G4FORCE_TBB", (
G4int) useTBB);
149 msg <<
"TBB was requested but Geant4 was not built with TBB support";
150 G4Exception(
"G4TaskRunManager::G4TaskRunManager(...)",
"Run0131",
201 std::ostringstream os;
203 G4Random::saveEngineStatus(os.str().c_str());
215 msg <<
"\n### Number of threads is forced to " <<
forcedNwokers
216 <<
" by G4FORCENUMBEROFTHREADS environment variable. G4TaskRunManager::"
217 << __FUNCTION__ <<
"(" <<
n <<
") ignored ###";
218 G4Exception(
"G4TaskRunManager::SetNumberOfThreads(G4int)",
"Run0132",
230 std::stringstream ss;
231 ss <<
"\n### Thread-pool already initialized. Resizing to " <<
nworkers
263 G4Exception(
"G4TaskRunManager::InitializeThreadPool",
"Run1040",
264 JustWarning,
"Threadpool already initialized. Ignoring...");
277 std::stringstream ss;
279 ss << std::setw(90) <<
"";
288 G4cout <<
"G4TaskRunManager :: Using G4ThreadPool..." <<
G4endl;
315 G4GetEnv<G4int>(
"G4FORCE_GRAINSIZE", grainSize,
"Forcing grainsize...");
339 msgd <<
"Event modulo is reduced to " <<
eventModulo <<
" (was " << oldMod
341 <<
" to distribute events to all threads.";
342 G4Exception(
"G4TaskRunManager::InitializeEventLoop()",
"Run10035",
348 nEvtsPerTask = G4GetEnv<G4int>(
349 "G4FORCE_EVENTS_PER_TASK", nEvtsPerTask,
350 "Forcing number of events per task (overrides grainsize)...");
352 nEvtsPerTask = G4GetEnv<G4int>(
"G4FORCE_EVENTS_PER_TASK", nEvtsPerTask);
363 std::stringstream msg;
364 msg <<
"--> G4TaskRunManager::ComputeNumberOfTasks() --> " <<
numberOfTasks
367 std::stringstream ss;
369 ss << std::setw(msg.str().length()) <<
"";
387 static bool initializeStarted =
false;
393 if(initializeStarted)
396 if(!initCmdStack.empty())
399 for(
auto& itr : initCmdStack)
407 std::stringstream msg;
408 msg <<
"--> G4TaskRunManager::CreateAndStartWorkers() --> "
409 <<
"Initializing workers...";
411 std::stringstream ss;
413 ss << std::setw(msg.str().length()) <<
"";
424 initializeStarted =
true;
429 if(!initCmdStack.empty())
432 for(
auto& itr : initCmdStack)
443 std::stringstream msg;
444 msg <<
"--> G4TaskRunManager::CreateAndStartWorkers() --> "
448 std::stringstream ss;
450 ss << std::setw(msg.str().length()) <<
"";
474 G4cout <<
"Adding task " << nt <<
" to task-group..." <<
G4endl;
524 if(macroFile !=
nullptr)
551 if(_overload ==
false && _functor ==
false)
568 <<
"> of seedOncePerCommunication is invalid. It is reset "
570 G4Exception(
"G4TaskRunManager::InitializeEventLoop()",
"Run10036",
622 std::vector<G4VPhysicalVolume*>::iterator itrW =
624 for(
size_t iWorld = 0; iWorld < nWorlds; ++iWorld)
662 s1 = helper->
GetSeed(idx_rndm);
663 s2 = helper->
GetSeed(idx_rndm + 1);
665 s3 = helper->
GetSeed(idx_rndm + 2);
699 for(
G4int i = 0; i < nevRnd; ++i)
746 G4cerr <<
"Run is not in progress. AbortRun() ignored." <<
G4endl;
776 auto process_commands_stack = []() {
781 for(
const auto& itr : cmds)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::queue< G4long > G4SeedsQueue
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
virtual void flatArray(const int size, double *vect)=0
static G4int SeedOncePerCommunication()
static void SetSeedOncePerCommunication(G4int val)
G4int numberOfEventToBeProcessed
virtual void ThisWorkerProcessCommandsStackDone()
static void addWorld(G4int counter, G4VPhysicalVolume *w)
virtual void PrepareCommandsStack()
static G4MTRUN_DLL G4ScoringManager * masterScM
static G4MTRUN_DLL G4MTRunManager * fMasterRM
static G4MTRUN_DLL masterWorlds_t masterWorlds
static G4MTRunManager * GetMasterRunManager()
static G4ThreadId GetMasterThreadId()
std::vector< G4String > GetCommandStack()
G4int GetNumberOfStaticAllocators() const
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()
G4String randomNumberStatusDir
virtual void TerminateEventLoop()
virtual void ConstructScoringWorlds()
virtual void Merge(const G4Run *)
void Merge(const G4ScoringManager *scMan)
static G4ScoringManager * GetScoringManagerIfExist()
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
void BroadcastAbortRun(G4bool softAbort)
static void ExecuteWorkerTask()
static void InitializeWorker()
static void TerminateWorker()
static void TerminateWorkerRunEventLoop()
static void ExecuteWorkerInit()
void SetUpDecayChannels()
static std::vector< G4String > & InitCommandStack()
virtual void ConstructScoringWorlds() override
virtual void InitializeThreadPool() override
virtual void CreateAndStartWorkers() override
static G4TaskRunManager * GetMasterRunManager()
virtual G4bool InitializeSeeds(G4int) override
virtual void ThisWorkerProcessCommandsStackDone() override
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true) override
G4VUserTaskQueue *& taskQueue
virtual void SetNumberOfThreads(G4int n) override
virtual void AbortRun(G4bool softAbort=false) override
InitializeSeedsCallback initSeedsCallback
virtual void RefillSeeds() override
virtual void RequestWorkersProcessCommandsStack() override
virtual void AddEventTask(G4int)
static G4ThreadId GetMasterThreadId()
virtual void TerminateOneEvent() override
RunTaskGroup * workTaskGroup
CLHEP::HepRandomEngine * masterRNGEngine
virtual void TerminateWorkers() override
virtual void AbortEvent() override
G4int numberOfEventsPerTask
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
virtual ~G4TaskRunManager()
virtual void Initialize() override
virtual void StoreRNGStatus(const G4String &filenamePrefix) override
G4TaskRunManagerKernel * MTkernel
virtual void RunTermination() override
void MergeScores(const G4ScoringManager *localScoringManager)
virtual void WaitForEndEventLoopWorkers() override
G4TaskGroup< void > RunTaskGroup
G4ThreadPool *& threadPool
static G4TaskRunManagerKernel * GetMTMasterRunManagerKernel()
virtual void ProcessOneEvent(G4int i_event) override
void MergeRun(const G4Run *localRun)
virtual void ComputeNumberOfTasks()
G4TaskRunManager(G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false))
virtual G4bool SetUpAnEvent(G4Event *, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true) override
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
G4int ApplyCommand(const char *aCommand)
void SetMasterUIManager(G4bool val)
static G4UImanager * GetUIpointer()
virtual void DoWork() override
static G4WorkerTaskRunManager * GetWorkerRunManager()
enable_if_t< std::is_void< Up >::value, void > exec(Func func, Args... args)
virtual void Initialize(uint64_t n=std::thread::hardware_concurrency())
ThreadPool * GetThreadPool() const
void resize(size_type _n)
static void set_use_tbb(bool val)
bool is_tbb_threadpool() const
void execute_on_all_threads(FuncT &&_func)
size_type destroy_threadpool()
G4int G4GetNumberOfCores()
G4Mutex scorerMergerMutex