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"
18 #include "sst/core/sstpart.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);
73 bool doesSubComponentExist(
const std::string& type);
89 std::string elemlib, elem;
90 std::tie(elemlib, elem) = parseLoadName(type);
92 requireLibrary(elemlib);
93 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
95 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
97 auto map = lib->getMap();
98 auto* info = lib->getInfo(elem);
100 auto* builderLib = Base::getBuilderLibrary(elemlib);
102 auto* fact = builderLib->getBuilder(elem);
103 if ( fact ) {
return true; }
110 template <
class Base,
int index,
class InfoType>
111 const InfoType& getSimpleInfo(
const std::string& type)
113 static InfoType invalid_ret;
114 std::string elemlib, elem;
115 std::tie(elemlib, elem) = parseLoadName(type);
117 std::stringstream err_os;
118 requireLibrary(elemlib, err_os);
119 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
121 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
123 auto* info = lib->getInfo(elem);
128 if ( cast_info ) {
return cast_info->getSimpleInfo(); }
142 template <
class Base,
class... CtorArgs>
143 Base*
Create(
const std::string& type, CtorArgs&&... args)
145 std::string elemlib, elem;
146 std::tie(elemlib, elem) = parseLoadName(type);
148 std::stringstream err_os;
149 requireLibrary(elemlib, err_os);
150 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
152 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
154 auto* info = lib->getInfo(elem);
156 auto* builderLib = Base::getBuilderLibrary(elemlib);
158 auto* fact = builderLib->getBuilder(elem);
160 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
166 notFound(Base::ELI_baseName(), type, err_os.str());
170 template <
class T,
class... ARGS>
171 T* CreateProfileTool(
const std::string& type, ARGS... args)
173 return Factory::getFactory()->Create<T>(type, args...);
187 template <
class Base,
class... CtorArgs>
190 std::string elemlib, elem;
191 std::tie(elemlib, elem) = parseLoadName(type);
193 std::stringstream err_os;
194 requireLibrary(elemlib, err_os);
195 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
197 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
199 auto map = lib->getMap();
200 auto* info = lib->getInfo(elem);
202 auto* builderLib = Base::getBuilderLibrary(elemlib);
204 auto* fact = builderLib->getBuilder(elem);
207 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
214 notFound(Base::ELI_baseName(), type, err_os.str());
226 template <
class T,
class... Args>
228 const std::string& type,
BaseComponent* comp,
const std::string& statName,
const std::string& stat,
229 Params& params, Args... args)
231 std::string elemlib, elem;
232 std::tie(elemlib, elem) = parseLoadName(type);
234 std::stringstream sstr;
235 requireLibrary(elemlib, sstr);
237 auto* lib = ELI::BuilderDatabase::getLibrary<Statistics::Statistic<T>, Args...>(elemlib);
239 auto* fact = lib->getFactory(elem);
240 if ( fact ) {
return fact->create(comp, statName, stat, params, std::forward<Args>(args)...); }
243 out.
fatal(CALL_INFO, -1,
"can't find requested statistic %s.\n%s\n", type.c_str(), sstr.str().c_str());
258 bool hasLibrary(
const std::string& elemlib, std::ostream& err_os);
259 void requireLibrary(
const std::string& elemlib, std::ostream& err_os);
264 void requireLibrary(
const std::string& elemlib);
266 void getLoadedLibraryNames(std::set<std::string>& lib_names);
267 void loadUnloadedLibraries(
const std::set<std::string>& lib_names);
283 const std::vector<std::string>& GetValidStatistics(
const std::string& compType);
307 friend int ::main(
int argc,
char** argv);
309 void notFound(
const std::string& baseName,
const std::string& type,
const std::string& errorMsg);
311 Factory(
const std::string& searchPaths);
316 void operator=(
Factory const&);
321 bool findLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
323 bool loadLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
325 std::set<std::string> loaded_libraries;
327 std::string searchPaths;
330 std::string loadingComponentType;
332 std::pair<std::string, std::string> parseLoadName(
const std::string& wholename);
334 std::recursive_mutex factoryMutex;
Main component object for the simulation.
Definition: baseComponent.h:52
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:44
void RequireEvent(const std::string &eventname)
Ensure that an element library containing the required event is loaded.
Definition: factory.cc:453
Partition::SSTPartitioner * CreatePartitioner(const std::string &name, RankInfo total_ranks, RankInfo my_rank, int verbosity)
Return partitioner function.
Definition: factory.cc:464
bool DoesSubComponentSlotExist(const std::string &type, const std::string &slotName)
Determine if a SubComponentSlot is defined in a components ElementInfoStatistic.
Definition: factory.cc:226
SSTElementPythonModule * getPythonModule(const std::string &name)
Return Python Module creation function.
Definition: factory.cc:497
Component * CreateComponent(ComponentId_t id, const std::string &componentname, Params ¶ms)
Attempt to create a new Component instantiation.
Definition: factory.cc:188
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:360
Base * Create(const std::string &type, CtorArgs &&... args)
General function to create a given base class.
Definition: factory.h:143
bool hasLibrary(const std::string &elemlib, std::ostream &err_os)
hasLibrary Checks to see if library exists and can be loaded
Definition: factory.cc:523
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:316
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:227
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:98
bool DoesComponentInfoStatisticNameExist(const std::string &type, const std::string &statisticName)
Determine if a statistic is defined in a components ElementInfoStatistic.
Definition: factory.cc:306
Base * CreateWithParams(const std::string &type, SST::Params ¶ms, CtorArgs &&... args)
General function to create a given base class.
Definition: factory.h:188
const Params::KeySet_t & getParamNames(const std::string &type)
Get a list of allowed param keys for a given component type.
Definition: factory.cc:149
bool isProfilePointValid(const std::string &type, const std::string &point)
Get a list of allowed ports for a given component type.
Definition: factory.cc:389
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: factory.h:87
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:159
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