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"
34extern int main(
int argc,
char** argv);
58 static Factory* getFactory() {
return instance; }
60 static Factory* createFactory(
const std::string& searchPaths);
73 bool isPortNameValid(
const std::string& type,
const std::string& port_name);
79 const std::vector<std::string>&
getParamNames(
const std::string& type);
94 bool doesSubComponentExist(
const std::string& type);
100 const std::string& name,
RankInfo total_ranks,
RankInfo my_rank,
int verbosity);
107 template <
class Base>
110 std::string elemlib, elem;
111 std::tie(elemlib, elem) = parseLoadName(type);
113 requireLibrary(elemlib);
114 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
116 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
118 auto map = lib->getMap();
119 auto* info = lib->getInfo(elem);
121 auto* builderLib = Base::getBuilderLibrary(elemlib);
123 auto* fact = builderLib->getBuilder(elem);
133 template <
class Base,
int index,
class InfoType>
134 const InfoType& getSimpleInfo(
const std::string& type)
136 static InfoType invalid_ret;
137 std::string elemlib, elem;
138 std::tie(elemlib, elem) = parseLoadName(type);
140 std::stringstream err_os;
141 requireLibrary(elemlib, err_os);
142 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
144 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
146 auto* info = lib->getInfo(elem);
152 return cast_info->getSimpleInfo();
167 template <
class Base,
class... CtorArgs>
168 Base*
Create(
const std::string& type, CtorArgs&&... args)
170 std::string elemlib, elem;
171 std::tie(elemlib, elem) = parseLoadName(type);
173 std::stringstream err_os;
174 requireLibrary(elemlib, err_os);
175 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
177 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
179 auto* info = lib->getInfo(elem);
181 auto* builderLib = Base::getBuilderLibrary(elemlib);
183 auto* fact = builderLib->getBuilder(elem);
185 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
191 notFound(Base::ELI_baseName(), type, err_os.str());
195 template <
class T,
class... ARGS>
196 T* CreateProfileTool(
const std::string& type, ARGS... args)
198 return Factory::getFactory()->Create<T>(type, args...);
212 template <
class Base,
class... CtorArgs>
215 std::string elemlib, elem;
216 std::tie(elemlib, elem) = parseLoadName(type);
218 std::stringstream err_os;
219 requireLibrary(elemlib, err_os);
220 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
222 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
224 auto map = lib->getMap();
225 auto* info = lib->getInfo(elem);
227 auto* builderLib = Base::getBuilderLibrary(elemlib);
229 auto* fact = builderLib->getBuilder(elem);
232 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
239 notFound(Base::ELI_baseName(), type, err_os.str());
251 template <
class T,
class... Args>
253 const std::string& stat,
Params& params, Args... args)
255 std::string elemlib, elem;
256 std::tie(elemlib, elem) = parseLoadName(type);
258 std::stringstream sstr;
259 requireLibrary(elemlib, sstr);
261 auto* lib = ELI::BuilderDatabase::getLibrary<Statistics::Statistic<T>, Args...>(elemlib);
263 auto* fact = lib->getFactory(elem);
265 return fact->create(comp, statName, stat, params, std::forward<Args>(args)...);
269 out.fatal(CALL_INFO, -1,
"can't find requested statistic %s.\n%s\n", type.c_str(), sstr.str().c_str());
284 bool hasLibrary(
const std::string& elemlib, std::ostream& err_os);
285 void requireLibrary(
const std::string& elemlib, std::ostream& err_os);
290 void requireLibrary(
const std::string& elemlib);
292 void getLoadedLibraryNames(std::set<std::string>& lib_names);
293 void loadUnloadedLibraries(
const std::set<std::string>& lib_names);
295 const std::string& getSearchPaths();
318 uint8_t GetStatisticValidityAndEnableLevel(
const std::string& type,
const std::string& statistic_name);
328 const std::string& type,
const std::string& input_file,
int verbose,
Config& cfg,
double start_time);
330 explicit Factory(
const std::string& searchPaths);
333 friend int ::main(
int argc,
char** argv);
336 void notFound(
const std::string& baseName,
const std::string& type,
const std::string& errorMsg);
346 bool findLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
348 bool loadLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
350 std::set<std::string> loaded_libraries;
352 std::string searchPaths;
355 std::string loadingComponentType;
357 static std::pair<std::string, std::string> parseLoadName(
const std::string& wholename);
359 std::recursive_mutex factoryMutex;
Main component object for the simulation.
Definition baseComponent.h:67
Main component object for the simulation.
Definition component.h:32
Class to contain SST Simulation Configuration variables.
Definition config.h:52
Definition simpleInfo.h:88
Class to load Element Libraries.
Definition elemLoader.h:25
Class for instantiating Components, Links and the like out of element libraries.
Definition factory.h:56
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:252
void RequireEvent(const std::string &eventname)
Ensure that an element library containing the required event is loaded.
Definition factory.cc:529
Partition::SSTPartitioner * CreatePartitioner(const std::string &name, RankInfo total_ranks, RankInfo my_rank, int verbosity)
Return partitioner function.
Definition factory.cc:540
bool DoesSubComponentSlotExist(const std::string &type, const std::string &slotName)
Determine if a SubComponentSlot is defined in a components ElementInfoSubComponentSlot.
Definition factory.cc:253
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:215
bool DoesComponentInfoStatisticNameExist(const std::string &type, const std::string &statistic_name)
Determine if a statistic is defined in a components ElementInfoStatistic.
Definition factory.cc:360
Base * CreateWithParams(const std::string &type, SST::Params ¶ms, CtorArgs &&... args)
General function to create a given base class.
Definition factory.h:213
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
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:174
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:117
Base * Create(const std::string &type, CtorArgs &&... args)
General function to create a given base class.
Definition factory.h:168
std::string GetComponentInfoStatisticUnits(const std::string &type, const std::string &statistic_name)
Get the units of a statistic defined in the component's ElementInfoStatistic.
Definition factory.cc:408
void updateSearchPaths(const std::string &paths)
Update the search paths.
Definition factory.cc:76
bool isProfilePointValid(const std::string &type, const std::string &point)
Get a list of allowed ports for a given component type.
Definition factory.cc:460
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition factory.h:108
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:58
Parameter store.
Definition params.h:65
void popAllowedKeys()
Removes the most recent set of keys considered allowed.
Definition params.cc:252
void pushAllowedKeys(const std::vector< std::string > &keys)
Definition params.cc:242
Base class for Partitioning graphs.
Definition sstpart.h:32
Base class for python modules in element libraries.
Definition element_python.h:133
Base class for Model Generation.
Definition sstmodel.h:32
Forms the base class for statistics gathering within SST.
Definition statbase.h:51
Forms the base class for statistics output generation within the SST core.
Definition statoutput.h:54
Forms the template defined base class for statistics gathering within SST.
Definition statbase.h:369
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition subcomponent.h:29