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"
30 using namespace SST::Statistics;
35 class ComponentExtension;
42 class Simulation_impl;
44 class SubComponentSlotInfo;
62 const std::string& ,
const std::string& ,
Params&)>;
68 const std::string& getType()
const {
return my_info->getType(); }
71 inline ComponentId_t
getId()
const {
return my_info->id; }
82 inline const std::string&
getName()
const {
return my_info->getName(); }
91 virtual void init(
unsigned int UNUSED(phase)) {}
95 virtual void complete(
unsigned int UNUSED(phase)) {}
117 SimTime_t getCurrentSimCycle()
const;
119 int getCurrentPriority()
const;
123 SimTime_t getEndSimCycle()
const;
131 Output& getSimulationOutput()
const;
141 SimTime_t getCurrentSimTime(
const std::string& base)
const;
144 SimTime_t getCurrentSimTimeNano()
const;
146 SimTime_t getCurrentSimTimeMicro()
const;
148 SimTime_t getCurrentSimTimeMilli()
const;
155 double getRunPhaseElapsedRealTime()
const;
162 double getInitPhaseElapsedRealTime()
const;
169 double getCompletePhaseElapsedRealTime()
const;
176 bool isSimulationRunModeInit()
const;
181 bool isSimulationRunModeRun()
const;
186 bool isSimulationRunModeBoth()
const;
193 std::string& getOutputDirectory()
const;
210 void requireLibrary(
const std::string& name);
214 bool isPortConnected(
const std::string& name)
const;
230 Link* configureLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
260 configureSelfLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
337 TimeConverter* registerTimeBase(
const std::string& base,
bool regAll =
true);
339 TimeConverter* getTimeConverter(
const std::string& base)
const;
342 bool isStatisticShared(
const std::string& statName,
bool include_me =
false)
345 if ( doesComponentInfoStatisticExist(statName) ) {
return true; }
347 if ( my_info->sharesStatistics() ) {
348 return my_info->parent_info->component->isStatisticShared(statName,
true);
356 template <
typename T>
357 Statistics::Statistic<T>*
358 createStatistic(
SST::Params& params, StatisticId_t
id,
const std::string& name,
const std::string& statSubId)
366 StatCreateFunction create = [=](BaseComponent* comp, Statistics::StatisticProcessingEngine* engine,
367 const std::string& type,
const std::string& name,
const std::string& subId,
368 SST::Params& params) -> Statistics::StatisticBase* {
369 return engine->createStatistic<T>(comp, type, name, subId, params);
376 Statistics::StatisticBase* base_stat =
377 id == STATALL_ID ? createEnabledAllStatistic(params, name, statSubId, std::move(create))
378 : getParentComponent()->createExplicitlyEnabledStatistic(
379 params, id, name, statSubId, std::move(create));
382 auto* statistic =
dynamic_cast<Statistics::Statistic<T>*
>(base_stat);
383 if ( statistic ) {
return statistic; }
386 __LINE__, __FILE__,
"createStatistic", 1,
"failed to cast created statistic '%s' to expected type",
392 template <
typename T>
393 Statistics::Statistic<T>*
394 createNullStatistic(
SST::Params& params,
const std::string& name,
const std::string& statSubId =
"")
396 auto* engine = getStatEngine();
397 return engine->createStatistic<T>(my_info->component,
"sst.NullStatistic", name, statSubId, params);
400 template <
typename T>
401 Statistics::Statistic<T>*
402 registerStatistic(
SST::Params& params,
const std::string& statName,
const std::string& statSubId,
bool inserting)
404 if ( my_info->enabledStatNames ) {
405 auto iter = my_info->enabledStatNames->find(statName);
406 if ( iter != my_info->enabledStatNames->end() ) {
410 StatisticId_t
id = iter->second;
411 return createStatistic<T>(params,
id, statName, statSubId);
416 if ( inserting || doesComponentInfoStatisticExist(statName) ) {
418 if ( my_info->enabledAllStats ) {
return createStatistic<T>(params, STATALL_ID, statName, statSubId); }
419 else if ( my_info->parent_info && my_info->canInsertStatistics() ) {
423 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId,
true);
427 return my_info->component->createNullStatistic<T>(params, statName, statSubId);
430 else if ( my_info->parent_info && my_info->sharesStatistics() ) {
433 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId,
false);
438 __LINE__, __FILE__,
"registerStatistic", 1,
"attempting to register unknown statistic '%s'",
462 template <
typename T>
463 Statistics::Statistic<T>*
466 return registerStatistic<T>(params, statName, statSubId,
false);
469 template <
typename T>
473 return registerStatistic<T>(empty, statName, statSubId,
false);
476 template <
typename... Args>
477 Statistics::Statistic<std::tuple<Args...>>*
478 registerMultiStatistic(
const std::string& statName,
const std::string& statSubId =
"")
481 return registerStatistic<std::tuple<Args...>>(empty, statName, statSubId,
false);
484 template <
typename... Args>
485 Statistics::Statistic<std::tuple<Args...>>*
486 registerMultiStatistic(
SST::Params& params,
const std::string& statName,
const std::string& statSubId =
"")
488 return registerStatistic<std::tuple<Args...>>(params, statName, statSubId,
false);
491 template <
typename T>
492 Statistics::Statistic<T>* registerStatistic(
const char* statName,
const char* statSubId =
"")
494 return registerStatistic<T>(std::string(statName), std::string(statSubId));
501 void performStatisticOutput(Statistics::StatisticBase* stat);
508 void performGlobalStatisticOutput();
515 template <
typename T>
518 std::string full_point_name = getType() +
"." + pointName;
519 auto tools = getComponentProfileTools(full_point_name);
520 if ( tools.size() == 0 )
return nullptr;
522 typename T::ProfilePoint* ret =
new typename T::ProfilePoint();
523 for (
auto* x : tools ) {
524 T* tool =
dynamic_cast<T*
>(x);
525 if (
nullptr == tool ) {
528 CALL_INFO_LONG, 1,
"ERROR: wrong type of profiling tool for profiling point %s)\n",
531 ret->registerProfilePoint(tool, pointName, getId(), getName(), getType());
541 template <
class T,
class... ARGS>
546 return Factory::getFactory()->CreateWithParams<T>(type, params, params, args...);
555 template <
class T,
class... ARGS>
556 T* loadComponentExtension(ARGS... args)
559 return static_cast<T*
>(ret);
571 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
589 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
592 for (
auto& ci : subcomps ) {
593 if ( ci.second.getSlotName() == slot_name ) {
594 index = ci.second.getSlotNum();
599 if ( sub_count > 1 ) {
603 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
604 slot_name.c_str(), my_info->getType().c_str(), sub_count);
607 return isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, index);
626 template <
class T,
class... ARGS>
628 const std::string& type,
const std::string& slot_name,
int slot_num, uint64_t share_flags,
Params& params,
632 share_flags = share_flags & ComponentInfo::USER_FLAGS;
633 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
637 if ( sub_info ==
nullptr )
return nullptr;
640 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
641 auto ret = Factory::getFactory()->CreateWithParams<T>(type, params, sub_info->id, params, args...);
661 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
677 template <
class T,
class... ARGS>
684 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
687 for (
auto& ci : subcomps ) {
688 if ( ci.second.getSlotName() == slot_name ) {
689 index = ci.second.getSlotNum();
694 if ( sub_count > 1 ) {
698 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
699 slot_name.c_str(), my_info->getType().c_str(), sub_count);
702 return loadUserSubComponentByIndex<T, ARGS...>(slot_name, index, share_flags, args...);
725 void fatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, ...) const
726 __attribute__((format(printf, 6, 7)));
752 bool condition, uint32_t line, const
char* file, const
char* func,
int exit_code, const
char* format, ...) const
753 __attribute__((format(printf, 7, 8)));
756 SimTime_t processCurrentTimeWithUnderflowedBase(const std::
string& base) const;
759 configureCollectionMode(Statistics::
StatisticBase* statistic, const SST::
Params& params, const std::
string& name);
770 SST::
Params& params, StatisticId_t
id, const std::
string& name, const std::
string& statSubId,
771 StatCreateFunction create);
783 SST::
Params& cpp_params, const SST::
Params& python_params, const std::
string& name,
784 const std::
string& statSubId,
bool check_load_level, StatCreateFunction create);
787 SST::
Params& params, const std::
string& name, const std::
string& statSubId, StatCreateFunction create);
789 void configureAllowedStatParams(SST::
Params& params);
793 void pushValidParams(
Params& params, const std::
string& type);
795 template <class T, class... ARGS>
796 T* loadUserSubComponentByIndex(const std::
string& slot_name,
int slot_num,
int share_flags, ARGS... args)
799 share_flags = share_flags & ComponentInfo::USER_FLAGS;
802 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
803 if ( sub_info ==
nullptr )
return nullptr;
804 sub_info->share_flags = share_flags;
805 sub_info->parent_info = my_info;
807 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
808 auto ret = Factory::getFactory()->CreateWithParams<T>(
809 sub_info->type, *sub_info->params, sub_info->id, *sub_info->params, args...);
816 bool isUserSubComponentLoadableUsingAPIByIndex(
const std::string& slot_name,
int slot_num)
819 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
820 if ( sub_info ==
nullptr )
return false;
822 return isSubComponentLoadableUsingAPI<T>(sub_info->type);
827 vfatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, va_list arg)
const;
833 SubComponentSlotInfo* getSubComponentSlotInfo(
const std::string& name,
bool fatalOnEmptyIndex =
false);
836 const std::vector<double>&
getCoordinates()
const {
return my_info->coordinates; }
842 bool isAnonymous() {
return my_info->isAnonymous(); }
844 bool isUser() {
return my_info->isUser(); }
849 TimeConverter* getDefaultTimeBase() {
return my_info->defaultTimeBase; }
851 const TimeConverter* getDefaultTimeBase()
const {
return my_info->defaultTimeBase; }
853 bool doesSubComponentExist(
const std::string& type);
856 #if !SST_BUILDING_CORE
857 [[deprecated(
"getSimulation is deprecated because the Simulation object is being removed as part of the public API "
858 "and simulation.h will be removed in SST 14")]]
861 getSimulation()
const;
864 bool doesComponentInfoStatisticExist(
const std::string& statisticName)
const;
866 uint8_t getComponentInfoStatisticEnableLevel(
const std::string& statisticName)
const;
870 std::vector<Profile::ComponentProfileTool*> getComponentProfileTools(
const std::string& point);
873 ComponentInfo* my_info =
nullptr;
874 Simulation_impl* sim_ =
nullptr;
877 void addSelfLink(
const std::string& name);
878 Link* getLinkFromParentSharedPort(
const std::string& port);
880 using StatNameMap = std::map<std::string, std::map<std::string, Statistics::StatisticBase*>>;
882 std::map<StatisticId_t, Statistics::StatisticBase*> m_explicitlyEnabledSharedStats;
883 std::map<StatisticId_t, StatNameMap> m_explicitlyEnabledUniqueStats;
884 StatNameMap m_enabledAllStats;
886 BaseComponent* getParentComponent()
888 ComponentInfo* base_info = my_info;
889 while ( base_info->parent_info ) {
890 base_info = base_info->parent_info;
892 return base_info->component;
905 std::string slot_name;
913 const std::map<ComponentId_t, ComponentInfo>& subcomps = comp->my_info->getSubComponents();
917 for (
auto& ci : subcomps ) {
918 if ( ci.second.getSlotName() == slot_name ) {
919 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
920 max_slot_index = ci.second.getSlotNum();
926 const std::string& getSlotName()
const {
return slot_name; };
928 bool isPopulated(
int slot_num)
const
930 if ( slot_num > max_slot_index )
return false;
931 if ( comp->my_info->findSubComponent(slot_name, slot_num) ==
nullptr )
return false;
935 bool isAllPopulated()
const
937 for (
int i = 0; i < max_slot_index; ++i ) {
938 if ( comp->my_info->findSubComponent(slot_name, i) ==
nullptr )
return false;
943 int getMaxPopulatedSlotNumber()
const {
return max_slot_index; }
955 return comp->isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, slot_num);
974 template <
typename T>
978 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
995 template <
class T,
class... ARGS>
996 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const
998 return comp->loadUserSubComponentByIndex<T, ARGS...>(slot_name, slot_num, share_flags, args...);
1019 template <
typename T,
class... ARGS>
1020 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const
1022 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1023 T* sub = create<T>(i, share_flags, args...);
1045 template <
typename T,
class... ARGS>
1046 void createAllSparse(std::vector<std::pair<int, 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...);
1050 if ( sub !=
nullptr ) vec.push_back(i, sub);
1070 template <
typename T,
class... ARGS>
1073 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1074 T* sub = create<T>(i, share_flags, args...);
1075 if ( sub !=
nullptr ) vec.push_back(sub);
Main component object for the simulation.
Definition: baseComponent.h:52
T * loadModule(const std::string &type, Params ¶ms, ARGS... args)
Loads a module from an element Library.
Definition: baseComponent.h:542
Statistics::Statistic< T > * registerStatistic(SST::Params ¶ms, const std::string &statName, const std::string &statSubId="")
Registers a statistic.
Definition: baseComponent.h:464
const std::vector< double > & getCoordinates() const
Retrieve the X,Y,Z coordinates of this component.
Definition: baseComponent.h:836
virtual void complete(unsigned int UNUSED(phase))
Used during the complete phase after the end of simulation.
Definition: baseComponent.h:95
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:627
virtual void emergencyShutdown(void)
Called when SIGINT or SIGTERM has been seen.
Definition: baseComponent.h:79
T::ProfilePoint * registerProfilePoint(const std::string &pointName)
Registers a profiling point.
Definition: baseComponent.h:516
virtual void setup()
Called after all components have been constructed and initialization has completed,...
Definition: baseComponent.h:99
T * loadUserSubComponent(const std::string &slot_name)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:659
uint8_t getStatisticLoadLevel() const
Returns Component Statistic load level.
Definition: baseComponent.h:74
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:86
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: baseComponent.h:569
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:91
SimTime_t getCurrentSimTime() const
return the time since the simulation began in the default timebase
Definition: baseComponent.h:138
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:678
void setDefaultTimeBase(TimeConverter *tc)
Manually set the default detaulTimeBase.
Definition: baseComponent.h:847
ComponentId_t getId() const
Returns unique component ID.
Definition: baseComponent.h:71
bool isUserSubComponentLoadableUsingAPI(const std::string &slot_name)
Check to see if the element type loaded by the user into the.
Definition: baseComponent.h:584
virtual void finish()
Called after complete phase, but before objects are destroyed.
Definition: baseComponent.h:102
virtual bool Status()
Currently unused function.
Definition: baseComponent.h:105
const std::string & getName() const
Returns Component/SubComponent Name.
Definition: baseComponent.h:82
virtual void printStatus(Output &UNUSED(out))
Called by the Simulation to request that the component print it's current status.
Definition: baseComponent.h:112
ComponentExtension is a class that can be loaded using loadComponentExtension<T>(....
Definition: componentExtension.h:29
Definition: componentInfo.h:40
Link between two components.
Definition: link.h:38
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
@ STDERR
Definition: output.h:59
Parameter store.
Definition: params.h:56
Definition: rankInfo.h:22
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:171
Forms the base class for statistics gathering within SST.
Definition: statbase.h:64
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:52
Forms the template defined base class for statistics gathering within SST.
Definition: statbase.h:361
Used to load SubComponents when multiple SubComponents are loaded into a single slot (will also also ...
Definition: baseComponent.h:902
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:996
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:1046
T * create(int slot_num) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:975
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:953
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:1020
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:1071
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:27
Performs Unit math in full precision.
Definition: unitAlgebra.h:109