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" 33 extern int main(
int argc,
char** argv);
36 namespace Statistics {
37 class StatisticOutput;
47 class SSTElementPythonModule;
48 class SSTModelDescription;
57 static Factory* getFactory() {
return instance; }
59 static Factory* createFactory(
const std::string& searchPaths);
72 bool isPortNameValid(
const std::string& type,
const std::string& port_name);
78 const std::vector<std::string>&
getParamNames(
const std::string& type);
93 bool doesSubComponentExist(
const std::string& type);
99 const std::string& name,
RankInfo total_ranks,
RankInfo my_rank,
int verbosity);
106 template <
class Base>
109 std::string elemlib, elem;
110 std::tie(elemlib, elem) = parseLoadName(type);
112 requireLibrary(elemlib);
113 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
115 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
117 auto map = lib->getMap();
118 auto* info = lib->getInfo(elem);
120 auto* builderLib = Base::getBuilderLibrary(elemlib);
122 auto* fact = builderLib->getBuilder(elem);
132 template <
class Base,
int index,
class InfoType>
133 const InfoType& getSimpleInfo(
const std::string& type)
135 static InfoType invalid_ret;
136 std::string elemlib, elem;
137 std::tie(elemlib, elem) = parseLoadName(type);
139 std::stringstream err_os;
140 requireLibrary(elemlib, err_os);
141 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
143 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
145 auto* info = lib->getInfo(elem);
151 return cast_info->getSimpleInfo();
166 template <
class Base,
class... CtorArgs>
167 Base*
Create(
const std::string& type, CtorArgs&&... args)
169 std::string elemlib, elem;
170 std::tie(elemlib, elem) = parseLoadName(type);
172 std::stringstream err_os;
173 requireLibrary(elemlib, err_os);
174 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
176 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
178 auto* info = lib->getInfo(elem);
180 auto* builderLib = Base::getBuilderLibrary(elemlib);
182 auto* fact = builderLib->getBuilder(elem);
184 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
190 notFound(Base::ELI_baseName(), type, err_os.str());
194 template <
class T,
class... ARGS>
195 T* CreateProfileTool(
const std::string& type, ARGS... args)
197 return Factory::getFactory()->Create<T>(type, args...);
211 template <
class Base,
class... CtorArgs>
214 std::string elemlib, elem;
215 std::tie(elemlib, elem) = parseLoadName(type);
217 std::stringstream err_os;
218 requireLibrary(elemlib, err_os);
219 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
221 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
223 auto map = lib->getMap();
224 auto* info = lib->getInfo(elem);
226 auto* builderLib = Base::getBuilderLibrary(elemlib);
228 auto* fact = builderLib->getBuilder(elem);
231 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
238 notFound(Base::ELI_baseName(), type, err_os.str());
250 template <
class T,
class... Args>
252 const std::string& stat,
Params& params, Args... args)
254 std::string elemlib, elem;
255 std::tie(elemlib, elem) = parseLoadName(type);
257 std::stringstream sstr;
258 requireLibrary(elemlib, sstr);
260 auto* lib = ELI::BuilderDatabase::getLibrary<Statistics::Statistic<T>, Args...>(elemlib);
262 auto* fact = lib->getFactory(elem);
264 return fact->create(comp, statName, stat, params, std::forward<Args>(args)...);
268 out.
fatal(CALL_INFO, -1,
"can't find requested statistic %s.\n%s\n", type.c_str(), sstr.str().c_str());
283 bool hasLibrary(
const std::string& elemlib, std::ostream& err_os);
284 void requireLibrary(
const std::string& elemlib, std::ostream& err_os);
289 void requireLibrary(
const std::string& elemlib);
291 void getLoadedLibraryNames(std::set<std::string>& lib_names);
292 void loadUnloadedLibraries(
const std::set<std::string>& lib_names);
294 const std::string& getSearchPaths();
317 uint8_t GetStatisticValidityAndEnableLevel(
const std::string& type,
const std::string& statistic_name);
327 const std::string& type,
const std::string& input_file,
int verbose,
Config& cfg,
double start_time);
329 explicit Factory(
const std::string& searchPaths);
332 friend int ::main(
int argc,
char** argv);
335 void notFound(
const std::string& baseName,
const std::string& type,
const std::string& errorMsg);
345 bool findLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
347 bool loadLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
349 std::set<std::string> loaded_libraries;
351 std::string searchPaths;
354 std::string loadingComponentType;
356 static std::pair<std::string, std::string> parseLoadName(
const std::string& wholename);
358 std::recursive_mutex factoryMutex;
366 #endif // SST_CORE_FACTORY_H Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:57
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:156
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
Class to contain SST Simulation Configuration variables.
Definition: config.h:51
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: factory.h:107
Main component object for the simulation.
Definition: component.h:30
SSTElementPythonModule * getPythonModule(const std::string &name)
Return Python Module creation function.
Definition: factory.cc:572
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:251
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:46
Definition: simpleInfo.h:87
bool hasLibrary(const std::string &elemlib, std::ostream &err_os)
hasLibrary Checks to see if library exists and can be loaded
Definition: factory.cc:598
Class to load Element Libraries.
Definition: elemLoader.h:23
Component * CreateComponent(ComponentId_t id, const std::string &componentname, Params ¶ms)
Attempt to create a new Component instantiation.
Definition: factory.cc:215
Partition::SSTPartitioner * CreatePartitioner(const std::string &name, RankInfo total_ranks, RankInfo my_rank, int verbosity)
Return partitioner function.
Definition: factory.cc:538
Base * CreateWithParams(const std::string &type, SST::Params ¶ms, CtorArgs &&... args)
General function to create a given base class.
Definition: factory.h:212
void pushAllowedKeys(const std::vector< std::string > &keys)
Definition: params.cc:242
void RequireEvent(const std::string &eventname)
Ensure that an element library containing the required event is loaded.
Definition: factory.cc:527
bool isProfilePointValid(const std::string &type, const std::string &point)
Get a list of allowed ports for a given component type.
Definition: factory.cc:458
Definition: rankInfo.h:23
Main component object for the simulation.
Definition: baseComponent.h:64
Base class for Partitioning graphs.
Definition: sstpart.h:31
Parameter store.
Definition: params.h:63
void popAllowedKeys()
Removes the most recent set of keys considered allowed.
Definition: params.cc:252
Base class for Model Generation.
Definition: sstmodel.h:29
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:54
Base class for python modules in element libraries.
Definition: element_python.h:132
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
Base * Create(const std::string &type, CtorArgs &&... args)
General function to create a given base class.
Definition: factory.h:167
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
bool DoesSubComponentSlotExist(const std::string &type, const std::string &slotName)
Determine if a SubComponentSlot is defined in a components ElementInfoSubComponentSlot.
Definition: factory.cc:253