Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MTRunManager Class Reference

#include <G4MTRunManager.hh>

+ Inheritance diagram for G4MTRunManager:

Public Types

enum class  WorkerActionRequest { UNDEFINED , NEXTITERATION , PROCESSUI , ENDWORKER }
 
using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>
 
using masterWorlds_t = std::map<G4int, G4VPhysicalVolume*>
 
- Public Types inherited from G4RunManager
enum  RMType { sequentialRM , masterRM , workerRM }
 
using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>
 

Public Member Functions

 G4MTRunManager ()
 
 ~G4MTRunManager () override
 
void SetNumberOfThreads (G4int n) override
 
G4int GetNumberOfThreads () const override
 
void SetPinAffinity (G4int n=1)
 
G4int GetPinAffinity () const
 
void Initialize () override
 
void InitializeEventLoop (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
 
virtual void InitializeThreadPool ()
 
void TerminateOneEvent () override
 
void ProcessOneEvent (G4int i_event) override
 
void ConstructScoringWorlds () override
 
void RunTermination () override
 
virtual G4bool SetUpAnEvent (G4Event *, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true)
 
virtual G4int SetUpNEvents (G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
 
std::vector< G4StringGetCommandStack ()
 
virtual size_t GetNumberActiveThreads () const
 
virtual void ThisWorkerReady ()
 
virtual void ThisWorkerEndEventLoop ()
 
const CLHEP::HepRandomEnginegetMasterRandomEngine () const
 
void SetUserInitialization (G4VUserPhysicsList *userPL) override
 
void SetUserInitialization (G4VUserDetectorConstruction *userDC) override
 
void SetUserInitialization (G4UserWorkerInitialization *userInit) override
 
void SetUserInitialization (G4UserWorkerThreadInitialization *userInit) override
 
void SetUserInitialization (G4VUserActionInitialization *userInit) override
 
void SetUserAction (G4UserRunAction *userAction) override
 
void SetUserAction (G4VUserPrimaryGeneratorAction *userAction) override
 
void SetUserAction (G4UserEventAction *userAction) override
 
void SetUserAction (G4UserStackingAction *userAction) override
 
void SetUserAction (G4UserTrackingAction *userAction) override
 
void SetUserAction (G4UserSteppingAction *userAction) override
 
void MergeScores (const G4ScoringManager *localScoringManager)
 
void MergeRun (const G4Run *localRun)
 
virtual void RequestWorkersProcessCommandsStack ()
 
virtual void ThisWorkerProcessCommandsStackDone ()
 
virtual WorkerActionRequest ThisWorkerWaitForNextAction ()
 
void SetEventModulo (G4int i=1)
 
G4int GetEventModulo () const
 
void AbortRun (G4bool softAbort=false) override
 
void AbortEvent () override
 
- Public Member Functions inherited from G4RunManager
 G4RunManager ()
 
virtual ~G4RunManager ()
 
 G4RunManager (const G4RunManager &)=delete
 
G4RunManageroperator= (const G4RunManager &)=delete
 
virtual void BeamOn (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
 
virtual void DefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
virtual void InitializeGeometry ()
 
virtual void InitializePhysics ()
 
virtual G4bool ConfirmBeamOnCondition ()
 
virtual void RunInitialization ()
 
virtual void DoEventLoop (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
 
virtual void TerminateEventLoop ()
 
virtual G4EventGenerateEvent (G4int i_event)
 
virtual void AnalyzeEvent (G4Event *anEvent)
 
virtual void ConfigureProfilers (const std::vector< std::string > &args={})
 
void ConfigureProfilers (G4int argc, char **argv)
 
void DumpRegion (const G4String &rname) const
 
void DumpRegion (G4Region *region=nullptr) const
 
void GeometryHasBeenModified (G4bool prop=true)
 
void ReinitializeGeometry (G4bool destroyFirst=false, G4bool prop=true)
 
void PhysicsHasBeenModified ()
 
void CutOffHasBeenModified ()
 
void ReOptimizeMotherOf (G4VPhysicalVolume *)
 
void ReOptimize (G4LogicalVolume *)
 
void SetGeometryToBeOptimized (G4bool vl)
 
G4bool GetGeometryToBeOptimized ()
 
void GeometryDirectlyUpdated (G4bool val=true)
 
virtual void RestoreRandomNumberStatus (const G4String &fileN)
 
virtual void RestoreRndmEachEvent (G4bool)
 
const G4VUserDetectorConstructionGetUserDetectorConstruction () const
 
const G4VUserPhysicsListGetUserPhysicsList () const
 
const G4VUserActionInitializationGetUserActionInitialization () const
 
G4VUserActionInitializationGetNonConstUserActionInitialization () const
 
const G4UserWorkerInitializationGetUserWorkerInitialization () const
 
const G4UserWorkerThreadInitializationGetUserWorkerThreadInitialization () const
 
const G4UserRunActionGetUserRunAction () const
 
const G4VUserPrimaryGeneratorActionGetUserPrimaryGeneratorAction () const
 
const G4UserEventActionGetUserEventAction () const
 
const G4UserStackingActionGetUserStackingAction () const
 
const G4UserTrackingActionGetUserTrackingAction () const
 
const G4UserSteppingActionGetUserSteppingAction () const
 
void SetNumberOfAdditionalWaitingStacks (G4int iAdd)
 
const G4StringGetVersionString () const
 
void SetPrimaryTransformer (G4PrimaryTransformer *pt)
 
void StoreRandomNumberStatusToG4Event (G4int vl)
 
G4int GetFlagRandomNumberStatusToG4Event () const
 
void SetRandomNumberStore (G4bool flag)
 
G4bool GetRandomNumberStore () const
 
void SetRandomNumberStoreDir (const G4String &dir)
 
const G4StringGetRandomNumberStoreDir () const
 
const G4StringGetRandomNumberStatusForThisRun () const
 
const G4StringGetRandomNumberStatusForThisEvent () const
 
void SetRandomNumberStorePerEvent (G4bool flag)
 
G4bool GetRandomNumberStorePerEvent () const
 
void SetVerboseLevel (G4int vl)
 
G4int GetVerboseLevel () const
 
G4int GetPrintProgress ()
 
void SetPrintProgress (G4int i)
 
void SetNumberOfEventsToBeStored (G4int val)
 
const G4RunGetCurrentRun () const
 
G4RunGetNonConstCurrentRun () const
 
const G4EventGetCurrentEvent () const
 
const G4EventGetPreviousEvent (G4int i) const
 
void SetRunIDCounter (G4int i)
 
G4int GetNumberOfParallelWorld () const
 
void SetNumberOfEventsToBeProcessed (G4int val)
 
G4int GetNumberOfEventsToBeProcessed () const
 
G4int GetNumberOfSelectEvents () const
 
const G4StringGetSelectMacro () const
 
void SetDCtable (G4DCtable *DCtbl)
 
RMType GetRunManagerType () const
 

Static Public Member Functions

static G4ThreadId GetMasterThreadId ()
 
static G4ScoringManagerGetMasterScoringManager ()
 
static masterWorlds_tGetMasterWorlds ()
 
static void addWorld (G4int counter, G4VPhysicalVolume *w)
 
static G4MTRunManagerGetMasterRunManager ()
 
static G4RunManagerKernelGetMasterRunManagerKernel ()
 
static G4MTRunManagerKernelGetMTMasterRunManagerKernel ()
 
static G4int SeedOncePerCommunication ()
 
static void SetSeedOncePerCommunication (G4int val)
 
- Static Public Member Functions inherited from G4RunManager
static G4RunManagerGetRunManager ()
 
static G4bool IfGeometryHasBeenDestroyed ()
 

Protected Member Functions

virtual G4bool InitializeSeeds (G4int)
 
virtual void PrepareCommandsStack ()
 
void StoreRNGStatus (const G4String &filenamePrefix) override
 
void rndmSaveThisRun () override
 
void rndmSaveThisEvent () override
 
virtual void CreateAndStartWorkers ()
 
virtual void WaitForReadyWorkers ()
 
virtual void WaitForEndEventLoopWorkers ()
 
virtual void TerminateWorkers ()
 
virtual void NewActionRequest (WorkerActionRequest newRequest)
 
virtual void RefillSeeds ()
 
- Protected Member Functions inherited from G4RunManager
 G4RunManager (RMType rmType)
 
void CleanUpPreviousEvents ()
 
void CleanUpUnnecessaryEvents (G4int keepNEvents)
 
void StackPreviousEvent (G4Event *anEvent)
 
void UpdateScoring ()
 
virtual void DeleteUserInitializations ()
 

Protected Attributes

G4int nworkers = 2
 
G4int forcedNwokers = -1
 
G4int numberOfEventToBeProcessed = 0
 
WorkerActionRequest nextActionRequest = WorkerActionRequest::UNDEFINED
 
G4int eventModuloDef = 0
 
G4int eventModulo = 1
 
G4int nSeedsUsed = 0
 
G4int nSeedsFilled = 0
 
G4int nSeedsMax = 10000
 
G4int nSeedsPerEvent = 2
 
G4doublerandDbl = nullptr
 
G4MTBarrier beginOfEventLoopBarrier
 
G4MTBarrier endOfEventLoopBarrier
 
G4MTBarrier nextActionRequestBarrier
 
G4MTBarrier processUIBarrier
 
- Protected Attributes inherited from G4RunManager
G4RunManagerKernelkernel = nullptr
 
G4EventManagereventManager = nullptr
 
G4VUserDetectorConstructionuserDetector = nullptr
 
G4VUserPhysicsListphysicsList = nullptr
 
G4VUserActionInitializationuserActionInitialization = nullptr
 
G4UserWorkerInitializationuserWorkerInitialization = nullptr
 
G4UserWorkerThreadInitializationuserWorkerThreadInitialization = nullptr
 
G4UserRunActionuserRunAction = nullptr
 
G4VUserPrimaryGeneratorActionuserPrimaryGeneratorAction = nullptr
 
G4UserEventActionuserEventAction = nullptr
 
G4UserStackingActionuserStackingAction = nullptr
 
G4UserTrackingActionuserTrackingAction = nullptr
 
G4UserSteppingActionuserSteppingAction = nullptr
 
G4bool geometryInitialized = false
 
G4bool physicsInitialized = false
 
G4bool runAborted = false
 
G4bool initializedAtLeastOnce = false
 
G4bool geometryToBeOptimized = true
 
G4int runIDCounter = 0
 
G4int verboseLevel = 0
 
G4int printModulo = -1
 
G4Timertimer = nullptr
 
G4DCtableDCtable = nullptr
 
G4RuncurrentRun = nullptr
 
G4EventcurrentEvent = nullptr
 
std::list< G4Event * > * previousEvents = nullptr
 
G4int n_perviousEventsToBeStored = 0
 
G4int numberOfEventToBeProcessed = 0
 
G4bool storeRandomNumberStatus = false
 
G4int storeRandomNumberStatusToG4Event = 0
 
G4String randomNumberStatusDir = "./"
 
G4String randomNumberStatusForThisRun = ""
 
G4String randomNumberStatusForThisEvent = ""
 
G4bool rngStatusEventsFlag = false
 
G4VPhysicalVolumecurrentWorld = nullptr
 
G4int nParallelWorlds = 0
 
G4String msgText = " "
 
G4int n_select_msg = -1
 
G4int numberOfEventProcessed = 0
 
G4String selectMacro = ""
 
G4bool fakeRun = false
 
G4bool isScoreNtupleWriter = false
 
G4bool geometryDirectlyUpdated = false
 
RMType runManagerType
 

Static Protected Attributes

static G4MTRUN_DLL G4ScoringManagermasterScM = nullptr
 
static G4MTRUN_DLL masterWorlds_t masterWorlds = G4MTRunManager::masterWorlds_t()
 
static G4MTRUN_DLL G4MTRunManagerfMasterRM = nullptr
 
static G4ThreadId masterThreadId = G4ThisThread::get_id()
 
static G4int seedOncePerCommunication = 0
 
- Static Protected Attributes inherited from G4RunManager
static G4RUN_DLL G4bool fGeometryHasBeenDestroyed = false
 

Friends

class G4RunManagerFactory
 

Detailed Description

Definition at line 58 of file G4MTRunManager.hh.

Member Typedef Documentation

◆ masterWorlds_t

Definition at line 68 of file G4MTRunManager.hh.

◆ ProfilerConfig

Member Enumeration Documentation

◆ WorkerActionRequest

Enumerator
UNDEFINED 
NEXTITERATION 
PROCESSUI 
ENDWORKER 

Definition at line 164 of file G4MTRunManager.hh.

165 {
166 UNDEFINED,
167 NEXTITERATION, // There is another set of UI commands to be executed
168 PROCESSUI, // Process UI commands w/o a /run/beamOn
169 ENDWORKER // Terminate thread, work finished
170 };

Constructor & Destructor Documentation

◆ G4MTRunManager()

G4MTRunManager::G4MTRunManager ( )

Definition at line 121 of file G4MTRunManager.cc.

122{
123 if (fMasterRM != nullptr) {
124 G4Exception("G4MTRunManager::G4MTRunManager", "Run0110", FatalException,
125 "Another instance of a G4MTRunManager already exists.");
126 }
127 fMasterRM = this;
128 masterThreadId = G4ThisThread::get_id();
129 MTkernel = static_cast<G4MTRunManagerKernel*>(kernel);
130#ifndef G4MULTITHREADED
132 msg << "Geant4 code is compiled without multi-threading support"
133 << "(-DG4MULTITHREADED is set to off).\n";
134 msg << "G4MTRunManager can only be used in multi-threaded applications.";
135 G4Exception("G4MTRunManager::G4MTRunManager", "Run0111", FatalException, msg);
136#endif
137
138 G4int numberOfStaticAllocators = kernel->GetNumberOfStaticAllocators();
139 if (numberOfStaticAllocators > 0) {
141 msg1 << "There are " << numberOfStaticAllocators << " static G4Allocator objects detected.\n"
142 << "In multi-threaded mode, all G4Allocator objects must be dynamically "
143 "instantiated.";
144 G4Exception("G4MTRunManager::G4MTRunManager", "Run1035", FatalException, msg1);
145 }
148
149 // Check if a default RandomNumberGenerator has been created by user,
150 // if not create default one
151 // Note this call forces creation of defaults if not already there
152 // G4Random::getTheEngine(); //User did not specify RNG, create defaults
153 // Now remember the master instance of the RNG Engine
154 masterRNGEngine = G4Random::getTheEngine();
155
157
158 char* env = std::getenv("G4FORCENUMBEROFTHREADS");
159 if (env != nullptr) {
160 G4String envS = env;
161 if (envS == "MAX" || envS == "max") {
163 }
164 else {
165 std::istringstream is(env);
166 G4int val = -1;
167 is >> val;
168 if (val > 0) {
169 forcedNwokers = val;
170 }
171 else {
173 msg2 << "Environment variable G4FORCENUMBEROFTHREADS has an invalid "
174 "value <"
175 << envS << ">. It has to be an integer or a word \"max\".\n"
176 << "G4FORCENUMBEROFTHREADS is ignored.";
177 G4Exception("G4MTRunManager::G4MTRunManager", "Run1039", JustWarning, msg2);
178 }
179 }
180 if (forcedNwokers > 0) {
182 if (verboseLevel > 0) {
183 G4cout << "### Number of threads is forced to " << forcedNwokers
184 << " by Environment variable G4FORCENUMBEROFTHREADS." << G4endl;
185 }
186 }
187 }
188}
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4MTRUN_DLL G4ScoringManager * masterScM
static G4MTRUN_DLL G4MTRunManager * fMasterRM
static G4ThreadId masterThreadId
G4int GetNumberOfStaticAllocators() const
G4RunManagerKernel * kernel
static G4ScoringManager * GetScoringManagerIfExist()
void SetMasterUIManager(G4bool val)
static G4UImanager * GetUIpointer()
G4int G4GetNumberOfCores()

◆ ~G4MTRunManager()

G4MTRunManager::~G4MTRunManager ( )
override

Definition at line 191 of file G4MTRunManager.cc.

192{
193 // TODO: Currently does not work due to concurrent deletion of something
194 // that is shared:
195 // G4ProcessTable::DeleteMessenger from ~G4RunManager
196 // G4cout<<"Destroy MTRunManager"<<G4endl;//ANDREA
198 delete[] randDbl;
199}
virtual void TerminateWorkers()

Member Function Documentation

◆ AbortEvent()

void G4MTRunManager::AbortEvent ( )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 657 of file G4MTRunManager.cc.

658{
659 // nothing to do in the master thread
660}

◆ AbortRun()

void G4MTRunManager::AbortRun ( G4bool softAbort = false)
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 643 of file G4MTRunManager.cc.

644{
645 // This method is valid only for GeomClosed or EventProc state
647 if (currentState == G4State_GeomClosed || currentState == G4State_EventProc) {
648 runAborted = true;
649 MTkernel->BroadcastAbortRun(softAbort);
650 }
651 else {
652 G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
653 }
654}
G4ApplicationState
@ G4State_EventProc
@ G4State_GeomClosed
G4GLOB_DLL std::ostream G4cerr
void BroadcastAbortRun(G4bool softAbort)
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()

◆ addWorld()

void G4MTRunManager::addWorld ( G4int counter,
G4VPhysicalVolume * w )
static

Definition at line 97 of file G4MTRunManager.cc.

98{
99 masterWorlds.insert(std::make_pair(counter, w));
100}
static G4MTRUN_DLL masterWorlds_t masterWorlds

Referenced by ConstructScoringWorlds(), and G4TaskRunManager::ConstructScoringWorlds().

◆ ConstructScoringWorlds()

void G4MTRunManager::ConstructScoringWorlds ( )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 463 of file G4MTRunManager.cc.

464{
466 // Call base class stuff...
468
469 masterWorlds.clear();
472 for (G4int iWorld = 0; iWorld < nWorlds; ++iWorld) {
473 addWorld(iWorld, *itrW);
474 ++itrW;
475 }
476}
static void addWorld(G4int counter, G4VPhysicalVolume *w)
virtual void ConstructScoringWorlds()
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
std::size_t GetNoWorlds() const

◆ CreateAndStartWorkers()

void G4MTRunManager::CreateAndStartWorkers ( )
protectedvirtual

Reimplemented in G4TaskRunManager.

Definition at line 304 of file G4MTRunManager.cc.

305{
306 // Now loop on requested number of workers
307 // This will also start the workers
308 // Currently we do not allow to change the
309 // number of threads: threads area created once
310 if (threads.empty()) {
311 if (verboseLevel > 0) {
312 // for consistency with G4TaskRunManager
313 std::stringstream msg;
314 msg << "--> G4MTRunManager::CreateAndStartWorkers() --> "
315 << "Initializing workers...";
316
317 std::stringstream ss;
318 ss.fill('=');
319 ss << std::setw(G4int(msg.str().length())) << "";
320 G4cout << "\n" << ss.str() << "\n" << msg.str() << "\n" << ss.str() << "\n" << G4endl;
321 }
322
323 for (G4int nw = 0; nw < nworkers; ++nw) {
324 // Create a new worker and remember it
325 auto context = new G4WorkerThread;
326 context->SetNumberThreads(nworkers);
327 context->SetThreadId(nw);
329 threads.push_back(thread);
330 }
331 }
332 // Signal to threads they can start a new run
334}
virtual void NewActionRequest(WorkerActionRequest newRequest)
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
virtual G4Thread * CreateAndStartWorker(G4WorkerThread *workerThreadContext)
void SetNumberThreads(G4int numnberThreads)

Referenced by InitializeEventLoop().

◆ GetCommandStack()

std::vector< G4String > G4MTRunManager::GetCommandStack ( )

◆ GetEventModulo()

G4int G4MTRunManager::GetEventModulo ( ) const
inline

◆ getMasterRandomEngine()

const CLHEP::HepRandomEngine * G4MTRunManager::getMasterRandomEngine ( ) const
inline

Definition at line 136 of file G4MTRunManager.hh.

136{ return masterRNGEngine; }

Referenced by G4TaskRunManagerKernel::InitializeWorker(), and G4MTRunManagerKernel::StartThread().

◆ GetMasterRunManager()

◆ GetMasterRunManagerKernel()

G4RunManagerKernel * G4MTRunManager::GetMasterRunManagerKernel ( )
static

Definition at line 73 of file G4MTRunManager.cc.

74{
75 return fMasterRM->kernel;
76}

Referenced by G4WorkerRunManager::InitializeGeometry().

◆ GetMasterScoringManager()

G4ScoringManager * G4MTRunManager::GetMasterScoringManager ( )
static

◆ GetMasterThreadId()

◆ GetMasterWorlds()

G4MTRunManager::masterWorlds_t & G4MTRunManager::GetMasterWorlds ( )
static

◆ GetMTMasterRunManagerKernel()

G4MTRunManagerKernel * G4MTRunManager::GetMTMasterRunManagerKernel ( )
static

Definition at line 79 of file G4MTRunManager.cc.

80{
81 return fMasterRM->MTkernel;
82}

◆ GetNumberActiveThreads()

virtual size_t G4MTRunManager::GetNumberActiveThreads ( ) const
inlinevirtual

Reimplemented in G4TaskRunManager.

Definition at line 119 of file G4MTRunManager.hh.

119{ return threads.size(); }

Referenced by NewActionRequest(), RequestWorkersProcessCommandsStack(), WaitForEndEventLoopWorkers(), and WaitForReadyWorkers().

◆ GetNumberOfThreads()

G4int G4MTRunManager::GetNumberOfThreads ( ) const
inlineoverridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 75 of file G4MTRunManager.hh.

75{ return nworkers; }

◆ GetPinAffinity()

G4int G4MTRunManager::GetPinAffinity ( ) const
inline

Definition at line 77 of file G4MTRunManager.hh.

77{ return pinAffinity; }

Referenced by G4TaskRunManagerKernel::InitializeWorker(), and G4MTRunManagerKernel::StartThread().

◆ Initialize()

void G4MTRunManager::Initialize ( )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 263 of file G4MTRunManager.cc.

264{
266
267 // make sure all worker threads are set up.
268 BeamOn(0);
270}
virtual void Initialize()
void SetRunIDCounter(G4int i)
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)

◆ InitializeEventLoop()

void G4MTRunManager::InitializeEventLoop ( G4int n_event,
const char * macroFile = nullptr,
G4int n_select = -1 )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 337 of file G4MTRunManager.cc.

338{
339 MTkernel->SetUpDecayChannels();
342
343 if (!fakeRun) {
344 nSeedsUsed = 0;
345 nSeedsFilled = 0;
346
347 if (verboseLevel > 0) {
348 timer->Start();
349 }
350
351 n_select_msg = n_select;
352 if (macroFile != nullptr) {
353 if (n_select_msg < 0) n_select_msg = n_event;
354 msgText = "/control/execute ";
355 msgText += macroFile;
356 selectMacro = macroFile;
357 }
358 else {
359 n_select_msg = -1;
360 selectMacro = "";
361 }
362
363 // initialize seeds
364 // If user did not implement InitializeSeeds,
365 // use default: nSeedsPerEvent seeds per event
366 if (eventModuloDef > 0) {
370 if (eventModulo < 1) eventModulo = 1;
372 msgd << "Event modulo is reduced to " << eventModulo
373 << " to distribute events to all threads.";
374 G4Exception("G4MTRunManager::InitializeEventLoop()", "Run10035", JustWarning, msgd);
375 }
376 }
377 else {
379 if (eventModulo < 1) eventModulo = 1;
380 }
381 if (!InitializeSeeds(n_event) && n_event > 0) {
383 switch (seedOncePerCommunication) {
384 case 0:
385 nSeedsFilled = n_event;
386 break;
387 case 1:
389 break;
390 case 2:
391 nSeedsFilled = n_event / eventModulo + 1;
392 break;
393 default:
395 msgd << "Parameter value <" << seedOncePerCommunication
396 << "> of seedOncePerCommunication is invalid. It is reset to 0.";
397 G4Exception("G4MTRunManager::InitializeEventLoop()", "Run10036", JustWarning, msgd);
399 nSeedsFilled = n_event;
400 }
401
402 // Generates up to nSeedsMax seed pairs only.
404 masterRNGEngine->flatArray(nSeedsPerEvent * nSeedsFilled, randDbl);
405 helper->Fill(randDbl, nSeedsFilled, n_event, nSeedsPerEvent);
406 }
407 }
408
409 // Now initialize workers. Check if user defined a WorkerThreadInitialization
410 if (userWorkerThreadInitialization == nullptr) {
412 }
413
414 // Prepare UI commands for threads
416
417 // Start worker threads
419
420 // We need a barrier here. Wait for workers to start event loop.
421 // This will return only when all workers have started processing events.
423}
virtual void flatArray(const int size, double *vect)=0
G4int numberOfEventToBeProcessed
virtual G4bool InitializeSeeds(G4int)
virtual void WaitForReadyWorkers()
virtual void CreateAndStartWorkers()
virtual void PrepareCommandsStack()
static G4int seedOncePerCommunication
G4Timer * timer
G4int numberOfEventProcessed
G4String msgText
G4String selectMacro
static G4TemplateRNGHelper< T > * GetInstance()
void Fill(G4double *dbl, G4int nev, G4int nev_tot, G4int nrpe)
void Start()

◆ InitializeSeeds()

virtual G4bool G4MTRunManager::InitializeSeeds ( G4int )
inlineprotectedvirtual

Reimplemented in G4TaskRunManager.

Definition at line 200 of file G4MTRunManager.hh.

200{ return false; };

Referenced by InitializeEventLoop().

◆ InitializeThreadPool()

virtual void G4MTRunManager::InitializeThreadPool ( )
inlinevirtual

Reimplemented in G4TaskRunManager.

Definition at line 83 of file G4MTRunManager.hh.

83{}

◆ MergeRun()

void G4MTRunManager::MergeRun ( const G4Run * localRun)

Definition at line 565 of file G4MTRunManager.cc.

566{
567 G4AutoLock l(&runMergerMutex);
568 if (currentRun != nullptr && localRun != nullptr) currentRun->Merge(localRun);
569}
G4Run * currentRun
virtual void Merge(const G4Run *)
Definition G4Run.cc:65

Referenced by G4WorkerRunManager::MergePartialResults().

◆ MergeScores()

void G4MTRunManager::MergeScores ( const G4ScoringManager * localScoringManager)

Definition at line 558 of file G4MTRunManager.cc.

559{
560 G4AutoLock l(&scorerMergerMutex);
561 if (masterScM != nullptr && localScoringManager != nullptr) masterScM->Merge(localScoringManager);
562}
void Merge(const G4ScoringManager *scMan)

Referenced by G4WorkerRunManager::MergePartialResults().

◆ NewActionRequest()

void G4MTRunManager::NewActionRequest ( G4MTRunManager::WorkerActionRequest newRequest)
protectedvirtual

Reimplemented in G4TaskRunManager.

Definition at line 691 of file G4MTRunManager.cc.

692{
694 // nextActionRequest is a shared resource, but there is no
695 // data-race thanks to the barrier: all threads are waiting
696 nextActionRequest = newRequest;
698}
void ReleaseBarrier()
virtual size_t GetNumberActiveThreads() const
WorkerActionRequest nextActionRequest
G4MTBarrier nextActionRequestBarrier

Referenced by CreateAndStartWorkers(), RequestWorkersProcessCommandsStack(), and TerminateWorkers().

◆ PrepareCommandsStack()

void G4MTRunManager::PrepareCommandsStack ( )
protectedvirtual

Definition at line 285 of file G4MTRunManager.cc.

286{
287 G4AutoLock l(&cmdHandlingMutex);
288 uiCmdsForWorkers.clear();
289 std::vector<G4String>* cmdCopy = G4UImanager::GetUIpointer()->GetCommandStack();
290 for (const auto& it : *cmdCopy)
291 uiCmdsForWorkers.push_back(it);
292 cmdCopy->clear();
293 delete cmdCopy;
294}
std::vector< G4String > * GetCommandStack()

Referenced by InitializeEventLoop(), G4TaskRunManager::InitializeEventLoop(), RequestWorkersProcessCommandsStack(), and G4TaskRunManager::RequestWorkersProcessCommandsStack().

◆ ProcessOneEvent()

void G4MTRunManager::ProcessOneEvent ( G4int i_event)
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 273 of file G4MTRunManager.cc.

274{
275 // Nothing to do
276}

◆ RefillSeeds()

void G4MTRunManager::RefillSeeds ( )
protectedvirtual

Reimplemented in G4TaskRunManager.

Definition at line 426 of file G4MTRunManager.cc.

427{
429 G4int nFill = 0;
430 switch (seedOncePerCommunication) {
431 case 0:
433 break;
434 case 1:
435 nFill = nworkers - nSeedsFilled;
436 break;
437 case 2:
438 default:
440 }
441 // Generates up to nSeedsMax seed pairs only.
442 if (nFill > nSeedsMax) nFill = nSeedsMax;
443 masterRNGEngine->flatArray(nSeedsPerEvent * nFill, randDbl);
444 helper->Refill(randDbl, nFill);
445 nSeedsFilled += nFill;
446}
void Refill(G4double *dbl, G4int nev)

Referenced by SetUpAnEvent(), and SetUpNEvents().

◆ RequestWorkersProcessCommandsStack()

void G4MTRunManager::RequestWorkersProcessCommandsStack ( )
virtual

Reimplemented in G4TaskRunManager.

Definition at line 708 of file G4MTRunManager.cc.

Referenced by TerminateWorkers().

◆ rndmSaveThisEvent()

void G4MTRunManager::rndmSaveThisEvent ( )
overrideprotectedvirtual

Reimplemented from G4RunManager.

Definition at line 235 of file G4MTRunManager.cc.

236{
237 G4Exception("G4MTRunManager::rndmSaveThisEvent", "RUN_RNDM001", FatalException,
238 "This method shall not be invoked !!");
239}

◆ rndmSaveThisRun()

void G4MTRunManager::rndmSaveThisRun ( )
overrideprotectedvirtual

Reimplemented from G4RunManager.

Definition at line 210 of file G4MTRunManager.cc.

211{
212 G4int runNumber = 0;
213 if (currentRun != nullptr) runNumber = currentRun->GetRunID();
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;
219 return;
220 }
221
222 G4fs::path fileIn = randomNumberStatusDir + "G4Worker_currentRun.rndm";
223
224 std::ostringstream os;
225 os << "run" << runNumber << ".rndm" << '\0';
226 G4fs::path fileOut = randomNumberStatusDir + os.str();
227
228 if (G4CopyRandomState(fileIn, fileOut, "G4MTRunManager::rndmSaveThisRun()") && verboseLevel > 0)
229 {
230 G4cout << fileIn << " is copied to " << fileOut << G4endl;
231 }
232}
G4bool G4CopyRandomState(const G4fs::path &source, const G4fs::path &dest, const G4String &callsite)
G4String randomNumberStatusDir
G4bool storeRandomNumberStatus
G4int GetRunID() const
Definition G4Run.hh:86

◆ RunTermination()

void G4MTRunManager::RunTermination ( )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 449 of file G4MTRunManager.cc.

450{
451 // Wait for all worker threads to have finished the run
452 // i.e. wait for them to return from RunTermination()
453 // This guarantee that userrunaction for workers has been called
454
455 // Wait now for all threads to finish event-loop
457 // Now call base-class methof
460}
virtual void WaitForEndEventLoopWorkers()
virtual void RunTermination()
virtual void TerminateEventLoop()

◆ SeedOncePerCommunication()

◆ SetEventModulo()

void G4MTRunManager::SetEventModulo ( G4int i = 1)
inline

Definition at line 186 of file G4MTRunManager.hh.

186{ eventModuloDef = i; }

◆ SetNumberOfThreads()

void G4MTRunManager::SetNumberOfThreads ( G4int n)
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 242 of file G4MTRunManager.cc.

243{
244 if (!threads.empty()) {
246 msg << "Number of threads cannot be changed at this moment \n"
247 << "(old threads are still alive). Method ignored.";
248 G4Exception("G4MTRunManager::SetNumberOfThreads(G4int)", "Run0112", JustWarning, msg);
249 }
250 else if (forcedNwokers > 0) {
252 msg << "Number of threads is forced to " << forcedNwokers
253 << " by G4FORCENUMBEROFTHREADS shell variable.\n"
254 << "Method ignored.";
255 G4Exception("G4MTRunManager::SetNumberOfThreads(G4int)", "Run0113", JustWarning, msg);
256 }
257 else {
258 nworkers = n;
259 }
260}

Referenced by G4RunManagerFactory::CreateRunManager().

◆ SetPinAffinity()

void G4MTRunManager::SetPinAffinity ( G4int n = 1)

Definition at line 723 of file G4MTRunManager.cc.

724{
725 if (n == 0) {
726 G4Exception("G4MTRunManager::SetPinAffinity", "Run0114", FatalException,
727 "Pin affinity must be >0 or <0.");
728 }
729 pinAffinity = n;
730 return;
731}

◆ SetSeedOncePerCommunication()

void G4MTRunManager::SetSeedOncePerCommunication ( G4int val)
static

Definition at line 115 of file G4MTRunManager.cc.

116{
118}

Referenced by G4TaskRunManager::InitializeEventLoop(), and G4RunMessenger::SetNewValue().

◆ SetUpAnEvent()

G4bool G4MTRunManager::SetUpAnEvent ( G4Event * evt,
G4long & s1,
G4long & s2,
G4long & s3,
G4bool reseedRequired = true )
virtual

Reimplemented in G4TaskRunManager.

Definition at line 572 of file G4MTRunManager.cc.

574{
575 G4AutoLock l(&setUpEventMutex);
578 if (reseedRequired) {
580 G4int idx_rndm = nSeedsPerEvent * nSeedsUsed;
581 s1 = helper->GetSeed(idx_rndm);
582 s2 = helper->GetSeed(idx_rndm + 1);
583 if (nSeedsPerEvent == 3) s3 = helper->GetSeed(idx_rndm + 2);
584 ++nSeedsUsed;
586 }
588 return true;
589 }
590 return false;
591}
void SetEventID(G4int i)
Definition G4Event.hh:85
virtual void RefillSeeds()
virtual const T GetSeed(const G4int &sdId)

Referenced by G4WorkerRunManager::GenerateEvent(), and G4WorkerTaskRunManager::GenerateEvent().

◆ SetUpNEvents()

G4int G4MTRunManager::SetUpNEvents ( G4Event * evt,
G4SeedsQueue * seedsQueue,
G4bool reseedRequired = true )
virtual

Reimplemented in G4TaskRunManager.

Definition at line 594 of file G4MTRunManager.cc.

595{
596 G4AutoLock l(&setUpEventMutex);
598 G4int nev = eventModulo;
601 }
603 if (reseedRequired) {
605 G4int nevRnd = nev;
606 if (seedOncePerCommunication > 0) nevRnd = 1;
607 for (G4int i = 0; i < nevRnd; ++i) {
608 seedsQueue->push(helper->GetSeed(nSeedsPerEvent * nSeedsUsed));
609 seedsQueue->push(helper->GetSeed(nSeedsPerEvent * nSeedsUsed + 1));
610 if (nSeedsPerEvent == 3) seedsQueue->push(helper->GetSeed(nSeedsPerEvent * nSeedsUsed + 2));
611 ++nSeedsUsed;
613 }
614 }
616 return nev;
617 }
618 return 0;
619}

Referenced by G4WorkerRunManager::GenerateEvent(), and G4WorkerTaskRunManager::GenerateEvent().

◆ SetUserAction() [1/6]

void G4MTRunManager::SetUserAction ( G4UserEventAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 526 of file G4MTRunManager.cc.

527{
528 G4Exception("G4MTRunManager::SetUserAction()", "Run0124", FatalException,
529 "For multi-threaded version, define G4UserEventAction in "
530 "G4VUserActionInitialization.");
531}

◆ SetUserAction() [2/6]

void G4MTRunManager::SetUserAction ( G4UserRunAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 511 of file G4MTRunManager.cc.

512{
513 G4RunManager::SetUserAction(userAction);
514 if (userAction != nullptr) userAction->SetMaster();
515}
virtual void SetUserAction(G4UserRunAction *userAction)
virtual void SetMaster(G4bool val=true)

Referenced by G4TheMTRayTracer::RestoreUserActions(), and G4TheMTRayTracer::StoreUserActions().

◆ SetUserAction() [3/6]

void G4MTRunManager::SetUserAction ( G4UserStackingAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 534 of file G4MTRunManager.cc.

535{
536 G4Exception("G4MTRunManager::SetUserAction()", "Run0125", FatalException,
537 "For multi-threaded version, define G4UserStackingAction in "
538 "G4VUserActionInitialization.");
539}

◆ SetUserAction() [4/6]

void G4MTRunManager::SetUserAction ( G4UserSteppingAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 550 of file G4MTRunManager.cc.

551{
552 G4Exception("G4MTRunManager::SetUserAction()", "Run0127", FatalException,
553 "For multi-threaded version, define G4UserSteppingAction in "
554 "G4VUserActionInitialization.");
555}

◆ SetUserAction() [5/6]

void G4MTRunManager::SetUserAction ( G4UserTrackingAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 542 of file G4MTRunManager.cc.

543{
544 G4Exception("G4MTRunManager::SetUserAction()", "Run0126", FatalException,
545 "For multi-threaded version, define G4UserTrackingAction in "
546 "G4VUserActionInitialization.");
547}

◆ SetUserAction() [6/6]

void G4MTRunManager::SetUserAction ( G4VUserPrimaryGeneratorAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 518 of file G4MTRunManager.cc.

519{
520 G4Exception("G4MTRunManager::SetUserAction()", "Run0123", FatalException,
521 "For multi-threaded version, define G4VUserPrimaryGeneratorAction in "
522 "G4VUserActionInitialization.");
523}

◆ SetUserInitialization() [1/5]

void G4MTRunManager::SetUserInitialization ( G4UserWorkerInitialization * userInit)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 479 of file G4MTRunManager.cc.

480{
481 userWorkerInitialization = userInit;
482}
G4UserWorkerInitialization * userWorkerInitialization

◆ SetUserInitialization() [2/5]

void G4MTRunManager::SetUserInitialization ( G4UserWorkerThreadInitialization * userInit)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 485 of file G4MTRunManager.cc.

486{
488}

◆ SetUserInitialization() [3/5]

void G4MTRunManager::SetUserInitialization ( G4VUserActionInitialization * userInit)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 491 of file G4MTRunManager.cc.

492{
493 userActionInitialization = userInit;
495}
G4VUserActionInitialization * userActionInitialization

◆ SetUserInitialization() [4/5]

void G4MTRunManager::SetUserInitialization ( G4VUserDetectorConstruction * userDC)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 505 of file G4MTRunManager.cc.

506{
508}
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)

◆ SetUserInitialization() [5/5]

void G4MTRunManager::SetUserInitialization ( G4VUserPhysicsList * userPL)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 498 of file G4MTRunManager.cc.

499{
501 // Needed for MT, to be moved in kernel
502}

Referenced by G4TheMTRayTracer::RestoreUserActions(), and G4TheMTRayTracer::StoreUserActions().

◆ StoreRNGStatus()

void G4MTRunManager::StoreRNGStatus ( const G4String & filenamePrefix)
overrideprotectedvirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 202 of file G4MTRunManager.cc.

203{
204 std::ostringstream os;
205 os << randomNumberStatusDir << "G4Master_" << fn << ".rndm";
206 G4Random::saveEngineStatus(os.str().c_str());
207}

◆ TerminateOneEvent()

void G4MTRunManager::TerminateOneEvent ( )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4TaskRunManager.

Definition at line 279 of file G4MTRunManager.cc.

280{
281 // Nothing to do
282}

◆ TerminateWorkers()

void G4MTRunManager::TerminateWorkers ( )
protectedvirtual

Reimplemented in G4TaskRunManager.

Definition at line 622 of file G4MTRunManager.cc.

623{
624 // Force workers to execute (if any) all UI commands left in the stack
626 // Ask workers to exit
628 // finalize profiler before shutting down the threads
630 // Now join threads.
631#ifdef G4MULTITHREADED // protect here to prevent warning in compilation
632 while (!threads.empty()) {
633 G4Thread* t = *(threads.begin());
634 threads.pop_front();
636 delete t;
637 }
638#endif
639 threads.clear();
640}
virtual void RequestWorkersProcessCommandsStack()
static void Finalize()

Referenced by ~G4MTRunManager().

◆ ThisWorkerEndEventLoop()

void G4MTRunManager::ThisWorkerEndEventLoop ( )
virtual

Reimplemented in G4TaskRunManager.

Definition at line 685 of file G4MTRunManager.cc.

686{
688}
void ThisWorkerReady()
G4MTBarrier endOfEventLoopBarrier

Referenced by G4WorkerRunManager::RunTermination(), and G4WorkerTaskRunManager::RunTermination().

◆ ThisWorkerProcessCommandsStackDone()

void G4MTRunManager::ThisWorkerProcessCommandsStackDone ( )
virtual

◆ ThisWorkerReady()

void G4MTRunManager::ThisWorkerReady ( )
virtual

◆ ThisWorkerWaitForNextAction()

G4MTRunManager::WorkerActionRequest G4MTRunManager::ThisWorkerWaitForNextAction ( )
virtual

Reimplemented in G4TaskRunManager.

Definition at line 701 of file G4MTRunManager.cc.

Referenced by G4WorkerRunManager::DoWork().

◆ WaitForEndEventLoopWorkers()

void G4MTRunManager::WaitForEndEventLoopWorkers ( )
protectedvirtual

◆ WaitForReadyWorkers()

void G4MTRunManager::WaitForReadyWorkers ( )
protectedvirtual

Friends And Related Symbol Documentation

◆ G4RunManagerFactory

friend class G4RunManagerFactory
friend

Definition at line 60 of file G4MTRunManager.hh.

Member Data Documentation

◆ beginOfEventLoopBarrier

G4MTBarrier G4MTRunManager::beginOfEventLoopBarrier
protected

◆ endOfEventLoopBarrier

G4MTBarrier G4MTRunManager::endOfEventLoopBarrier
protected

◆ eventModulo

◆ eventModuloDef

G4int G4MTRunManager::eventModuloDef = 0
protected

◆ fMasterRM

G4MTRunManager * G4MTRunManager::fMasterRM = nullptr
staticprotected

◆ forcedNwokers

G4int G4MTRunManager::forcedNwokers = -1
protected

◆ masterScM

◆ masterThreadId

G4ThreadId G4MTRunManager::masterThreadId = G4ThisThread::get_id()
staticprotected

Definition at line 253 of file G4MTRunManager.hh.

Referenced by G4MTRunManager(), and GetMasterThreadId().

◆ masterWorlds

◆ nextActionRequest

WorkerActionRequest G4MTRunManager::nextActionRequest = WorkerActionRequest::UNDEFINED
protected

Definition at line 243 of file G4MTRunManager.hh.

Referenced by NewActionRequest(), and ThisWorkerWaitForNextAction().

◆ nextActionRequestBarrier

G4MTBarrier G4MTRunManager::nextActionRequestBarrier
protected

Definition at line 274 of file G4MTRunManager.hh.

Referenced by NewActionRequest(), and ThisWorkerWaitForNextAction().

◆ nSeedsFilled

◆ nSeedsMax

◆ nSeedsPerEvent

◆ nSeedsUsed

◆ numberOfEventToBeProcessed

◆ nworkers

◆ processUIBarrier

G4MTBarrier G4MTRunManager::processUIBarrier
protected

◆ randDbl

◆ seedOncePerCommunication

G4int G4MTRunManager::seedOncePerCommunication = 0
staticprotected

The documentation for this class was generated from the following files: