12#ifndef SST_CORE_FACTORY_H
13#define SST_CORE_FACTORY_H
15#include "sst/core/eli/elementinfo.h"
16#include "sst/core/output.h"
17#include "sst/core/params.h"
18#include "sst/core/sst_types.h"
19#include "sst/core/sstpart.h"
28extern int main(
int argc,
char** argv);
50 static Factory* getFactory() {
return instance; }
56 bool isPortNameValid(
const std::string& type,
const std::string& port_name);
62 const std::vector<std::string>&
getParamNames(
const std::string& type);
77 bool doesSubComponentExist(
const std::string& type);
83 const std::string& name,
RankInfo total_ranks,
RankInfo my_rank,
int verbosity);
93 std::string elemlib, elem;
94 std::tie(elemlib, elem) = parseLoadName(type);
96 requireLibrary(elemlib);
97 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
99 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
101 auto map = lib->getMap();
102 auto* info = lib->getInfo(elem);
104 auto* builderLib = Base::getBuilderLibrary(elemlib);
106 auto* fact = builderLib->getBuilder(elem);
116 template <
class Base,
int index,
class InfoType>
117 const InfoType& getSimpleInfo(
const std::string& type)
119 static InfoType invalid_ret;
120 std::string elemlib, elem;
121 std::tie(elemlib, elem) = parseLoadName(type);
123 std::stringstream err_os;
124 requireLibrary(elemlib, err_os);
125 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
127 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
129 auto* info = lib->getInfo(elem);
135 return cast_info->getSimpleInfo();
150 template <
class Base,
class... CtorArgs>
151 Base*
Create(
const std::string& type, CtorArgs&&... args)
153 std::string elemlib, elem;
154 std::tie(elemlib, elem) = parseLoadName(type);
156 std::stringstream err_os;
157 requireLibrary(elemlib, err_os);
158 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
160 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
162 auto* info = lib->getInfo(elem);
164 auto* builderLib = Base::getBuilderLibrary(elemlib);
166 auto* fact = builderLib->getBuilder(elem);
168 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
174 notFound(Base::ELI_baseName(), type, err_os.str());
178 template <
class T,
class... ARGS>
179 T* CreateProfileTool(
const std::string& type, ARGS... args)
181 return Factory::getFactory()->Create<T>(type, args...);
195 template <
class Base,
class... CtorArgs>
198 std::string elemlib, elem;
199 std::tie(elemlib, elem) = parseLoadName(type);
201 std::stringstream err_os;
202 requireLibrary(elemlib, err_os);
203 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
205 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
207 auto map = lib->getMap();
208 auto* info = lib->getInfo(elem);
210 auto* builderLib = Base::getBuilderLibrary(elemlib);
212 auto* fact = builderLib->getBuilder(elem);
215 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
222 notFound(Base::ELI_baseName(), type, err_os.str());
234 template <
class T,
class... Args>
236 const std::string& stat,
Params& params, Args... args)
238 std::string elemlib, elem;
239 std::tie(elemlib, elem) = parseLoadName(type);
241 std::stringstream sstr;
242 requireLibrary(elemlib, sstr);
244 auto* lib = ELI::BuilderDatabase::getLibrary<Statistics::Statistic<T>, Args...>(elemlib);
246 auto* fact = lib->getFactory(elem);
248 return fact->create(comp, statName, stat, params, std::forward<Args>(args)...);
252 out.fatal(CALL_INFO, -1,
"can't find requested statistic %s.\n%s\n", type.c_str(), sstr.str().c_str());
267 bool hasLibrary(
const std::string& elemlib, std::ostream& err_os);
268 void requireLibrary(
const std::string& elemlib, std::ostream& err_os);
273 void requireLibrary(
const std::string& elemlib);
275 void getLoadedLibraryNames(std::set<std::string>& lib_names);
276 void loadUnloadedLibraries(
const std::set<std::string>& lib_names);
278 const std::string& getSearchPaths();
294 const std::vector<std::string>& GetValidStatistics(
const std::string& compType);
318 friend int ::main(
int argc,
char** argv);
321 void notFound(
const std::string& baseName,
const std::string& type,
const std::string& errorMsg);
323 explicit Factory(
const std::string& searchPaths);
332 bool findLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
334 bool loadLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
336 std::set<std::string> loaded_libraries;
338 std::string searchPaths;
341 std::string loadingComponentType;
343 std::pair<std::string, std::string> parseLoadName(
const std::string& wholename);
345 std::recursive_mutex factoryMutex;
Main component object for the simulation.
Definition baseComponent.h:62
Main component object for the simulation.
Definition component.h:31
Definition simpleInfo.h:88
Class to load Element Libraries.
Definition elemLoader.h:24
Class for instantiating Components, Links and the like out of element libraries.
Definition factory.h:48
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:235
void RequireEvent(const std::string &eventname)
Ensure that an element library containing the required event is loaded.
Definition factory.cc:487
Partition::SSTPartitioner * CreatePartitioner(const std::string &name, RankInfo total_ranks, RankInfo my_rank, int verbosity)
Return partitioner function.
Definition factory.cc:498
bool DoesSubComponentSlotExist(const std::string &type, const std::string &slotName)
Determine if a SubComponentSlot is defined in a components ElementInfoStatistic.
Definition factory.cc:236
SSTElementPythonModule * getPythonModule(const std::string &name)
Return Python Module creation function.
Definition factory.cc:532
Component * CreateComponent(ComponentId_t id, const std::string &componentname, Params ¶ms)
Attempt to create a new Component instantiation.
Definition factory.cc:198
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:383
Base * CreateWithParams(const std::string &type, SST::Params ¶ms, CtorArgs &&... args)
General function to create a given base class.
Definition factory.h:196
bool hasLibrary(const std::string &elemlib, std::ostream &err_os)
hasLibrary Checks to see if library exists and can be loaded
Definition factory.cc:558
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:333
const std::vector< std::string > & getParamNames(const std::string &type)
Get a list of allowed param keys for a given component type.
Definition factory.cc:157
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:100
Base * Create(const std::string &type, CtorArgs &&... args)
General function to create a given base class.
Definition factory.h:151
bool DoesComponentInfoStatisticNameExist(const std::string &type, const std::string &statisticName)
Determine if a statistic is defined in a components ElementInfoStatistic.
Definition factory.cc:321
bool isProfilePointValid(const std::string &type, const std::string &point)
Get a list of allowed ports for a given component type.
Definition factory.cc:418
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition factory.h:91
Module is a tag class used with the loadModule function.
Definition module.h:26
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition output.h:54
Parameter store.
Definition params.h:58
void popAllowedKeys()
Removes the most recent set of keys considered allowed.
Definition params.cc:243
void pushAllowedKeys(const std::vector< std::string > &keys)
Definition params.cc:233
Base class for Partitioning graphs.
Definition sstpart.h:32
Base class for python modules in element libraries.
Definition element_python.h:133
Forms the base class for statistics gathering within SST.
Definition statbase.h:49
Forms the base class for statistics output generation within the SST core.
Definition statoutput.h:52
Forms the template defined base class for statistics gathering within SST.
Definition statbase.h:373
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition subcomponent.h:29