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/simulation.h"
21 #include "sst/core/sst_types.h"
22 #include "sst/core/statapi/statbase.h"
23 #include "sst/core/statapi/statengine.h"
24 #include "sst/core/warnmacros.h"
29 using namespace SST::Statistics;
34 class ComponentExtension;
40 class Simulation_impl;
42 class SubComponentSlotInfo;
60 const std::string& ,
const std::string& ,
Params&)>;
66 const std::string& getType()
const {
return my_info->getType(); }
69 inline ComponentId_t
getId()
const {
return my_info->id; }
80 inline const std::string&
getName()
const {
return my_info->getName(); }
89 virtual void init(
unsigned int UNUSED(phase)) {}
93 virtual void complete(
unsigned int UNUSED(phase)) {}
115 SimTime_t getCurrentSimCycle()
const;
117 int getCurrentPriority()
const;
121 SimTime_t getEndSimCycle()
const;
126 __attribute__((deprecated("getFinalSimTime() has been deprecated and will be removed in SST 13. It has been "
127 "replaced by getEndSimTime().")));
133 Output& getSimulationOutput() const;
140 inline SimTime_t getCurrentSimTime()
const {
return getCurrentSimTime(my_info->defaultTimeBase); }
143 SimTime_t getCurrentSimTime(
const std::string& base)
const;
146 SimTime_t getCurrentSimTimeNano()
const;
148 SimTime_t getCurrentSimTimeMicro()
const;
150 SimTime_t getCurrentSimTimeMilli()
const;
157 double getRunPhaseElapsedRealTime()
const;
164 double getInitPhaseElapsedRealTime()
const;
171 double getCompletePhaseElapsedRealTime()
const;
178 bool isSimulationRunModeInit()
const;
183 bool isSimulationRunModeRun()
const;
188 bool isSimulationRunModeBoth()
const;
195 std::string& getOutputDirectory()
const;
212 void requireLibrary(
const std::string& name);
216 bool isPortConnected(
const std::string& name)
const;
232 Link* configureLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
262 configureSelfLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
326 TimeConverter* registerTimeBase(
const std::string& base,
bool regAll =
true);
328 TimeConverter* getTimeConverter(
const std::string& base)
const;
331 bool isStatisticShared(
const std::string& statName,
bool include_me =
false)
334 if ( doesComponentInfoStatisticExist(statName) ) {
return true; }
336 if ( my_info->sharesStatistics() ) {
337 return my_info->parent_info->component->isStatisticShared(statName,
true);
344 template <
typename T>
345 Statistics::Statistic<T>*
346 createStatistic(
SST::Params& params, StatisticId_t
id,
const std::string& name,
const std::string& statSubId)
354 StatCreateFunction create = [=](BaseComponent* comp, Statistics::StatisticProcessingEngine* engine,
355 const std::string& type,
const std::string& name,
const std::string& subId,
356 SST::Params& params) -> Statistics::StatisticBase* {
357 return engine->createStatistic<T>(comp, type, name, subId, params);
364 Statistics::StatisticBase* base_stat =
365 id == STATALL_ID ? createEnabledAllStatistic(params, name, statSubId, std::move(create))
366 : getParentComponent()->createExplicitlyEnabledStatistic(
367 params, id, name, statSubId, std::move(create));
370 auto* statistic =
dynamic_cast<Statistics::Statistic<T>*
>(base_stat);
371 if ( statistic ) {
return statistic; }
374 __LINE__, __FILE__,
"createStatistic", 1,
"failed to cast created statistic '%s' to expected type",
380 template <
typename T>
381 Statistics::Statistic<T>*
382 createNullStatistic(
SST::Params& params,
const std::string& name,
const std::string& statSubId =
"")
384 auto* engine = Statistics::StatisticProcessingEngine::getInstance();
385 return engine->createStatistic<T>(my_info->component,
"sst.NullStatistic", name, statSubId, params);
404 template <
typename T>
406 SST::Params& params,
const std::string& statName,
const std::string& statSubId =
"",
bool inserting =
false)
408 if ( my_info->enabledStatNames ) {
409 auto iter = my_info->enabledStatNames->find(statName);
410 if ( iter != my_info->enabledStatNames->end() ) {
414 StatisticId_t
id = iter->second;
415 return createStatistic<T>(params, id, statName, statSubId);
420 if ( inserting || doesComponentInfoStatisticExist(statName) ) {
422 if ( my_info->enabledAllStats ) {
return createStatistic<T>(params, STATALL_ID, statName, statSubId); }
423 else if ( my_info->parent_info && my_info->canInsertStatistics() ) {
427 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId,
true);
431 return my_info->component->createNullStatistic<T>(params, statName, statSubId);
434 else if ( my_info->parent_info && my_info->sharesStatistics() ) {
437 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId);
442 __LINE__, __FILE__,
"registerStatistic", 1,
"attempting to register unknown statistic '%s'",
448 template <
typename T>
452 return registerStatistic<T>(empty, statName, statSubId);
455 template <
typename... Args>
456 Statistics::Statistic<std::tuple<Args...>>*
457 registerMultiStatistic(
const std::string& statName,
const std::string& statSubId =
"")
460 return registerStatistic<std::tuple<Args...>>(empty, statName, statSubId);
463 template <
typename... Args>
464 Statistics::Statistic<std::tuple<Args...>>*
465 registerMultiStatistic(
SST::Params& params,
const std::string& statName,
const std::string& statSubId =
"")
467 return registerStatistic<std::tuple<Args...>>(params, statName, statSubId);
470 template <
typename T>
471 Statistics::Statistic<T>* registerStatistic(
const char* statName,
const char* statSubId =
"")
473 return registerStatistic<T>(std::string(statName), std::string(statSubId));
480 void performStatisticOutput(Statistics::StatisticBase* stat);
487 void performGlobalStatisticOutput();
494 Module* loadModule(
const std::string& type, Params& params)
495 __attribute__((deprecated(
"This version of loadModule() has been deprecated. Please use the new templated "
496 "version that uses Module APIs")));
503 template <
class T,
class... ARGS>
508 return Factory::getFactory()->CreateWithParams<T>(type, params, params, args...);
517 template <
class T,
class... ARGS>
518 T* loadComponentExtension(ARGS... args)
521 return static_cast<T*
>(ret);
533 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
551 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
554 for (
auto& ci : subcomps ) {
555 if ( ci.second.getSlotName() == slot_name ) {
556 index = ci.second.getSlotNum();
561 if ( sub_count > 1 ) {
565 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
566 slot_name.c_str(), my_info->getType().c_str(), sub_count);
569 return isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, index);
588 template <
class T,
class... ARGS>
590 const std::string& type,
const std::string& slot_name,
int slot_num, uint64_t share_flags,
Params& params,
594 share_flags = share_flags & ComponentInfo::USER_FLAGS;
595 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
599 if ( sub_info ==
nullptr )
return nullptr;
602 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
603 auto ret = Factory::getFactory()->CreateWithParams<T>(type, params, sub_info->id, params, args...);
623 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
639 template <
class T,
class... ARGS>
646 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
649 for (
auto& ci : subcomps ) {
650 if ( ci.second.getSlotName() == slot_name ) {
651 index = ci.second.getSlotNum();
656 if ( sub_count > 1 ) {
660 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
661 slot_name.c_str(), my_info->getType().c_str(), sub_count);
664 return loadUserSubComponentByIndex<T, ARGS...>(slot_name, index, share_flags, args...);
687 void fatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, ...) const
688 __attribute__((format(printf, 6, 7)));
714 bool condition, uint32_t line, const
char* file, const
char* func,
int exit_code, const
char* format, ...) const
715 __attribute__((format(printf, 7, 8)));
718 SimTime_t processCurrentTimeWithUnderflowedBase(const std::
string& base) const;
721 configureCollectionMode(Statistics::
StatisticBase* statistic, const SST::
Params& params, const std::
string& name);
732 SST::
Params& params, StatisticId_t
id, const std::
string& name, const std::
string& statSubId,
733 StatCreateFunction create);
745 SST::
Params& cpp_params, const SST::
Params& python_params, const std::
string& name,
746 const std::
string& statSubId,
bool check_load_level, StatCreateFunction create);
749 SST::
Params& params, const std::
string& name, const std::
string& statSubId, StatCreateFunction create);
751 void configureAllowedStatParams(SST::
Params& params);
755 void pushValidParams(
Params& params, const std::
string& type);
757 template <class T, class... ARGS>
758 T* loadUserSubComponentByIndex(const std::
string& slot_name,
int slot_num,
int share_flags, ARGS... args)
761 share_flags = share_flags & ComponentInfo::USER_FLAGS;
764 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
765 if ( sub_info ==
nullptr )
return nullptr;
766 sub_info->share_flags = share_flags;
767 sub_info->parent_info = my_info;
769 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
770 auto ret = Factory::getFactory()->CreateWithParams<T>(
771 sub_info->type, *sub_info->params, sub_info->id, *sub_info->params, args...);
778 bool isUserSubComponentLoadableUsingAPIByIndex(
const std::string& slot_name,
int slot_num)
781 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
782 if ( sub_info ==
nullptr )
return false;
784 return isSubComponentLoadableUsingAPI<T>(sub_info->type);
789 vfatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, va_list arg)
const;
792 SubComponentSlotInfo* getSubComponentSlotInfo(
const std::string& name,
bool fatalOnEmptyIndex =
false);
795 const std::vector<double>&
getCoordinates()
const {
return my_info->coordinates; }
800 bool isAnonymous() {
return my_info->isAnonymous(); }
802 bool isUser() {
return my_info->isUser(); }
807 TimeConverter* getDefaultTimeBase() {
return my_info->defaultTimeBase; }
809 const TimeConverter* getDefaultTimeBase()
const {
return my_info->defaultTimeBase; }
811 bool doesSubComponentExist(
const std::string& type);
814 Simulation* getSimulation()
const;
817 virtual bool doesComponentInfoStatisticExist(
const std::string& statisticName)
const;
819 uint8_t getComponentInfoStatisticEnableLevel(
const std::string& statisticName)
const;
824 ComponentInfo* my_info =
nullptr;
827 void addSelfLink(
const std::string& name);
828 Link* getLinkFromParentSharedPort(
const std::string& port);
830 using StatNameMap = std::map<std::string, std::map<std::string, Statistics::StatisticBase*>>;
832 std::map<StatisticId_t, Statistics::StatisticBase*> m_explicitlyEnabledSharedStats;
833 std::map<StatisticId_t, StatNameMap> m_explicitlyEnabledUniqueStats;
834 StatNameMap m_enabledAllStats;
836 BaseComponent* getParentComponent()
838 ComponentInfo* base_info = my_info;
839 while ( base_info->parent_info ) {
840 base_info = base_info->parent_info;
842 return base_info->component;
855 std::string slot_name;
863 const std::map<ComponentId_t, ComponentInfo>& subcomps = comp->my_info->getSubComponents();
867 for (
auto& ci : subcomps ) {
868 if ( ci.second.getSlotName() == slot_name ) {
869 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
870 max_slot_index = ci.second.getSlotNum();
876 const std::string& getSlotName()
const {
return slot_name; };
878 bool isPopulated(
int slot_num)
const
880 if ( slot_num > max_slot_index )
return false;
881 if ( comp->my_info->findSubComponent(slot_name, slot_num) == nullptr )
return false;
885 bool isAllPopulated()
const
887 for (
int i = 0; i < max_slot_index; ++i ) {
888 if ( comp->my_info->findSubComponent(slot_name, i) == nullptr )
return false;
893 int getMaxPopulatedSlotNumber()
const {
return max_slot_index; }
905 return comp->isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, slot_num);
924 template <
typename T>
928 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
945 template <
class T,
class... ARGS>
946 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const
948 return comp->loadUserSubComponentByIndex<T, ARGS...>(slot_name, slot_num, share_flags, args...);
969 template <
typename T,
class... ARGS>
970 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const
972 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
973 T* sub = create<T>(i, share_flags, args...);
995 template <
typename T,
class... ARGS>
996 void createAllSparse(std::vector<std::pair<int, T*>>& vec, uint64_t share_flags, ARGS... args)
const
998 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
999 T* sub = create<T>(i, share_flags, args...);
1000 if ( sub !=
nullptr ) vec.push_back(i, sub);
1020 template <
typename T,
class... ARGS>
1023 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
1024 T* sub = create<T>(i, share_flags, args...);
1025 if ( sub !=
nullptr ) vec.push_back(sub);
1032 #endif // SST_CORE_BASECOMPONENT_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:51
Statistics::Statistic< T > * registerStatistic(SST::Params ¶ms, const std::string &statName, const std::string &statSubId="", bool inserting=false)
Registers a statistic.
Definition: baseComponent.h:405
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:84
virtual void complete(unsigned int UNUSED(phase))
Used during the complete phase after the end of simulation.
Definition: baseComponent.h:93
Definition: ssthandler.h:100
virtual void printStatus(Output &UNUSED(out))
Called by the Simulation to request that the component print it's current status. ...
Definition: baseComponent.h:110
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: baseComponent.h:531
ComponentId_t getId() const
Returns unique component ID.
Definition: baseComponent.h:69
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:946
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:26
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:1021
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:970
virtual void finish()
Called after complete phase, but before objects are destroyed.
Definition: baseComponent.h:100
T * loadUserSubComponent(const std::string &slot_name)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:621
Forms the base class for statistics gathering within SST.
Definition: statbase.h:63
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:589
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:77
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:42
T * loadModule(const std::string &type, Params ¶ms, ARGS...args)
Loads a module from an element Library.
Definition: baseComponent.h:504
uint8_t getStatisticLoadLevel() const
Returns Component Statistic load level.
Definition: baseComponent.h:72
const std::vector< double > & getCoordinates() const
Retrieve the X,Y,Z coordinates of this component.
Definition: baseComponent.h:795
virtual void setup()
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: baseComponent.h:97
bool isUserSubComponentLoadableUsingAPI(const std::string &slot_name)
Check to see if the element type loaded by the user into the.
Definition: baseComponent.h:546
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
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:640
Definition: rankInfo.h:21
Main component object for the simulation.
Definition: baseComponent.h:49
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:903
virtual bool Status()
Currently unused function.
Definition: baseComponent.h:103
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:996
Parameter store.
Definition: params.h:55
Definition: componentInfo.h:39
Used to load SubComponents when multiple SubComponents are loaded into a single slot (will also also ...
Definition: baseComponent.h:851
T * create(int slot_num) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:925
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:51
const std::string & getName() const
Returns Component/SubComponent Name.
Definition: baseComponent.h:80
Performs Unit math in full precision.
Definition: unitAlgebra.h:106
void setDefaultTimeBase(TimeConverter *tc)
Manually set the default detaulTimeBase.
Definition: baseComponent.h:805
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:28
SimTime_t getCurrentSimTime() const
return the time since the simulation began in the default timebase
Definition: baseComponent.h:140
Link between two components.
Definition: link.h:32
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:89