12 #ifndef _SST_CORE_FACTORY_H
13 #define _SST_CORE_FACTORY_H
15 #include "sst/core/sst_types.h"
20 #include "sst/core/params.h"
21 #include "sst/core/eli/elementinfo.h"
24 extern int main(
int argc,
char **argv);
27 namespace Statistics {
28 class StatisticOutput;
37 class SSTElementPythonModule;
46 static Factory* getFactory() {
return instance; }
52 bool isPortNameValid(
const std::string& type,
const std::string& port_name);
89 bool doesSubComponentExist(
const std::string& type);
102 template <
class Base>
104 std::string elemlib, elem;
105 std::tie(elemlib, elem) = parseLoadName(type);
107 requireLibrary(elemlib);
108 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
110 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
112 auto map = lib->getMap();
113 auto* info = lib->getInfo(elem);
115 auto* builderLib = Base::getBuilderLibrary(elemlib);
117 auto* fact = builderLib->getBuilder(elem);
133 template <
class Base,
class... CtorArgs>
135 std::string elemlib, elem;
136 std::tie(elemlib, elem) = parseLoadName(type);
138 std::stringstream err_os;
139 requireLibrary(elemlib, err_os);
140 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
142 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
144 auto map = lib->getMap();
145 auto* info = lib->getInfo(elem);
147 auto* builderLib = Base::getBuilderLibrary(elemlib);
149 auto* fact = builderLib->getBuilder(elem);
152 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
159 notFound(Base::ELI_baseName(), type, err_os.str());
171 template <
class T,
class... Args>
174 const std::string& stat,
Params& params,
176 std::string elemlib, elem;
177 std::tie(elemlib, elem) = parseLoadName(type);
179 std::stringstream sstr;
180 requireLibrary(elemlib, sstr);
182 auto* lib = ELI::BuilderDatabase::getLibrary<Statistics::Statistic<T>, Args...>(elemlib);
184 auto* fact = lib->getFactory(elem);
186 return fact->create(comp, statName, stat, params, std::forward<Args>(args)...);
190 out.
fatal(CALL_INFO, -1,
"can't find requested statistic %s.\n%s\n",
191 type.c_str(), sstr.str().c_str());
207 bool hasLibrary(
const std::string& elemlib, std::ostream& err_os);
208 void requireLibrary(
const std::string& elemlib, std::ostream& err_os);
213 void requireLibrary(
const std::string& elemlib);
215 void getLoadedLibraryNames(std::set<std::string>& lib_names);
216 void loadUnloadedLibraries(
const std::set<std::string>& lib_names);
254 friend int ::main(
int argc,
char **argv);
256 void notFound(
const std::string& baseName,
const std::string& type,
257 const std::string& errorMsg);
260 Factory(
const std::string& searchPaths);
265 void operator=(
Factory const&);
270 bool findLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
272 bool loadLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
274 std::set<std::string> loaded_libraries;
276 std::string searchPaths;
279 std::string loadingComponentType;
281 std::pair<std::string, std::string> parseLoadName(
const std::string& wholename);
283 std::recursive_mutex factoryMutex;
293 #endif // SST_CORE_FACTORY_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
Module * CreateModule(const std::string &type, Params ¶ms)
Instantiate a new Module.
Definition: factory.cc:428
void pushAllowedKeys(const KeySet_t &keys)
Definition: params.cc:179
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: factory.h:103
Main component object for the simulation.
Definition: component.h:31
bool DoesComponentInfoStatisticNameExist(const std::string &type, const std::string &statisticName)
Determine if a statistic is defined in a components ElementInfoStatistic.
Definition: factory.cc:288
SSTElementPythonModule * getPythonModule(const std::string &name)
Return Python Module creation function.
Definition: factory.cc:574
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:42
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:391
bool hasLibrary(const std::string &elemlib, std::ostream &err_os)
hasLibrary Checks to see if library exists and can be loaded
Definition: factory.cc:601
Module is a tag class used with the loadModule function.
Definition: module.h:22
Class to load Element Libraries.
Definition: elemLoader.h:25
uint8_t GetComponentInfoStatisticEnableLevel(const std::string &type, const std::string &statisticName)
Determine if a statistic is defined in a subcomponents ElementInfoStatistic.
Definition: factory.cc:340
Component * CreateComponent(ComponentId_t id, const std::string &componentname, Params ¶ms)
Attempt to create a new Component instantiation.
Definition: factory.cc:203
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
Partition::SSTPartitioner * CreatePartitioner(const std::string &name, RankInfo total_ranks, RankInfo my_rank, int verbosity)
Return partitioner function.
Definition: factory.cc:539
void RequireEvent(const std::string &eventname)
Ensure that an element library containing the required event is loaded.
Definition: factory.cc:528
Definition: rankInfo.h:21
Main component object for the simulation.
Definition: baseComponent.h:52
const Params::KeySet_t & getParamNames(const std::string &type)
Get a list of allowed param keys for a given component type.
Definition: factory.cc:160
Base * Create(const std::string &type, SST::Params ¶ms, CtorArgs &&...args)
General function for a given base class.
Definition: factory.h:134
Base class for Partitioning graphs.
Definition: sstpart.h:32
Parameter store.
Definition: params.h:44
Module * CreateModuleWithComponent(const std::string &type, Component *comp, Params ¶ms)
Instantiate a new Module.
Definition: factory.cc:468
void popAllowedKeys()
Removes the most recent set of keys considered allowed.
Definition: params.cc:185
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:43
Base class for python modules in element libraries.
Definition: element_python.h:133
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:188
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:102
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:172
bool DoesSubComponentSlotExist(const std::string &type, const std::string &slotName)
Determine if a SubComponentSlot is defined in a components ElementInfoStatistic.
Definition: factory.cc:245