12 #ifndef SST_CORE_BASECOMPONENT_H 13 #define SST_CORE_BASECOMPONENT_H 15 #include "sst/core/clock.h" 16 #include "sst/core/componentInfo.h" 17 #include "sst/core/eli/elementinfo.h" 18 #include "sst/core/event.h" 19 #include "sst/core/factory.h" 20 #include "sst/core/oneshot.h" 21 #include "sst/core/profile/componentProfileTool.h" 22 #include "sst/core/sst_types.h" 23 #include "sst/core/statapi/statbase.h" 24 #include "sst/core/statapi/statengine.h" 25 #include "sst/core/warnmacros.h" 35 class ComponentExtension;
42 class Simulation_impl;
44 class SubComponentSlotInfo;
63 const std::string& ,
const std::string& ,
Params&)>;
72 const std::string& getType()
const {
return my_info->getType(); }
75 inline ComponentId_t
getId()
const {
return my_info->id; }
86 inline const std::string&
getName()
const {
return my_info->getName(); }
95 virtual void init(
unsigned int UNUSED(phase)) {}
99 virtual void complete(
unsigned int UNUSED(phase)) {}
121 SimTime_t getCurrentSimCycle()
const;
123 int getCurrentPriority()
const;
127 SimTime_t getEndSimCycle()
const;
135 Output& getSimulationOutput()
const;
145 SimTime_t getCurrentSimTime(
const std::string& base)
const;
148 SimTime_t getCurrentSimTimeNano()
const;
150 SimTime_t getCurrentSimTimeMicro()
const;
152 SimTime_t getCurrentSimTimeMilli()
const;
159 double getRunPhaseElapsedRealTime()
const;
166 double getInitPhaseElapsedRealTime()
const;
173 double getCompletePhaseElapsedRealTime()
const;
180 bool isSimulationRunModeInit()
const;
185 bool isSimulationRunModeRun()
const;
190 bool isSimulationRunModeBoth()
const;
197 std::string& getOutputDirectory()
const;
214 void requireLibrary(
const std::string& name);
218 bool isPortConnected(
const std::string& name)
const;
234 Link* configureLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
264 configureSelfLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
341 TimeConverter* registerTimeBase(
const std::string& base,
bool regAll =
true);
343 TimeConverter* getTimeConverter(
const std::string& base)
const;
346 bool isStatisticShared(
const std::string& statName,
bool include_me =
false)
349 if ( doesComponentInfoStatisticExist(statName) ) {
return true; }
351 if ( my_info->sharesStatistics() ) {
352 return my_info->parent_info->component->isStatisticShared(statName,
true);
370 template <
typename T>
371 Statistics::Statistic<T>*
372 createStatistic(
SST::Params& params, StatisticId_t
id,
const std::string& name,
const std::string& statSubId)
380 StatCreateFunction create = [=](BaseComponent* comp, Statistics::StatisticProcessingEngine* engine,
381 const std::string& type,
const std::string& name,
const std::string& subId,
382 SST::Params& params) -> Statistics::StatisticBase* {
383 return engine->createStatistic<T>(comp, type, name, subId, params);
390 Statistics::StatisticBase* base_stat =
391 id == STATALL_ID ? createEnabledAllStatistic(params, name, statSubId, std::move(create))
392 : getParentComponent()->createExplicitlyEnabledStatistic(
393 params, id, name, statSubId,
std::move(create));
396 auto* statistic =
dynamic_cast<Statistics::Statistic<T>*
>(base_stat);
397 if ( statistic ) {
return statistic; }
400 __LINE__, __FILE__,
"createStatistic", 1,
"failed to cast created statistic '%s' to expected type",
406 template <
typename T>
407 Statistics::Statistic<T>*
408 createNullStatistic(
SST::Params& params,
const std::string& name,
const std::string& statSubId =
"")
410 auto* engine = getStatEngine();
411 return engine->createStatistic<T>(my_info->component,
"sst.NullStatistic", name, statSubId, params);
414 template <
typename T>
415 Statistics::Statistic<T>*
416 registerStatistic(
SST::Params& params,
const std::string& statName,
const std::string& statSubId,
bool inserting)
418 if ( my_info->enabledStatNames ) {
419 auto iter = my_info->enabledStatNames->find(statName);
420 if ( iter != my_info->enabledStatNames->end() ) {
424 StatisticId_t
id = iter->second;
425 return createStatistic<T>(params, id, statName, statSubId);
430 if ( inserting || doesComponentInfoStatisticExist(statName) ) {
432 if ( my_info->enabledAllStats ) {
return createStatistic<T>(params, STATALL_ID, statName, statSubId); }
433 else if ( my_info->parent_info && my_info->canInsertStatistics() ) {
437 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId,
true);
441 return my_info->component->createNullStatistic<T>(params, statName, statSubId);
444 else if ( my_info->parent_info && my_info->sharesStatistics() ) {
447 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId,
false);
452 __LINE__, __FILE__,
"registerStatistic", 1,
"attempting to register unknown statistic '%s'",
476 template <
typename T>
477 Statistics::Statistic<T>*
480 return registerStatistic<T>(params, statName, statSubId,
false);
483 template <
typename T>
487 return registerStatistic<T>(empty, statName, statSubId,
false);
490 template <
typename... Args>
491 Statistics::Statistic<std::tuple<Args...>>*
492 registerMultiStatistic(
const std::string& statName,
const std::string& statSubId =
"")
495 return registerStatistic<std::tuple<Args...>>(empty, statName, statSubId,
false);
498 template <
typename... Args>
499 Statistics::Statistic<std::tuple<Args...>>*
500 registerMultiStatistic(
SST::Params& params,
const std::string& statName,
const std::string& statSubId =
"")
502 return registerStatistic<std::tuple<Args...>>(params, statName, statSubId,
false);
505 template <
typename T>
506 Statistics::Statistic<T>* registerStatistic(
const char* statName,
const char* statSubId =
"")
508 return registerStatistic<T>(std::string(statName), std::string(statSubId));
515 void performStatisticOutput(Statistics::StatisticBase* stat);
522 void performGlobalStatisticOutput();
529 template <
typename T>
532 std::string full_point_name = getType() +
"." + pointName;
533 auto tools = getComponentProfileTools(full_point_name);
534 if ( tools.size() == 0 )
return nullptr;
536 typename T::ProfilePoint* ret =
new typename T::ProfilePoint();
537 for (
auto* x : tools ) {
538 T* tool =
dynamic_cast<T*
>(x);
539 if (
nullptr == tool ) {
542 CALL_INFO_LONG, 1,
"ERROR: wrong type of profiling tool for profiling point %s)\n",
545 ret->registerProfilePoint(tool, pointName, getId(), getName(), getType());
555 template <
class T,
class... ARGS>
560 return Factory::getFactory()->CreateWithParams<T>(type, params, params, args...);
569 template <
class T,
class... ARGS>
570 T* loadComponentExtension(ARGS... args)
573 return static_cast<T*
>(ret);
585 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
603 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
606 for (
auto& ci : subcomps ) {
607 if ( ci.second.getSlotName() == slot_name ) {
608 index = ci.second.getSlotNum();
613 if ( sub_count > 1 ) {
617 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
618 slot_name.c_str(), my_info->getType().c_str(), sub_count);
621 return isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, index);
640 template <
class T,
class... ARGS>
642 const std::string& type,
const std::string& slot_name,
int slot_num, uint64_t share_flags,
Params& params,
646 share_flags = share_flags & ComponentInfo::USER_FLAGS;
647 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
651 if ( sub_info ==
nullptr )
return nullptr;
654 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
655 auto ret = Factory::getFactory()->CreateWithParams<T>(type, params, sub_info->id, params, args...);
675 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
691 template <
class T,
class... ARGS>
698 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
701 for (
auto& ci : subcomps ) {
702 if ( ci.second.getSlotName() == slot_name ) {
703 index = ci.second.getSlotNum();
708 if ( sub_count > 1 ) {
712 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
713 slot_name.c_str(), my_info->getType().c_str(), sub_count);
716 return loadUserSubComponentByIndex<T, ARGS...>(slot_name, index, share_flags, args...);
739 void fatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, ...) const
740 __attribute__((format(printf, 6, 7)));
766 bool condition, uint32_t line, const
char* file, const
char* func,
int exit_code, const
char* format, ...) const
767 __attribute__((format(printf, 7, 8)));
770 SimTime_t processCurrentTimeWithUnderflowedBase(const
std::
string& base) const;
784 SST::
Params& params, StatisticId_t
id, const
std::
string& name, const
std::
string& statSubId,
785 StatCreateFunction create);
798 const
std::
string& statSubId,
bool check_load_level, StatCreateFunction create);
801 SST::
Params& params, const
std::
string& name, const
std::
string& statSubId, StatCreateFunction create);
803 void configureAllowedStatParams(
SST::
Params& params);
807 void pushValidParams(
Params& params, const
std::
string& type);
809 template <class T, class... ARGS>
810 T* loadUserSubComponentByIndex(const
std::
string& slot_name,
int slot_num,
int share_flags, ARGS... args)
813 share_flags = share_flags & ComponentInfo::USER_FLAGS;
816 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
817 if ( sub_info ==
nullptr )
return nullptr;
818 sub_info->share_flags = share_flags;
819 sub_info->parent_info = my_info;
821 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
822 auto ret = Factory::getFactory()->CreateWithParams<T>(
823 sub_info->type, *sub_info->params, sub_info->id, *sub_info->params, args...);
830 bool isUserSubComponentLoadableUsingAPIByIndex(
const std::string& slot_name,
int slot_num)
833 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
834 if ( sub_info ==
nullptr )
return false;
836 return isSubComponentLoadableUsingAPI<T>(sub_info->type);
841 vfatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, va_list arg)
const;
847 SubComponentSlotInfo* getSubComponentSlotInfo(
const std::string& name,
bool fatalOnEmptyIndex =
false);
850 const std::vector<double>&
getCoordinates()
const {
return my_info->coordinates; }
856 bool isAnonymous() {
return my_info->isAnonymous(); }
858 bool isUser() {
return my_info->isUser(); }
863 TimeConverter* getDefaultTimeBase() {
return my_info->defaultTimeBase; }
865 const TimeConverter* getDefaultTimeBase()
const {
return my_info->defaultTimeBase; }
867 bool doesSubComponentExist(
const std::string& type);
870 bool doesComponentInfoStatisticExist(
const std::string& statisticName)
const;
872 uint8_t getComponentInfoStatisticEnableLevel(
const std::string& statisticName)
const;
876 std::vector<Profile::ComponentProfileTool*> getComponentProfileTools(
const std::string& point);
879 ComponentInfo* my_info =
nullptr;
880 Simulation_impl* sim_ =
nullptr;
881 bool isExtension =
false;
885 std::vector<Clock::HandlerBase*> clock_handlers;
887 void addSelfLink(
const std::string& name);
888 Link* getLinkFromParentSharedPort(
const std::string& port);
890 using StatNameMap = std::map<std::string, std::map<std::string, Statistics::StatisticBase*>>;
892 std::map<StatisticId_t, Statistics::StatisticBase*> m_explicitlyEnabledSharedStats;
893 std::map<StatisticId_t, StatNameMap> m_explicitlyEnabledUniqueStats;
894 StatNameMap m_enabledAllStats;
896 BaseComponent* getParentComponent()
898 ComponentInfo* base_info = my_info;
899 while ( base_info->parent_info ) {
900 base_info = base_info->parent_info;
902 return base_info->component;
915 std::string slot_name;
923 const std::map<ComponentId_t, ComponentInfo>& subcomps = comp->my_info->getSubComponents();
927 for (
auto& ci : subcomps ) {
928 if ( ci.second.getSlotName() == slot_name ) {
929 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
930 max_slot_index = ci.second.getSlotNum();
936 const std::string& getSlotName()
const {
return slot_name; };
938 bool isPopulated(
int slot_num)
const 940 if ( slot_num > max_slot_index )
return false;
941 if ( comp->my_info->findSubComponent(slot_name, slot_num) == nullptr )
return false;
945 bool isAllPopulated()
const 947 for (
int i = 0; i < max_slot_index; ++i ) {
948 if ( comp->my_info->findSubComponent(slot_name, i) == nullptr )
return false;
953 int getMaxPopulatedSlotNumber()
const {
return max_slot_index; }
965 return comp->isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, slot_num);
984 template <
typename T>
988 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
1005 template <
class T,
class... ARGS>
1006 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const 1008 return comp->loadUserSubComponentByIndex<T, ARGS...>(slot_name, slot_num, share_flags, args...);
1029 template <
typename T,
class... ARGS>
1030 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const 1032 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1033 T* sub = create<T>(i, share_flags, args...);
1055 template <
typename T,
class... ARGS>
1056 void createAllSparse(std::vector<std::pair<int, T*>>& vec, uint64_t share_flags, ARGS... args)
const 1058 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1059 T* sub = create<T>(i, share_flags, args...);
1060 if ( sub !=
nullptr ) vec.push_back(i, sub);
1080 template <
typename T,
class... ARGS>
1083 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1084 T* sub = create<T>(i, share_flags, args...);
1085 if ( sub !=
nullptr ) vec.push_back(sub);
1091 namespace Serialization {
1102 switch ( ser.mode() ) {
1103 case serializer::SIZER:
1104 case serializer::PACK:
1110 case serializer::UNPACK:
1115 s = Factory::getFactory()->CreateWithParams<
Statistic<T>>(
1116 "sst.NullStatistic", params, comp,
"",
"", params);
1128 #endif // SST_CORE_BASECOMPONENT_H Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:53
ComponentId_t getId() const
Returns unique component ID.
Definition: baseComponent.h:75
virtual void complete(unsigned int UNUSED(phase))
Used during the complete phase after the end of simulation.
Definition: baseComponent.h:99
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:210
const std::string & getParentComponentName() const
Returns the name of the parent Component, or, if called on a Component, the name of that Component...
Definition: baseComponent.h:90
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:160
virtual void printStatus(Output &UNUSED(out))
Called by the Simulation to request that the component print it's current status. ...
Definition: baseComponent.h:116
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: baseComponent.h:583
T::ProfilePoint * registerProfilePoint(const std::string &pointName)
Registers a profiling point.
Definition: baseComponent.h:530
SSTHandlerBase< bool, Cycle_t > HandlerBase
Base handler for clock functions.
Definition: clock.h:42
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:27
Main component object for the simulation.
Definition: component.h:30
virtual void finish()
Called after complete phase, but before objects are destroyed.
Definition: baseComponent.h:106
T * create(int slot_num, uint64_t share_flags, ARGS... args) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:1006
T * loadUserSubComponent(const std::string &slot_name)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:673
Base serialize class.
Definition: serialize.h:32
Forms the base class for statistics gathering within SST.
Definition: statbase.h:64
ComponentExtension is a class that can be loaded using loadComponentExtension<T>(...).
Definition: componentExtension.h:28
virtual void emergencyShutdown(void)
Called when SIGINT or SIGTERM has been seen.
Definition: baseComponent.h:83
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:44
Definition: serializable.h:118
virtual void setup()
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: baseComponent.h:103
bool isUserSubComponentLoadableUsingAPI(const std::string &slot_name)
Check to see if the element type loaded by the user into the.
Definition: baseComponent.h:598
BaseComponent * getComponent() const
Return a pointer to the parent Component.
Definition: statbase.h:144
Serialization "gateway" object.
Definition: serialize.h:110
void createAll(std::vector< T *> &vec, uint64_t share_flags, ARGS... args) const
Create all user defined subcomponents (defined in input file to SST run) for the slot.
Definition: baseComponent.h:1030
Definition: rankInfo.h:21
T * loadModule(const std::string &type, Params ¶ms, ARGS... args)
Loads a module from an element Library.
Definition: baseComponent.h:556
T * loadAnonymousSubComponent(const std::string &type, const std::string &slot_name, int slot_num, uint64_t share_flags, Params ¶ms, ARGS... args)
Loads an anonymous subcomponent (not defined in input file to SST run).
Definition: baseComponent.h:641
Main component object for the simulation.
Definition: baseComponent.h:51
bool isLoadableUsingAPI(int slot_num)
Check to see if the element type loaded by the user into the specified slot index is loadable with a ...
Definition: baseComponent.h:963
void createAllSparse(std::vector< std::pair< int, T *>> &vec, uint64_t share_flags, ARGS... args) const
Create all user defined subcomponents (defined in input file to SST run) for the slot.
Definition: baseComponent.h:1056
Statistics::Statistic< T > * registerStatistic(SST::Params ¶ms, const std::string &statName, const std::string &statSubId="")
Registers a statistic.
Definition: baseComponent.h:478
SimTime_t getCurrentSimTime() const
return the time since the simulation began in the default timebase
Definition: baseComponent.h:142
virtual bool Status()
Currently unused function.
Definition: baseComponent.h:109
Parameter store.
Definition: params.h:55
T * loadUserSubComponent(const std::string &slot_name, uint64_t share_flags, ARGS... args)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:692
T * create(int slot_num) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:985
Definition: componentInfo.h:40
Used to load SubComponents when multiple SubComponents are loaded into a single slot (will also also ...
Definition: baseComponent.h:911
void createAllSparse(std::vector< T *> &vec, uint64_t share_flags, ARGS... args) const
Create all user defined subcomponents (defined in input file to SST run) for the slot.
Definition: baseComponent.h:1081
uint8_t getStatisticLoadLevel() const
Returns Component Statistic load level.
Definition: baseComponent.h:78
Definition: componentInfo.h:36
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:51
Performs Unit math in full precision.
Definition: unitAlgebra.h:106
void setDefaultTimeBase(TimeConverter *tc)
Manually set the default detaulTimeBase.
Definition: baseComponent.h:861
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:28
const std::vector< double > & getCoordinates() const
Retrieve the X,Y,Z coordinates of this component.
Definition: baseComponent.h:850
const std::string & getName() const
Returns Component/SubComponent Name.
Definition: baseComponent.h:86
Link between two components.
Definition: link.h:50
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:95