Geant4 11.1.1
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 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)

◆ 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 }

◆ 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 ||
72 _type == G4RunManagerType::TaskingOnly ||
73 _type == G4RunManagerType::TBBOnly)
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 {
123 case G4RunManagerType::Serial:
124 rm = new G4RunManager();
125 break;
126 case G4RunManagerType::MT:
127#if defined(G4MULTITHREADED)
128 rm = new G4MTRunManager();
129#endif
130 break;
131 case G4RunManagerType::Tasking:
132#if defined(G4MULTITHREADED)
133 rm = new G4TaskRunManager(_queue, false);
134#endif
135 break;
136 case G4RunManagerType::TBB:
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
142 case G4RunManagerType::SerialOnly:
143 break;
144 case G4RunManagerType::MTOnly:
145 break;
146 case G4RunManagerType::TaskingOnly:
147 break;
148 case G4RunManagerType::TBBOnly:
149 break;
150 case G4RunManagerType::Default:
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
161 master_run_manager = rm;
162 mt_master_run_manager = mtrm;
163 master_run_manager_kernel = rm->kernel;
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
void G4ConsumeParameters(_Args &&...)
Definition: templates.hh:177

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 }

◆ 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
255 if(master_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

Referenced by G4TrajectoriesModel::DescribeYourselfTo(), G4VisManager::Draw(), 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
302 if(master_run_manager_kernel)
303 return master_run_manager_kernel;
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}

◆ 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
277 if(mt_master_run_manager)
278 return mt_master_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()

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 {
224 case G4RunManagerType::Serial:
225 return "Serial";
226 case G4RunManagerType::SerialOnly:
227 return "Serial";
228 case G4RunManagerType::MT:
229 return "MT";
230 case G4RunManagerType::MTOnly:
231 return "MT";
232 case G4RunManagerType::Tasking:
233 return "Tasking";
234 case G4RunManagerType::TaskingOnly:
235 return "Tasking";
236 case G4RunManagerType::TBB:
237 return "TBB";
238 case G4RunManagerType::TBBOnly:
239 return "TBB";
240 default:
241 break;
242 };
243 return "";
244}

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)))
207 return G4RunManagerType::Serial;
208 else if(std::regex_match(key, std::regex("^(MT).*", opts)))
209 return G4RunManagerType::MT;
210 else if(std::regex_match(key, std::regex("^(Task).*", opts)))
211 return G4RunManagerType::Tasking;
212 else if(std::regex_match(key, std::regex("^(TBB).*", opts)))
213 return G4RunManagerType::TBB;
214
215 return G4RunManagerType::Default;
216}

Referenced by CreateRunManager().


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