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/serialization/serializable_base.h" 23 #include "sst/core/serialization/serialize.h" 24 #include "sst/core/sst_types.h" 25 #include "sst/core/statapi/statbase.h" 26 #include "sst/core/statapi/statengine.h" 27 #include "sst/core/warnmacros.h" 37 class ComponentExtension;
44 class Simulation_impl;
46 class SubComponentSlotInfo;
52 namespace Serialization {
54 class SerializeBaseComponentHelper;
74 const std::string& ,
const std::string& ,
Params&)>;
83 const std::string& getType()
const {
return my_info->getType(); }
86 inline ComponentId_t
getId()
const {
return my_info->id; }
97 inline const std::string&
getName()
const {
return my_info->getName(); }
106 virtual void init(
unsigned int UNUSED(phase)) {}
110 virtual void complete(
unsigned int UNUSED(phase)) {}
132 SimTime_t getCurrentSimCycle()
const;
134 int getCurrentPriority()
const;
138 SimTime_t getEndSimCycle()
const;
146 Output& getSimulationOutput()
const;
156 SimTime_t getCurrentSimTime(
const std::string& base)
const;
159 SimTime_t getCurrentSimTimeNano()
const;
161 SimTime_t getCurrentSimTimeMicro()
const;
163 SimTime_t getCurrentSimTimeMilli()
const;
170 double getRunPhaseElapsedRealTime()
const;
177 double getInitPhaseElapsedRealTime()
const;
184 double getCompletePhaseElapsedRealTime()
const;
191 bool isSimulationRunModeInit()
const;
196 bool isSimulationRunModeRun()
const;
201 bool isSimulationRunModeBoth()
const;
208 std::string& getOutputDirectory()
const;
225 void requireLibrary(
const std::string& name);
229 bool isPortConnected(
const std::string& name)
const;
245 Link* configureLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
275 configureSelfLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
352 TimeConverter* registerTimeBase(
const std::string& base,
bool regAll =
true);
354 TimeConverter* getTimeConverter(
const std::string& base)
const;
357 bool isStatisticShared(
const std::string& statName,
bool include_me =
false)
360 if ( doesComponentInfoStatisticExist(statName) ) {
return true; }
362 if ( my_info->sharesStatistics() ) {
363 return my_info->parent_info->component->isStatisticShared(statName,
true);
370 void initiateInteractive(
const std::string& msg);
383 template <
typename T>
384 Statistics::Statistic<T>*
385 createStatistic(
SST::Params& params, StatisticId_t
id,
const std::string& name,
const std::string& statSubId)
393 StatCreateFunction create = [=](BaseComponent* comp, Statistics::StatisticProcessingEngine* engine,
394 const std::string& type,
const std::string& name,
const std::string& subId,
395 SST::Params& params) -> Statistics::StatisticBase* {
396 return engine->createStatistic<T>(comp, type, name, subId, params);
403 Statistics::StatisticBase* base_stat =
404 id == STATALL_ID ? createEnabledAllStatistic(params, name, statSubId, std::move(create))
405 : getParentComponent()->createExplicitlyEnabledStatistic(
406 params, id, name, statSubId,
std::move(create));
409 auto* statistic =
dynamic_cast<Statistics::Statistic<T>*
>(base_stat);
410 if ( statistic ) {
return statistic; }
413 __LINE__, __FILE__,
"createStatistic", 1,
"failed to cast created statistic '%s' to expected type",
419 template <
typename T>
420 Statistics::Statistic<T>*
421 createNullStatistic(
SST::Params& params,
const std::string& name,
const std::string& statSubId =
"")
423 auto* engine = getStatEngine();
424 return engine->createStatistic<T>(my_info->component,
"sst.NullStatistic", name, statSubId, params);
427 template <
typename T>
428 Statistics::Statistic<T>*
429 registerStatistic(
SST::Params& params,
const std::string& statName,
const std::string& statSubId,
bool inserting)
431 if ( my_info->enabledStatNames ) {
432 auto iter = my_info->enabledStatNames->find(statName);
433 if ( iter != my_info->enabledStatNames->end() ) {
437 StatisticId_t
id = iter->second;
438 return createStatistic<T>(params, id, statName, statSubId);
443 if ( inserting || doesComponentInfoStatisticExist(statName) ) {
445 if ( my_info->enabledAllStats ) {
return createStatistic<T>(params, STATALL_ID, statName, statSubId); }
446 else if ( my_info->parent_info && my_info->canInsertStatistics() ) {
450 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId,
true);
454 return my_info->component->createNullStatistic<T>(params, statName, statSubId);
457 else if ( my_info->parent_info && my_info->sharesStatistics() ) {
460 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId,
false);
465 __LINE__, __FILE__,
"registerStatistic", 1,
"attempting to register unknown statistic '%s'",
489 template <
typename T>
490 Statistics::Statistic<T>*
493 return registerStatistic<T>(params, statName, statSubId,
false);
496 template <
typename T>
500 return registerStatistic<T>(empty, statName, statSubId,
false);
503 template <
typename... Args>
504 Statistics::Statistic<std::tuple<Args...>>*
505 registerMultiStatistic(
const std::string& statName,
const std::string& statSubId =
"")
508 return registerStatistic<std::tuple<Args...>>(empty, statName, statSubId,
false);
511 template <
typename... Args>
512 Statistics::Statistic<std::tuple<Args...>>*
513 registerMultiStatistic(
SST::Params& params,
const std::string& statName,
const std::string& statSubId =
"")
515 return registerStatistic<std::tuple<Args...>>(params, statName, statSubId,
false);
518 template <
typename T>
519 Statistics::Statistic<T>* registerStatistic(
const char* statName,
const char* statSubId =
"")
521 return registerStatistic<T>(std::string(statName), std::string(statSubId));
528 void performStatisticOutput(Statistics::StatisticBase* stat);
535 void performGlobalStatisticOutput();
542 template <
typename T>
545 std::string full_point_name = getType() +
"." + pointName;
546 auto tools = getComponentProfileTools(full_point_name);
547 if ( tools.size() == 0 )
return nullptr;
549 typename T::ProfilePoint* ret =
new typename T::ProfilePoint();
550 for (
auto* x : tools ) {
551 T* tool =
dynamic_cast<T*
>(x);
552 if (
nullptr == tool ) {
555 CALL_INFO_LONG, 1,
"ERROR: wrong type of profiling tool for profiling point %s)\n",
558 ret->registerProfilePoint(tool, pointName, getId(), getName(), getType());
568 template <
class T,
class... ARGS>
573 return Factory::getFactory()->CreateWithParams<T>(type, params, params, args...);
582 template <
class T,
class... ARGS>
583 T* loadComponentExtension(ARGS... args)
586 return static_cast<T*
>(ret);
598 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
616 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
619 for (
auto& ci : subcomps ) {
620 if ( ci.second.getSlotName() == slot_name ) {
621 index = ci.second.getSlotNum();
626 if ( sub_count > 1 ) {
630 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
631 slot_name.c_str(), my_info->getType().c_str(), sub_count);
634 return isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, index);
653 template <
class T,
class... ARGS>
655 const std::string& type,
const std::string& slot_name,
int slot_num, uint64_t share_flags,
Params& params,
659 share_flags = share_flags & ComponentInfo::USER_FLAGS;
660 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
664 if ( sub_info ==
nullptr )
return nullptr;
667 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
668 auto ret = Factory::getFactory()->CreateWithParams<T>(type, params, sub_info->id, params, args...);
688 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
704 template <
class T,
class... ARGS>
711 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
714 for (
auto& ci : subcomps ) {
715 if ( ci.second.getSlotName() == slot_name ) {
716 index = ci.second.getSlotNum();
721 if ( sub_count > 1 ) {
725 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
726 slot_name.c_str(), my_info->getType().c_str(), sub_count);
729 return loadUserSubComponentByIndex<T, ARGS...>(slot_name, index, share_flags, args...);
752 void fatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, ...) const
753 __attribute__((format(printf, 6, 7)));
779 bool condition, uint32_t line, const
char* file, const
char* func,
int exit_code, const
char* format, ...) const
780 __attribute__((format(printf, 7, 8)));
783 SimTime_t processCurrentTimeWithUnderflowedBase(const
std::
string& base) const;
797 SST::
Params& params, StatisticId_t
id, const
std::
string& name, const
std::
string& statSubId,
798 StatCreateFunction create);
811 const
std::
string& statSubId,
bool check_load_level, StatCreateFunction create);
814 SST::
Params& params, const
std::
string& name, const
std::
string& statSubId, StatCreateFunction create);
816 void configureAllowedStatParams(
SST::
Params& params);
820 void pushValidParams(
Params& params, const
std::
string& type);
822 template <class T, class... ARGS>
823 T* loadUserSubComponentByIndex(const
std::
string& slot_name,
int slot_num,
int share_flags, ARGS... args)
826 share_flags = share_flags & ComponentInfo::USER_FLAGS;
829 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
830 if ( sub_info ==
nullptr )
return nullptr;
831 sub_info->share_flags = share_flags;
832 sub_info->parent_info = my_info;
834 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
835 auto ret = Factory::getFactory()->CreateWithParams<T>(
836 sub_info->type, *sub_info->params, sub_info->id, *sub_info->params, args...);
843 bool isUserSubComponentLoadableUsingAPIByIndex(
const std::string& slot_name,
int slot_num)
846 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
847 if ( sub_info ==
nullptr )
return false;
849 return isSubComponentLoadableUsingAPI<T>(sub_info->type);
854 vfatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, va_list arg)
const;
860 SubComponentSlotInfo* getSubComponentSlotInfo(
const std::string& name,
bool fatalOnEmptyIndex =
false);
863 const std::vector<double>&
getCoordinates()
const {
return my_info->coordinates; }
869 bool isAnonymous() {
return my_info->isAnonymous(); }
871 bool isUser() {
return my_info->isUser(); }
876 TimeConverter* getDefaultTimeBase() {
return my_info->defaultTimeBase; }
878 const TimeConverter* getDefaultTimeBase()
const {
return my_info->defaultTimeBase; }
880 bool doesSubComponentExist(
const std::string& type);
883 bool doesComponentInfoStatisticExist(
const std::string& statisticName)
const;
885 uint8_t getComponentInfoStatisticEnableLevel(
const std::string& statisticName)
const;
889 std::vector<Profile::ComponentProfileTool*> getComponentProfileTools(
const std::string& point);
892 friend class Core::Serialization::pvt::SerializeBaseComponentHelper;
895 ComponentInfo* my_info =
nullptr;
896 Simulation_impl* sim_ =
nullptr;
897 bool isExtension =
false;
901 std::vector<Clock::HandlerBase*> clock_handlers;
903 void addSelfLink(
const std::string& name);
904 Link* getLinkFromParentSharedPort(
const std::string& port);
906 using StatNameMap = std::map<std::string, std::map<std::string, Statistics::StatisticBase*>>;
908 std::map<StatisticId_t, Statistics::StatisticBase*> m_explicitlyEnabledSharedStats;
909 std::map<StatisticId_t, StatNameMap> m_explicitlyEnabledUniqueStats;
910 StatNameMap m_enabledAllStats;
912 BaseComponent* getParentComponent()
914 ComponentInfo* base_info = my_info;
915 while ( base_info->parent_info ) {
916 base_info = base_info->parent_info;
918 return base_info->component;
931 std::string slot_name;
939 const std::map<ComponentId_t, ComponentInfo>& subcomps = comp->my_info->getSubComponents();
943 for (
auto& ci : subcomps ) {
944 if ( ci.second.getSlotName() == slot_name ) {
945 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
946 max_slot_index = ci.second.getSlotNum();
952 const std::string& getSlotName()
const {
return slot_name; };
954 bool isPopulated(
int slot_num)
const 956 if ( slot_num > max_slot_index )
return false;
957 if ( comp->my_info->findSubComponent(slot_name, slot_num) == nullptr )
return false;
961 bool isAllPopulated()
const 963 for (
int i = 0; i < max_slot_index; ++i ) {
964 if ( comp->my_info->findSubComponent(slot_name, i) == nullptr )
return false;
969 int getMaxPopulatedSlotNumber()
const {
return max_slot_index; }
981 return comp->isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, slot_num);
1000 template <
typename T>
1004 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
1021 template <
class T,
class... ARGS>
1022 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const 1024 return comp->loadUserSubComponentByIndex<T, ARGS...>(slot_name, slot_num, share_flags, args...);
1045 template <
typename T,
class... ARGS>
1046 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const 1048 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1049 T* sub = create<T>(i, share_flags, args...);
1071 template <
typename T,
class... ARGS>
1072 void createAllSparse(std::vector<std::pair<int, T*>>& vec, uint64_t share_flags, ARGS... args)
const 1074 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1075 T* sub = create<T>(i, share_flags, args...);
1076 if ( sub !=
nullptr ) vec.push_back(i, sub);
1096 template <
typename T,
class... ARGS>
1099 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1100 T* sub = create<T>(i, share_flags, args...);
1101 if ( sub !=
nullptr ) vec.push_back(sub);
1107 namespace Serialization {
1127 class serialize_impl<T*,
typename std::enable_if<std::is_base_of<SST::BaseComponent, T>::value>::type>
1134 switch ( ser.mode() ) {
1135 case serializer::SIZER:
1136 pvt::SerializeBaseComponentHelper::size_basecomponent(sp, ser);
1138 case serializer::PACK:
1139 pvt::SerializeBaseComponentHelper::pack_basecomponent(sp, ser);
1141 case serializer::UNPACK:
1142 pvt::SerializeBaseComponentHelper::unpack_basecomponent(sp, ser);
1144 case serializer::MAP:
1148 s =
static_cast<T*
>(sp);
1151 void operator()(T*& s,
serializer& ser,
const char* name)
1154 pvt::SerializeBaseComponentHelper::map_basecomponent(sp, ser, name);
1163 #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:86
virtual void complete(unsigned int UNUSED(phase))
Used during the complete phase after the end of simulation.
Definition: baseComponent.h:110
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
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:101
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:163
virtual void printStatus(Output &UNUSED(out))
Called by the Simulation to request that the component print it's current status. ...
Definition: baseComponent.h:127
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: baseComponent.h:596
T::ProfilePoint * registerProfilePoint(const std::string &pointName)
Registers a profiling point.
Definition: baseComponent.h:543
SSTHandlerBase< bool, Cycle_t > HandlerBase
Base handler for clock functions.
Definition: clock.h:42
Definition: baseComponent.h:1111
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:117
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:1022
T * loadUserSubComponent(const std::string &slot_name)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:686
Base serialize class.
Definition: serialize.h:45
Forms the base class for statistics gathering within SST.
Definition: statbase.h:45
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:94
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:45
virtual void setup()
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: baseComponent.h:114
bool isUserSubComponentLoadableUsingAPI(const std::string &slot_name)
Check to see if the element type loaded by the user into the.
Definition: baseComponent.h:611
Serialization "gateway" object.
Definition: serialize.h:133
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:1046
Definition: serializable_base.h:118
Definition: rankInfo.h:21
T * loadModule(const std::string &type, Params ¶ms, ARGS... args)
Loads a module from an element Library.
Definition: baseComponent.h:569
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:654
Main component object for the simulation.
Definition: baseComponent.h:62
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:979
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:1072
Statistics::Statistic< T > * registerStatistic(SST::Params ¶ms, const std::string &statName, const std::string &statSubId="")
Registers a statistic.
Definition: baseComponent.h:491
SimTime_t getCurrentSimTime() const
return the time since the simulation began in the default timebase
Definition: baseComponent.h:153
virtual bool Status()
Currently unused function.
Definition: baseComponent.h:120
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:705
T * create(int slot_num) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:1001
Definition: componentInfo.h:44
Used to load SubComponents when multiple SubComponents are loaded into a single slot (will also also ...
Definition: baseComponent.h:927
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:1097
uint8_t getStatisticLoadLevel() const
Returns Component Statistic load level.
Definition: baseComponent.h:89
Definition: elementinfo.h:43
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:52
Performs Unit math in full precision.
Definition: unitAlgebra.h:106
void setDefaultTimeBase(TimeConverter *tc)
Manually set the default detaulTimeBase.
Definition: baseComponent.h:874
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:863
const std::string & getName() const
Returns Component/SubComponent Name.
Definition: baseComponent.h:97
Link between two components.
Definition: link.h:51
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:106