41 static void fail(
const std::string& _prefix,
const std::string& _name,
42 const std::set<std::string>& _opts,
G4int _num)
45 msg << _prefix <<
": \"" << _name <<
"\". "
46 <<
"Must be one of: ";
48 for(
const auto& itr : _opts)
49 ss <<
", \"" << itr <<
"\"";
50 msg << ss.str().substr(2);
51 auto mnum = std::string(
"RunManagerFactory000") + std::to_string(_num);
52 G4Exception(
"G4RunManagerFactory::CreateRunManager", mnum.c_str(),
69 std::string rm_type =
GetName(_type);
76 fail_if_unavail =
true;
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...");
90 if(force_rm.length() > 0)
93 fail_if_unavail =
true;
95 else if(rm_type.empty())
105 if(opts.find(rm_type) == opts.end())
109 fail(
"Run manager type is not available", rm_type, opts, 1);
127#if defined(G4MULTITHREADED)
132#if defined(G4MULTITHREADED)
137#if defined(G4MULTITHREADED) && defined(GEANT4_USE_TBB)
158 if(nthreads > 0 && mtrm)
173#if defined(G4MULTITHREADED)
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");
204 static const auto opts = std::regex::icase;
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)))
250#if !defined(G4MULTITHREADED)
275#if defined(G4MULTITHREADED)
297#if !defined(G4MULTITHREADED)
310 return mt_rm->kernel;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
virtual void SetNumberOfThreads(G4int n)
static G4MTRunManager * GetMasterRunManager()
static G4RunManager * CreateRunManager(G4RunManagerType _type=G4RunManagerType::Default, G4VUserTaskQueue *_queue=nullptr, G4bool fail_if_unavail=true, G4int nthreads=0)
static G4RunManager * GetMasterRunManager()
static G4MTRunManager * GetMTMasterRunManager()
static std::set< std::string > GetOptions()
static std::string GetName(G4RunManagerType)
static std::string GetDefault()
static G4RunManagerType GetType(const std::string &)
static G4RunManagerKernel * GetMasterRunManagerKernel()
G4RunManagerKernel * kernel
static G4RunManager * GetRunManager()
static G4TaskRunManager * GetMasterRunManager()
G4bool IsMultithreadedApplication()
static G4MTRunManager * mt_master_run_manager
static void fail(const std::string &_prefix, const std::string &_name, const std::set< std::string > &_opts, G4int _num)
static G4RunManager * master_run_manager
static G4RunManagerKernel * master_run_manager_kernel
void G4ConsumeParameters(_Args &&...)