Geant4-11
Static Public Member Functions
G4RunManagerFactory Class Reference

#include <G4RunManagerFactory.hh>

Static Public Member Functions

static G4RunManagerCreateRunManager (G4RunManagerType _type, G4bool fail_if_unavail, G4int nthreads=0, G4VUserTaskQueue *_queue=nullptr)
 
static G4RunManagerCreateRunManager (G4RunManagerType _type, G4int nthreads, G4bool fail_if_unavail=true, G4VUserTaskQueue *_queue=nullptr)
 
static G4RunManagerCreateRunManager (G4RunManagerType _type=G4RunManagerType::Default, G4VUserTaskQueue *_queue=nullptr, G4bool fail_if_unavail=true, G4int nthreads=0)
 
template<typename... Args>
static G4RunManagerCreateRunManager (std::string type, Args &&... args)
 
static std::string GetDefault ()
 
static G4RunManagerGetMasterRunManager ()
 
static G4RunManagerKernelGetMasterRunManagerKernel ()
 
static G4MTRunManagerGetMTMasterRunManager ()
 
static std::string GetName (G4RunManagerType)
 
static std::set< std::string > GetOptions ()
 
static G4RunManagerType GetType (const std::string &)
 

Detailed Description

Definition at line 65 of file G4RunManagerFactory.hh.

Member Function Documentation

◆ CreateRunManager() [1/4]

static G4RunManager * G4RunManagerFactory::CreateRunManager ( G4RunManagerType  _type,
G4bool  fail_if_unavail,
G4int  nthreads = 0,
G4VUserTaskQueue _queue = nullptr 
)
inlinestatic

Definition at line 74 of file G4RunManagerFactory.hh.

78 {
79 return CreateRunManager(_type, _queue, fail_if_unavail, nthreads);
80 }
static G4RunManager * CreateRunManager(G4RunManagerType _type=G4RunManagerType::Default, G4VUserTaskQueue *_queue=nullptr, G4bool fail_if_unavail=true, G4int nthreads=0)

References CreateRunManager().

◆ CreateRunManager() [2/4]

static G4RunManager * G4RunManagerFactory::CreateRunManager ( G4RunManagerType  _type,
G4int  nthreads,
G4bool  fail_if_unavail = true,
G4VUserTaskQueue _queue = nullptr 
)
inlinestatic

Definition at line 82 of file G4RunManagerFactory.hh.

85 {
86 return CreateRunManager(_type, _queue, fail_if_unavail, nthreads);
87 }

References CreateRunManager().

◆ CreateRunManager() [3/4]

G4RunManager * G4RunManagerFactory::CreateRunManager ( G4RunManagerType  _type = G4RunManagerType::Default,
G4VUserTaskQueue _queue = nullptr,
G4bool  fail_if_unavail = true,
G4int  nthreads = 0 
)
static

Definition at line 63 of file G4RunManagerFactory.cc.

67{
68 // If the supplied type is not ...Only, then allow override from environment
69 std::string rm_type = GetName(_type);
70 if(_type == G4RunManagerType::SerialOnly ||
71 _type == G4RunManagerType::MTOnly ||
74 {
75 // MUST fail if unavail in this case
76 fail_if_unavail = true;
77 }
78 else
79 {
80 // - G4RUN_MANAGER_TYPE can be set to override the "default"
81 // - If the requested type isn't available, then it will fall back to the
82 // system default
83 // - G4FORCE_RUN_MANAGER_TYPE can be set to force a specific type
84 // - A G4Exception is raised if the requested type is not available
85 rm_type = G4GetEnv<std::string>("G4RUN_MANAGER_TYPE", GetName(_type),
86 "Overriding G4RunManager type...");
87 auto force_rm = G4GetEnv<std::string>("G4FORCE_RUN_MANAGER_TYPE", "",
88 "Forcing G4RunManager type...");
89
90 if(force_rm.length() > 0)
91 {
92 rm_type = force_rm;
93 fail_if_unavail = true;
94 }
95 else if(rm_type.empty())
96 {
97 rm_type = GetDefault();
98 }
99 }
100
101 // At this point will have a string for the RM type we can check for existence
102 // NB: Comparison at present is case sensitive (needs a comparator in
103 // GetOptions)
104 auto opts = GetOptions();
105 if(opts.find(rm_type) == opts.end())
106 {
107 if(fail_if_unavail)
108 {
109 fail("Run manager type is not available", rm_type, opts, 1);
110 }
111 else
112 {
113 rm_type = GetDefault();
114 }
115 }
116
117 // Construct requested RunManager given type
118 _type = GetType(rm_type);
119 G4RunManager* rm = nullptr;
120
121 switch(_type)
122 {
124 rm = new G4RunManager();
125 break;
127#if defined(G4MULTITHREADED)
128 rm = new G4MTRunManager();
129#endif
130 break;
132#if defined(G4MULTITHREADED)
133 rm = new G4TaskRunManager(_queue, false);
134#endif
135 break;
137#if defined(G4MULTITHREADED) && defined(GEANT4_USE_TBB)
138 rm = new G4TaskRunManager(_queue, true);
139#endif
140 break;
141 // "Only" types are not handled since they are converted above to main type
143 break;
145 break;
147 break;
149 break;
151 break;
152 }
153
154 if(!rm)
155 fail("Failure creating run manager", GetName(_type), GetOptions(), 2);
156
157 auto mtrm = dynamic_cast<G4MTRunManager*>(rm);
158 if(nthreads > 0 && mtrm)
159 mtrm->SetNumberOfThreads(nthreads);
160
164
165 G4ConsumeParameters(_queue);
166 return rm;
167}
virtual void SetNumberOfThreads(G4int n)
static std::set< std::string > GetOptions()
static std::string GetName(G4RunManagerType)
static std::string GetDefault()
static G4RunManagerType GetType(const std::string &)
G4RunManagerKernel * kernel
static void fail(const std::string &_prefix, const std::string &_name, const std::set< std::string > &_opts, G4int _num)
static G4RunManagerKernel * master_run_manager_kernel
void G4ConsumeParameters(_Args &&...)
Definition: templates.hh:187

References Default, anonymous_namespace{G4RunManagerFactory.cc}::fail(), G4ConsumeParameters(), GetDefault(), GetName(), GetOptions(), GetType(), G4RunManager::kernel, anonymous_namespace{G4RunManagerFactory.cc}::master_run_manager, anonymous_namespace{G4RunManagerFactory.cc}::master_run_manager_kernel, MT, anonymous_namespace{G4RunManagerFactory.cc}::mt_master_run_manager, MTOnly, Serial, SerialOnly, G4MTRunManager::SetNumberOfThreads(), Tasking, TaskingOnly, TBB, and TBBOnly.

Referenced by CreateRunManager().

◆ CreateRunManager() [4/4]

template<typename... Args>
static G4RunManager * G4RunManagerFactory::CreateRunManager ( std::string  type,
Args &&...  args 
)
inlinestatic

Definition at line 91 of file G4RunManagerFactory.hh.

92 {
93 return CreateRunManager(GetType(type), std::forward<Args>(args)...);
94 }
static char ** args
Definition: G4Xt.cc:51

References args, CreateRunManager(), and GetType().

◆ GetDefault()

std::string G4RunManagerFactory::GetDefault ( )
static

Definition at line 171 of file G4RunManagerFactory.cc.

172{
173#if defined(G4MULTITHREADED)
174 // For version 10.7, default is set to MT
175 // return "MT";
176 return "Tasking";
177#else
178 return "Serial";
179#endif
180}

Referenced by CreateRunManager().

◆ GetMasterRunManager()

G4RunManager * G4RunManagerFactory::GetMasterRunManager ( )
static

Definition at line 248 of file G4RunManagerFactory.cc.

249{
250#if !defined(G4MULTITHREADED)
251 // if serial build just return G4RunManager
253#else
254 // if the application used G4RunManagerFactory to create the run-manager
256 return master_run_manager;
257
258 // if the application did not use G4RunManagerFactory and is MT
260 {
261 auto mt_rm = GetMTMasterRunManager();
262 if(mt_rm)
263 return mt_rm;
264 }
265
266 // if the application did not use G4RunManagerFactory and is serial
268#endif
269}
static G4MTRunManager * GetMTMasterRunManager()
static G4RunManager * GetRunManager()
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:130

References GetMTMasterRunManager(), G4RunManager::GetRunManager(), G4Threading::IsMultithreadedApplication(), and anonymous_namespace{G4RunManagerFactory.cc}::master_run_manager.

Referenced by G4VisManager::BeginOfRun(), G4TrajectoriesModel::DescribeYourselfTo(), G4VisManager::Draw(), G4VisManager::EndOfEvent(), G4VisManager::EndOfRun(), G4VisCommandSceneAddEventID::EventID::operator()(), G4VSceneHandler::ProcessScene(), G4OpenGLSceneHandler::ScaledFlush(), G4VisCommandReviewKeptEvents::SetNewValue(), and G4VisCommandSceneEndOfEventAction::SetNewValue().

◆ GetMasterRunManagerKernel()

G4RunManagerKernel * G4RunManagerFactory::GetMasterRunManagerKernel ( )
static

Definition at line 295 of file G4RunManagerFactory.cc.

296{
297#if !defined(G4MULTITHREADED)
298 // if serial build just return G4RunManager
300#else
301 // if the application used G4RunManagerFactory to create the run-manager
304
305 // if the application did not use G4RunManagerFactory and is MT
307 {
308 auto mt_rm = GetMTMasterRunManager();
309 if(mt_rm)
310 return mt_rm->kernel;
311 }
312
313 // if the application did not use G4RunManagerFactory and is serial
315#endif
316}

References GetMTMasterRunManager(), G4RunManager::GetRunManager(), G4Threading::IsMultithreadedApplication(), G4RunManager::kernel, and anonymous_namespace{G4RunManagerFactory.cc}::master_run_manager_kernel.

◆ GetMTMasterRunManager()

G4MTRunManager * G4RunManagerFactory::GetMTMasterRunManager ( )
static

Definition at line 273 of file G4RunManagerFactory.cc.

274{
275#if defined(G4MULTITHREADED)
276 // if the application used G4RunManagerFactory to create the run-manager
279
280 // if the application did not use G4RunManagerFactory
282 {
284 if(task_rm)
285 return task_rm;
287 }
288#endif
289
290 return nullptr;
291}
static G4MTRunManager * GetMasterRunManager()
static G4TaskRunManager * GetMasterRunManager()

References G4MTRunManager::GetMasterRunManager(), G4TaskRunManager::GetMasterRunManager(), G4Threading::IsMultithreadedApplication(), and anonymous_namespace{G4RunManagerFactory.cc}::mt_master_run_manager.

Referenced by G4TheMTRayTracer::CreateBitMap(), GetMasterRunManager(), GetMasterRunManagerKernel(), G4TheMTRayTracer::RestoreUserActions(), and G4TheMTRayTracer::StoreUserActions().

◆ GetName()

std::string G4RunManagerFactory::GetName ( G4RunManagerType  _type)
static

Definition at line 220 of file G4RunManagerFactory.cc.

221{
222 switch(_type)
223 {
225 return "Serial";
227 return "Serial";
229 return "MT";
231 return "MT";
233 return "Tasking";
235 return "Tasking";
237 return "TBB";
239 return "TBB";
240 default:
241 break;
242 };
243 return "";
244}

References MT, MTOnly, Serial, SerialOnly, Tasking, TaskingOnly, TBB, and TBBOnly.

Referenced by CreateRunManager().

◆ GetOptions()

std::set< std::string > G4RunManagerFactory::GetOptions ( )
static

Definition at line 184 of file G4RunManagerFactory.cc.

185{
186 static auto _instance = []() {
187 std::set<std::string> options = { "Serial" };
188#if defined(G4MULTITHREADED)
189 options.insert({ "MT", "Tasking" });
190# if defined(GEANT4_USE_TBB)
191 options.insert("TBB");
192# endif
193#endif
194 return options;
195 }();
196 return _instance;
197}

Referenced by CreateRunManager().

◆ GetType()

G4RunManagerType G4RunManagerFactory::GetType ( const std::string &  key)
static

Definition at line 201 of file G4RunManagerFactory.cc.

202{
203 // IGNORES CASE!
204 static const auto opts = std::regex::icase;
205
206 if(std::regex_match(key, std::regex("^(Serial).*", opts)))
208 else if(std::regex_match(key, std::regex("^(MT).*", opts)))
210 else if(std::regex_match(key, std::regex("^(Task).*", opts)))
212 else if(std::regex_match(key, std::regex("^(TBB).*", opts)))
214
216}

References Default, MT, Serial, Tasking, and TBB.

Referenced by CreateRunManager().


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