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

#include <G4RunManagerFactory.hh>

Static Public Member Functions

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

Detailed Description

Definition at line 67 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 75 of file G4RunManagerFactory.hh.

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

◆ CreateRunManager() [2/4]

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

Definition at line 81 of file G4RunManagerFactory.hh.

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

◆ 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 65 of file G4RunManagerFactory.cc.

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

Referenced by CreateRunManager(), CreateRunManager(), and CreateRunManager().

◆ CreateRunManager() [4/4]

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

Definition at line 90 of file G4RunManagerFactory.hh.

91 {
92 return CreateRunManager(GetType(type), std::forward<Args>(args)...);
93 }

◆ GetDefault()

std::string G4RunManagerFactory::GetDefault ( )
static

Definition at line 173 of file G4RunManagerFactory.cc.

174{
175#if defined(G4MULTITHREADED)
176 return "Tasking";
177#else
178 return "Serial";
179#endif
180}

Referenced by CreateRunManager().

◆ GetMasterRunManager()

G4RunManager * G4RunManagerFactory::GetMasterRunManager ( )
static

Definition at line 249 of file G4RunManagerFactory.cc.

250{
251#if !defined(G4MULTITHREADED)
252 // if serial build just return G4RunManager
254#else
255 // if the application used G4RunManagerFactory to create the run-manager
256 if (master_run_manager != nullptr) return master_run_manager;
257
258 // if the application did not use G4RunManagerFactory and is MT
260 auto mt_rm = GetMTMasterRunManager();
261 if (mt_rm != nullptr) return mt_rm;
262 }
263
264 // if the application did not use G4RunManagerFactory and is serial
266#endif
267}
static G4MTRunManager * GetMTMasterRunManager()
static G4RunManager * GetRunManager()
G4bool IsMultithreadedApplication()

Referenced by G4TrajectoriesModel::DescribeYourselfTo(), G4VisManager::Draw(), G4VSceneHandler::ProcessScene(), G4OpenGLSceneHandler::ScaledFlush(), G4VisCommandReviewKeptEvents::SetNewValue(), and G4VisCommandSceneEndOfEventAction::SetNewValue().

◆ GetMasterRunManagerKernel()

G4RunManagerKernel * G4RunManagerFactory::GetMasterRunManagerKernel ( )
static

Definition at line 290 of file G4RunManagerFactory.cc.

291{
292#if !defined(G4MULTITHREADED)
293 // if serial build just return G4RunManager
295#else
296 // if the application used G4RunManagerFactory to create the run-manager
297 if (master_run_manager_kernel != nullptr) return master_run_manager_kernel;
298
299 // if the application did not use G4RunManagerFactory and is MT
301 auto mt_rm = GetMTMasterRunManager();
302 if (mt_rm != nullptr) return mt_rm->kernel;
303 }
304
305 // if the application did not use G4RunManagerFactory and is serial
307#endif
308}

Referenced by G4VisManager::G4VisSubThread().

◆ GetMTMasterRunManager()

G4MTRunManager * G4RunManagerFactory::GetMTMasterRunManager ( )
static

Definition at line 271 of file G4RunManagerFactory.cc.

272{
273#if defined(G4MULTITHREADED)
274 // if the application used G4RunManagerFactory to create the run-manager
275 if (mt_master_run_manager != nullptr) return mt_master_run_manager;
276
277 // if the application did not use G4RunManagerFactory
280 if (task_rm != nullptr) return task_rm;
282 }
283#endif
284
285 return nullptr;
286}
static G4MTRunManager * GetMasterRunManager()
static G4TaskRunManager * GetMasterRunManager()

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

◆ GetName()

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

Definition at line 218 of file G4RunManagerFactory.cc.

219{
220 switch (_type) {
222 return "Serial";
224 return "Serial";
226 return "MT";
228 return "MT";
230 return "Tasking";
232 return "Tasking";
234 return "TBB";
236 return "TBB";
238 return "SubEvt";
240 return "SubEvt";
241 default:
242 break;
243 };
244 return "";
245}

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 options.insert("SubEvt");
194#endif
195 return options;
196 }();
197 return _instance;
198}

Referenced by CreateRunManager().

◆ GetType()

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

Definition at line 202 of file G4RunManagerFactory.cc.

203{
204 // IGNORES CASE!
205 static const auto opts = std::regex::icase;
206
207 if (std::regex_match(key, std::regex("^(Serial).*", opts))) return G4RunManagerType::Serial;
208 if (std::regex_match(key, std::regex("^(MT).*", opts))) return G4RunManagerType::MT;
209 if (std::regex_match(key, std::regex("^(Task).*", opts))) return G4RunManagerType::Tasking;
210 if (std::regex_match(key, std::regex("^(TBB).*", opts))) return G4RunManagerType::TBB;
211 if (std::regex_match(key, std::regex("^(SubEvt).*", opts))) return G4RunManagerType::SubEvt;
212
214}

Referenced by CreateRunManager(), and CreateRunManager().


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