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/oneshot.h"
20#include "sst/core/profile/componentProfileTool.h"
21#include "sst/core/simulation.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"
30using namespace SST::Statistics;
61 const std::string& ,
const std::string& ,
Params&)>;
67 const std::string& getType()
const {
return my_info->getType(); }
70 inline ComponentId_t
getId()
const {
return my_info->id; }
81 inline const std::string&
getName()
const {
return my_info->getName(); }
90 virtual void init(
unsigned int UNUSED(phase)) {}
94 virtual void complete(
unsigned int UNUSED(phase)) {}
127 __attribute__((deprecated("
getFinalSimTime() has been deprecated and will be removed in SST 13. It has been "
329 TimeConverter* getTimeConverter(
const std::string& base)
const;
332 bool isStatisticShared(
const std::string& statName,
bool include_me =
false)
335 if ( doesComponentInfoStatisticExist(statName) ) {
return true; }
337 if ( my_info->sharesStatistics() ) {
338 return my_info->parent_info->component->isStatisticShared(statName,
true);
345 template <
typename T>
347 createStatistic(
SST::Params& params, StatisticId_t
id,
const std::string& name,
const std::string& statSubId)
356 const std::string& type,
const std::string& name,
const std::string& subId,
358 return engine->createStatistic<T>(comp, type, name, subId, params);
366 id == STATALL_ID ? createEnabledAllStatistic(params, name, statSubId, std::move(create))
367 : getParentComponent()->createExplicitlyEnabledStatistic(
368 params, id, name, statSubId, std::move(create));
372 if ( statistic ) {
return statistic; }
375 __LINE__, __FILE__,
"createStatistic", 1,
"failed to cast created statistic '%s' to expected type",
381 template <
typename T>
383 createNullStatistic(
SST::Params& params,
const std::string& name,
const std::string& statSubId =
"")
385 auto* engine = Statistics::StatisticProcessingEngine::getInstance();
386 return engine->createStatistic<T>(my_info->component,
"sst.NullStatistic", name, statSubId, params);
405 template <
typename T>
407 SST::Params& params,
const std::string& statName,
const std::string& statSubId =
"",
bool inserting =
false)
409 if ( my_info->enabledStatNames ) {
410 auto iter = my_info->enabledStatNames->find(statName);
411 if ( iter != my_info->enabledStatNames->end() ) {
415 StatisticId_t
id = iter->second;
416 return createStatistic<T>(params,
id, statName, statSubId);
421 if ( inserting || doesComponentInfoStatisticExist(statName) ) {
423 if ( my_info->enabledAllStats ) {
return createStatistic<T>(params, STATALL_ID, statName, statSubId); }
424 else if ( my_info->parent_info && my_info->canInsertStatistics() ) {
428 return my_info->parent_info->component->
registerStatistic<T>(params, statName, statSubId,
true);
432 return my_info->component->createNullStatistic<T>(params, statName, statSubId);
435 else if ( my_info->parent_info && my_info->sharesStatistics() ) {
438 return my_info->parent_info->component->
registerStatistic<T>(params, statName, statSubId);
443 __LINE__, __FILE__,
"registerStatistic", 1,
"attempting to register unknown statistic '%s'",
449 template <
typename T>
453 return registerStatistic<T>(empty, statName, statSubId);
456 template <
typename... Args>
458 registerMultiStatistic(
const std::string& statName,
const std::string& statSubId =
"")
464 template <
typename... Args>
466 registerMultiStatistic(
SST::Params& params,
const std::string& statName,
const std::string& statSubId =
"")
471 template <
typename T>
474 return registerStatistic<T>(std::string(statName), std::string(statSubId));
495 template <
typename T>
498 std::string full_point_name = getType() +
"." + pointName;
499 auto tools = getComponentProfileTools(full_point_name);
500 if ( tools.size() == 0 )
return nullptr;
502 typename T::ProfilePoint* ret =
new typename T::ProfilePoint();
503 for (
auto* x : tools ) {
504 T* tool =
dynamic_cast<T*
>(x);
505 if (
nullptr == tool ) {
508 CALL_INFO_LONG, 1,
"ERROR: wrong type of profiling tool for profiling point %s)\n",
511 ret->registerProfilePoint(tool, pointName,
getId(),
getName(), getType());
522 __attribute__((deprecated(
"This version of loadModule() has been deprecated. Please use the new templated "
523 "version that uses Module APIs")));
530 template <
class T,
class... ARGS>
535 return Factory::getFactory()->CreateWithParams<T>(type, params, params, args...);
544 template <
class T,
class... ARGS>
545 T* loadComponentExtension(ARGS... args)
548 return static_cast<T*
>(ret);
560 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
578 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
581 for (
auto& ci : subcomps ) {
582 if ( ci.second.getSlotName() == slot_name ) {
583 index = ci.second.getSlotNum();
588 if ( sub_count > 1 ) {
592 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
593 slot_name.c_str(), my_info->getType().c_str(), sub_count);
596 return isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, index);
615 template <
class T,
class... ARGS>
617 const std::string& type,
const std::string& slot_name,
int slot_num, uint64_t share_flags,
Params& params,
621 share_flags = share_flags & ComponentInfo::USER_FLAGS;
622 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
626 if ( sub_info ==
nullptr )
return nullptr;
629 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
630 auto ret = Factory::getFactory()->CreateWithParams<T>(type, params, sub_info->id, params, args...);
650 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
666 template <
class T,
class... ARGS>
673 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
676 for (
auto& ci : subcomps ) {
677 if ( ci.second.getSlotName() == slot_name ) {
678 index = ci.second.getSlotNum();
683 if ( sub_count > 1 ) {
687 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
688 slot_name.c_str(), my_info->getType().c_str(), sub_count);
691 return loadUserSubComponentByIndex<T, ARGS...>(slot_name, index, share_flags, args...);
714 void fatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, ...) const
715 __attribute__((format(printf, 6, 7)));
741 bool condition, uint32_t line, const
char* file, const
char* func,
int exit_code, const
char* format, ...) const
742 __attribute__((format(printf, 7, 8)));
745 SimTime_t processCurrentTimeWithUnderflowedBase(const std::
string& base) const;
748 configureCollectionMode(Statistics::
StatisticBase* statistic, const SST::
Params& params, const std::
string& name);
759 SST::
Params& params, StatisticId_t
id, const std::
string& name, const std::
string& statSubId,
760 StatCreateFunction create);
772 SST::
Params& cpp_params, const SST::
Params& python_params, const std::
string& name,
773 const std::
string& statSubId,
bool check_load_level, StatCreateFunction create);
776 SST::
Params& params, const std::
string& name, const std::
string& statSubId, StatCreateFunction create);
778 void configureAllowedStatParams(SST::
Params& params);
782 void pushValidParams(
Params& params, const std::
string& type);
784 template <class T, class... ARGS>
785 T* loadUserSubComponentByIndex(const std::
string& slot_name,
int slot_num,
int share_flags, ARGS... args)
788 share_flags = share_flags & ComponentInfo::USER_FLAGS;
791 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
792 if ( sub_info ==
nullptr )
return nullptr;
793 sub_info->share_flags = share_flags;
794 sub_info->parent_info = my_info;
796 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
797 auto ret = Factory::getFactory()->CreateWithParams<T>(
798 sub_info->type, *sub_info->params, sub_info->id, *sub_info->params, args...);
805 bool isUserSubComponentLoadableUsingAPIByIndex(
const std::string& slot_name,
int slot_num)
808 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
809 if ( sub_info ==
nullptr )
return false;
811 return isSubComponentLoadableUsingAPI<T>(sub_info->type);
816 vfatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, va_list arg)
const;
819 SubComponentSlotInfo* getSubComponentSlotInfo(
const std::string& name,
bool fatalOnEmptyIndex =
false);
822 const std::vector<double>&
getCoordinates()
const {
return my_info->coordinates; }
827 bool isAnonymous() {
return my_info->isAnonymous(); }
829 bool isUser() {
return my_info->isUser(); }
834 TimeConverter* getDefaultTimeBase() {
return my_info->defaultTimeBase; }
836 const TimeConverter* getDefaultTimeBase()
const {
return my_info->defaultTimeBase; }
838 bool doesSubComponentExist(
const std::string& type);
844 virtual bool doesComponentInfoStatisticExist(
const std::string& statisticName)
const;
846 uint8_t getComponentInfoStatisticEnableLevel(
const std::string& statisticName)
const;
850 std::vector<Profile::ComponentProfileTool*> getComponentProfileTools(
const std::string& point);
857 void addSelfLink(
const std::string& name);
858 Link* getLinkFromParentSharedPort(
const std::string& port);
860 using StatNameMap = std::map<std::string, std::map<std::string, Statistics::StatisticBase*>>;
862 std::map<StatisticId_t, Statistics::StatisticBase*> m_explicitlyEnabledSharedStats;
863 std::map<StatisticId_t, StatNameMap> m_explicitlyEnabledUniqueStats;
864 StatNameMap m_enabledAllStats;
869 while ( base_info->parent_info ) {
870 base_info = base_info->parent_info;
872 return base_info->component;
885 std::string slot_name;
893 const std::map<ComponentId_t, ComponentInfo>& subcomps = comp->my_info->getSubComponents();
897 for (
auto& ci : subcomps ) {
898 if ( ci.second.getSlotName() == slot_name ) {
899 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
900 max_slot_index = ci.second.getSlotNum();
906 const std::string& getSlotName()
const {
return slot_name; };
908 bool isPopulated(
int slot_num)
const
910 if ( slot_num > max_slot_index )
return false;
911 if ( comp->my_info->findSubComponent(slot_name, slot_num) ==
nullptr )
return false;
915 bool isAllPopulated()
const
917 for (
int i = 0; i < max_slot_index; ++i ) {
918 if ( comp->my_info->findSubComponent(slot_name, i) ==
nullptr )
return false;
923 int getMaxPopulatedSlotNumber()
const {
return max_slot_index; }
935 return comp->isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, slot_num);
954 template <
typename T>
958 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
975 template <
class T,
class... ARGS>
976 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const
978 return comp->loadUserSubComponentByIndex<T, ARGS...>(slot_name, slot_num, share_flags, args...);
999 template <
typename T,
class... ARGS>
1000 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const
1002 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1003 T* sub = create<T>(i, share_flags, args...);
1025 template <
typename T,
class... ARGS>
1026 void createAllSparse(std::vector<std::pair<int, T*>>& vec, uint64_t share_flags, ARGS... args)
const
1028 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1029 T* sub = create<T>(i, share_flags, args...);
1030 if ( sub !=
nullptr ) vec.push_back(i, sub);
1050 template <
typename T,
class... ARGS>
1053 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1054 T* sub = create<T>(i, share_flags, args...);
1055 if ( sub !=
nullptr ) vec.push_back(sub);
Main component object for the simulation.
Definition: baseComponent.h:51
bool isSimulationRunModeInit() const
Check to see if the run mode was set to INIT.
Definition: baseComponent.cc:534
SimTime_t getCurrentSimTimeMilli() const
Utility function to return the time since the simulation began in milliseconds.
Definition: baseComponent.cc:507
TimeConverter * registerTimeBase(const std::string &base, bool regAll=true)
Registers a default time base for the component and optionally sets the the component's links to that...
Definition: baseComponent.cc:197
virtual void complete(unsigned int UNUSED(phase))
Used during the complete phase after the end of simulation.
Definition: baseComponent.h:94
void requireLibrary(const std::string &name)
Signifies that a library is required for this simulation.
Definition: baseComponent.cc:558
bool isSimulationRunModeRun() const
Check to see if the run mode was set to RUN.
Definition: baseComponent.cc:540
Link * configureLink(const std::string &name, TimeConverter *time_base, Event::HandlerBase *handler=nullptr)
Configure a Link.
Definition: baseComponent.cc:266
Link * configureSelfLink(const std::string &name, TimeConverter *time_base, Event::HandlerBase *handler=nullptr)
Configure a SelfLink (Loopback link)
Definition: baseComponent.cc:360
bool isPortConnected(const std::string &name) const
Determine if a port name is connected to any links.
Definition: baseComponent.cc:223
void fatal(uint32_t line, const char *file, const char *func, int exit_code, const char *format,...) const
Convenience function for reporting fatal conditions.
Definition: baseComponent.cc:605
double getRunPhaseElapsedRealTime() const
Get the amount of real-time spent executing the run phase of the simulation.
Definition: baseComponent.cc:516
T * loadUserSubComponent(const std::string &slot_name)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:648
const std::string & getName() const
Returns Component/SubComponent Name.
Definition: baseComponent.h:81
virtual void emergencyShutdown(void)
Called when SIGINT or SIGTERM has been seen.
Definition: baseComponent.h:78
virtual void setup()
Called after all components have been constructed and initialization has completed,...
Definition: baseComponent.h:98
Cycle_t getNextClockCycle(TimeConverter *freq)
Returns the next Cycle that the TimeConverter would fire.
Definition: baseComponent.cc:185
uint8_t getStatisticLoadLevel() const
Returns Component Statistic load level.
Definition: baseComponent.h:73
UnitAlgebra getCoreTimeBase() const
Get the core timebase.
Definition: baseComponent.cc:388
std::string & getOutputDirectory() const
Returns the output directory of the simulation.
Definition: baseComponent.cc:552
double getCompletePhaseElapsedRealTime() const
Get the amount of real-time spent executing the complete phase of the simulation.
Definition: baseComponent.cc:528
void performStatisticOutput(Statistics::StatisticBase *stat)
Called by the Components and Subcomponent to perform a statistic Output.
Definition: baseComponent.cc:828
int getCurrentPriority() const
Return the current priority.
Definition: baseComponent.cc:400
double getInitPhaseElapsedRealTime() const
Get the amount of real-time spent executing the init phase of the simulation.
Definition: baseComponent.cc:522
void performGlobalStatisticOutput()
Performs a global statistic Output.
Definition: baseComponent.cc:834
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: baseComponent.h:558
const std::vector< double > & getCoordinates() const
Retrieve the X,Y,Z coordinates of this component.
Definition: baseComponent.h:822
T::ProfilePoint * registerProfilePoint(const std::string &pointName)
Registers a profiling point.
Definition: baseComponent.h:496
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:85
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:90
Output & getSimulationOutput() const
Return the base simulation Output class instance.
Definition: baseComponent.cc:442
SimTime_t getCurrentSimTime() const
return the time since the simulation began in the default timebase
Definition: baseComponent.h:141
UnitAlgebra getElapsedSimTime() const
Return the elapsed simulation time as a time.
Definition: baseComponent.cc:406
SimTime_t getCurrentSimTimeMicro() const
Utility function to return the time since the simulation began in microseconds.
Definition: baseComponent.cc:499
RankInfo getNumRanks() const
Get the number of parallel ranks in the simulation.
Definition: baseComponent.cc:436
UnitAlgebra getEndSimTime() const
Return the end simulation time as a time.
Definition: baseComponent.cc:418
Module * loadModule(const std::string &type, Params ¶ms)
Loads a module from an element Library.
Definition: baseComponent.cc:571
void sst_assert(bool condition, uint32_t line, const char *file, const char *func, int exit_code, const char *format,...) const
Convenience function for testing for and reporting fatal conditions.
Definition: baseComponent.cc:614
bool isSimulationRunModeBoth() const
Check to see if the run mode was set to BOTH.
Definition: baseComponent.cc:546
RankInfo getRank() const
Get this instance's parallel rank.
Definition: baseComponent.cc:430
TimeConverter * registerClock(const std::string &freq, Clock::HandlerBase *handler, bool regAll=true)
Registers a clock for this component.
Definition: baseComponent.cc:110
void setDefaultTimeBase(TimeConverter *tc)
Manually set the default detaulTimeBase.
Definition: baseComponent.h:832
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:667
SimTime_t getCurrentSimTimeNano() const
Utility function to return the time since the simulation began in nanoseconds.
Definition: baseComponent.cc:491
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:616
Statistics::Statistic< T > * registerStatistic(SST::Params ¶ms, const std::string &statName, const std::string &statSubId="", bool inserting=false)
Registers a statistic.
Definition: baseComponent.h:406
void unregisterClock(TimeConverter *tc, Clock::HandlerBase *handler)
Removes a clock handler from the component.
Definition: baseComponent.cc:191
ComponentId_t getId() const
Returns unique component ID.
Definition: baseComponent.h:70
Cycle_t reregisterClock(TimeConverter *freq, Clock::HandlerBase *handler)
Reactivates an existing Clock and Handler.
Definition: baseComponent.cc:179
bool isUserSubComponentLoadableUsingAPI(const std::string &slot_name)
Check to see if the element type loaded by the user into the.
Definition: baseComponent.h:573
virtual void finish()
Called after complete phase, but before objects are destroyed.
Definition: baseComponent.h:101
SimTime_t getEndSimCycle() const
Return the end simulation time as a cycle count.
Definition: baseComponent.cc:412
virtual bool Status()
Currently unused function.
Definition: baseComponent.h:104
UnitAlgebra getFinalSimTime() const
Return the end simulation time as a time.
Definition: baseComponent.cc:424
SimTime_t getCurrentSimCycle() const
Return the current simulation time as a cycle count.
Definition: baseComponent.cc:394
virtual void printStatus(Output &UNUSED(out))
Called by the Simulation to request that the component print it's current status.
Definition: baseComponent.h:111
T * loadModule(const std::string &type, Params ¶ms, ARGS... args)
Loads a module from an element Library.
Definition: baseComponent.h:531
A Clock class.
Definition: clock.h:33
ComponentExtension is a class that can be loaded using loadComponentExtension<T>(....
Definition: componentExtension.h:29
Definition: componentInfo.h:40
Main component object for the simulation.
Definition: component.h:31
Maps port names to the Links that are connected to it.
Definition: linkMap.h:28
Link between two components.
Definition: link.h:38
Module is a tag class used with the loadModule function.
Definition: module.h:22
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:155
@ 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
Main control class for a SST Simulation.
Definition: simulation_impl.h:77
Main control class for a SST Simulation.
Definition: simulation.h:35
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:882
T * create(int slot_num) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:955
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:1026
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:933
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:1000
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:976
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:1051
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