12#ifndef SST_CORE_FACTORY_H
13#define SST_CORE_FACTORY_H
15#include "sst/core/eli/elementinfo.h"
16#include "sst/core/params.h"
17#include "sst/core/sst_types.h"
23extern int main(
int argc,
char** argv);
36class SSTElementPythonModule;
45 static Factory* getFactory() {
return instance; }
51 bool isPortNameValid(
const std::string& type,
const std::string& port_name);
85 bool doesSubComponentExist(
const std::string& type);
101 std::string elemlib, elem;
102 std::tie(elemlib, elem) = parseLoadName(type);
104 requireLibrary(elemlib);
105 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
107 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
109 auto map = lib->getMap();
110 auto* info = lib->getInfo(elem);
112 auto* builderLib = Base::getBuilderLibrary(elemlib);
114 auto* fact = builderLib->getBuilder(elem);
115 if ( fact ) {
return true; }
122 template <
class Base,
int index,
class InfoType>
123 const InfoType& getSimpleInfo(
const std::string& type)
125 static InfoType invalid_ret;
126 std::string elemlib, elem;
127 std::tie(elemlib, elem) = parseLoadName(type);
129 std::stringstream err_os;
130 requireLibrary(elemlib, err_os);
131 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
133 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
135 auto* info = lib->getInfo(elem);
140 if ( cast_info ) {
return cast_info->getSimpleInfo(); }
154 template <
class Base,
class... CtorArgs>
155 Base*
Create(
const std::string& type, CtorArgs&&... args)
157 std::string elemlib, elem;
158 std::tie(elemlib, elem) = parseLoadName(type);
160 std::stringstream err_os;
161 requireLibrary(elemlib, err_os);
162 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
164 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
166 auto* info = lib->getInfo(elem);
168 auto* builderLib = Base::getBuilderLibrary(elemlib);
170 auto* fact = builderLib->getBuilder(elem);
172 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
178 notFound(Base::ELI_baseName(), type, err_os.str());
182 template <
class T,
class... ARGS>
183 T* CreateProfileTool(
const std::string& type, ARGS... args)
185 return Factory::getFactory()->Create<T>(type, args...);
199 template <
class Base,
class... CtorArgs>
202 std::string elemlib, elem;
203 std::tie(elemlib, elem) = parseLoadName(type);
205 std::stringstream err_os;
206 requireLibrary(elemlib, err_os);
207 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
209 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
211 auto map = lib->getMap();
212 auto* info = lib->getInfo(elem);
214 auto* builderLib = Base::getBuilderLibrary(elemlib);
216 auto* fact = builderLib->getBuilder(elem);
219 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
226 notFound(Base::ELI_baseName(), type, err_os.str());
238 template <
class T,
class... Args>
240 const std::string& type,
BaseComponent* comp,
const std::string& statName,
const std::string& stat,
241 Params& params, Args... args)
243 std::string elemlib, elem;
244 std::tie(elemlib, elem) = parseLoadName(type);
246 std::stringstream sstr;
247 requireLibrary(elemlib, sstr);
249 auto* lib = ELI::BuilderDatabase::getLibrary<Statistics::Statistic<T>, Args...>(elemlib);
251 auto* fact = lib->getFactory(elem);
252 if ( fact ) {
return fact->create(comp, statName, stat, params, std::forward<Args>(args)...); }
255 out.
fatal(CALL_INFO, -1,
"can't find requested statistic %s.\n%s\n", type.c_str(), sstr.str().c_str());
270 bool hasLibrary(
const std::string& elemlib, std::ostream& err_os);
271 void requireLibrary(
const std::string& elemlib, std::ostream& err_os);
276 void requireLibrary(
const std::string& elemlib);
278 void getLoadedLibraryNames(std::set<std::string>& lib_names);
279 void loadUnloadedLibraries(
const std::set<std::string>& lib_names);
295 const std::vector<std::string>& GetValidStatistics(
const std::string& compType);
319 friend int ::main(
int argc,
char** argv);
321 void notFound(
const std::string& baseName,
const std::string& type,
const std::string& errorMsg);
323 Factory(
const std::string& searchPaths);
328 void operator=(
Factory const&);
333 bool findLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
335 bool loadLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
337 std::set<std::string> loaded_libraries;
339 std::string searchPaths;
342 std::string loadingComponentType;
344 std::pair<std::string, std::string> parseLoadName(
const std::string& wholename);
346 std::recursive_mutex factoryMutex;
Main component object for the simulation.
Definition: baseComponent.h:51
Main component object for the simulation.
Definition: component.h:31
Definition: simpleInfo.h:83
Class to load Element Libraries.
Definition: elemLoader.h:24
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:43
Statistics::Statistic< T > * CreateStatistic(const std::string &type, BaseComponent *comp, const std::string &statName, const std::string &stat, Params ¶ms, Args... args)
Instantiate a new Statistic.
Definition: factory.h:239
void RequireEvent(const std::string &eventname)
Ensure that an element library containing the required event is loaded.
Definition: factory.cc:530
Partition::SSTPartitioner * CreatePartitioner(const std::string &name, RankInfo total_ranks, RankInfo my_rank, int verbosity)
Return partitioner function.
Definition: factory.cc:541
bool DoesSubComponentSlotExist(const std::string &type, const std::string &slotName)
Determine if a SubComponentSlot is defined in a components ElementInfoStatistic.
Definition: factory.cc:227
Module * CreateModuleWithComponent(const std::string &type, Component *comp, Params ¶ms)
Instantiate a new Module.
Definition: factory.cc:472
SSTElementPythonModule * getPythonModule(const std::string &name)
Return Python Module creation function.
Definition: factory.cc:574
Component * CreateComponent(ComponentId_t id, const std::string &componentname, Params ¶ms)
Attempt to create a new Component instantiation.
Definition: factory.cc:189
std::string GetComponentInfoStatisticUnits(const std::string &type, const std::string &statisticName)
Get the units of a statistic defined in the component's ElementInfoStatistic.
Definition: factory.cc:361
Base * CreateWithParams(const std::string &type, SST::Params ¶ms, CtorArgs &&... args)
General function to create a given base class.
Definition: factory.h:200
bool hasLibrary(const std::string &elemlib, std::ostream &err_os)
hasLibrary Checks to see if library exists and can be loaded
Definition: factory.cc:600
uint8_t GetComponentInfoStatisticEnableLevel(const std::string &type, const std::string &statisticName)
Get the enable level of a statistic defined in the component's ElementInfoStatistic.
Definition: factory.cc:317
bool isPortNameValid(const std::string &type, const std::string &port_name)
Get a list of allowed ports for a given component type.
Definition: factory.cc:99
Base * Create(const std::string &type, CtorArgs &&... args)
General function to create a given base class.
Definition: factory.h:155
bool DoesComponentInfoStatisticNameExist(const std::string &type, const std::string &statisticName)
Determine if a statistic is defined in a components ElementInfoStatistic.
Definition: factory.cc:307
Module * CreateModule(const std::string &type, Params ¶ms)
Instantiate a new Module.
Definition: factory.cc:432
const Params::KeySet_t & getParamNames(const std::string &type)
Get a list of allowed param keys for a given component type.
Definition: factory.cc:150
bool isProfilePointValid(const std::string &type, const std::string &point)
Get a list of allowed ports for a given component type.
Definition: factory.cc:390
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: factory.h:99
Module is a tag class used with the loadModule function.
Definition: module.h:22
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition: output.h:52
void fatal(uint32_t line, const char *file, const char *func, int exit_code, const char *format,...) const
Output the fatal message with formatting as specified by the format parameter.
Definition: output.cc:155
Parameter store.
Definition: params.h:56
void popAllowedKeys()
Removes the most recent set of keys considered allowed.
Definition: params.cc:209
void pushAllowedKeys(const KeySet_t &keys)
Definition: params.cc:203
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:233
Base class for Partitioning graphs.
Definition: sstpart.h:32
Definition: rankInfo.h:22
Base class for python modules in element libraries.
Definition: element_python.h:129
Forms the template defined base class for statistics gathering within SST.
Definition: statbase.h:361