12 #ifndef SST_CORE_BASECOMPONENT_H
13 #define SST_CORE_BASECOMPONENT_H
15 #include "sst/core/sst_types.h"
16 #include "sst/core/warnmacros.h"
21 #include "sst/core/simulation.h"
22 #include "sst/core/statapi/statengine.h"
23 #include "sst/core/statapi/statbase.h"
24 #include "sst/core/event.h"
25 #include "sst/core/clock.h"
26 #include "sst/core/oneshot.h"
27 #include "sst/core/componentInfo.h"
28 #include "sst/core/eli/elementinfo.h"
30 using namespace SST::Statistics;
39 class Simulation_impl;
44 class SharedRegionMerger;
46 class ComponentExtension;
48 class SubComponentSlotInfo;
63 const std::string& ,
const std::string& ,
Params&)>;
70 const std::string& getType()
const {
return my_info->getType(); }
73 inline ComponentId_t
getId()
const {
return my_info->id; }
85 inline const std::string&
getName()
const {
return my_info->getName(); }
94 virtual void init(
unsigned int UNUSED(phase)) {}
97 virtual void complete(
unsigned int UNUSED(phase)) {}
117 SimTime_t getCurrentSimCycle()
const;
119 int getCurrentPriority()
const;
129 Output& getSimulationOutput()
const;
138 return getCurrentSimTime(my_info->defaultTimeBase);
142 SimTime_t getCurrentSimTime(
const std::string& base)
const;
145 SimTime_t getCurrentSimTimeNano()
const;
147 SimTime_t getCurrentSimTimeMicro()
const;
149 SimTime_t getCurrentSimTimeMilli()
const;
154 bool isPortConnected(
const std::string& name)
const;
170 Link* configureLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
192 Link* configureSelfLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
250 TimeConverter* registerTimeBase(
const std::string& base,
bool regAll =
true);
252 TimeConverter* getTimeConverter(
const std::string& base )
const;
259 bool isStatisticShared(
const std::string& statName,
bool include_me =
false) {
261 if ( doesComponentInfoStatisticExist(statName)) {
265 if ( my_info->sharesStatistics() ) {
266 return my_info->parent_info->component->isStatisticShared(statName,
true);
273 template <
typename T>
274 Statistics::Statistic<T>* createStatistic(
SST::Params& params, StatisticId_t
id,
const std::string& name,
275 const std::string& statSubId) {
283 StatCreateFunction create = [=](BaseComponent* comp, Statistics::StatisticProcessingEngine* engine,
284 const std::string& type,
const std::string& name,
const std::string& subId,
285 SST::Params& params) -> Statistics::StatisticBase* {
286 return engine->createStatistic<T>(comp, type, name, subId, params);
293 Statistics::StatisticBase* base_stat
294 =
id == STATALL_ID ? createEnabledAllStatistic(params, name, statSubId, std::move(create))
295 : getParentComponent()->createExplicitlyEnabledStatistic(params, id, name, statSubId,
299 auto* statistic =
dynamic_cast<Statistics::Statistic<T>*
>(base_stat);
303 fatal(__LINE__, __FILE__,
"createStatistic", 1,
"failed to cast created statistic '%s' to expected type",
309 template <
typename T>
310 Statistics::Statistic<T>* createNullStatistic(
SST::Params& params,
const std::string& name,
311 const std::string& statSubId =
"") {
312 auto* engine = Statistics::StatisticProcessingEngine::getInstance();
313 return engine->createStatistic<T>(my_info->component,
"sst.NullStatistic", name, statSubId, params);
332 template <
typename T>
334 const std::string& statSubId =
"",
bool inserting =
false) {
335 if (my_info->enabledStatNames) {
336 auto iter = my_info->enabledStatNames->find(statName);
337 if (iter != my_info->enabledStatNames->end()) {
341 StatisticId_t
id = iter->second;
342 return createStatistic<T>(params, id, statName, statSubId);
347 if (inserting || doesComponentInfoStatisticExist(statName)) {
349 if (my_info->enabledAllStats) {
350 return createStatistic<T>(params, STATALL_ID, statName, statSubId);
351 }
else if (my_info->parent_info && my_info->canInsertStatistics()) {
355 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId,
true);
358 return my_info->component->createNullStatistic<T>(params, statName, statSubId);
360 }
else if (my_info->parent_info && my_info->sharesStatistics()) {
363 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId);
366 fatal(__LINE__, __FILE__,
"registerStatistic", 1,
"attempting to register unknown statistic '%s'",
372 template <
typename T>
375 return registerStatistic<T>(empty, statName, statSubId);
378 template <
typename... Args>
379 Statistics::Statistic<std::tuple<Args...>>* registerMultiStatistic(
const std::string& statName,
380 const std::string& statSubId =
"") {
382 return registerStatistic<std::tuple<Args...>>(empty, statName, statSubId);
385 template <
typename... Args>
386 Statistics::Statistic<std::tuple<Args...>>* registerMultiStatistic(
SST::Params& params,
const std::string& statName,
387 const std::string& statSubId =
"") {
388 return registerStatistic<std::tuple<Args...>>(params, statName, statSubId);
391 template <
typename T>
392 Statistics::Statistic<T>* registerStatistic(
const char* statName,
const char* statSubId =
"") {
393 return registerStatistic<T>(std::string(statName), std::string(statSubId));
400 void performStatisticOutput(Statistics::StatisticBase* stat);
407 void performGlobalStatisticOutput();
414 Module* loadModule(
const std::string& type, Params& params);
421 template <
class T,
class... ARGS>
425 return Factory::getFactory()->Create<T>(type, params, params, args...);
435 template <
class T,
class... ARGS>
436 T* loadComponentExtension(ARGS... args) {
438 return static_cast<T*
>(ret);
449 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
466 const std::map<ComponentId_t,ComponentInfo>& subcomps = my_info->getSubComponents();
469 for (
auto &ci : subcomps ) {
470 if ( ci.second.getSlotName() == slot_name ) {
471 index = ci.second.getSlotNum();
476 if ( sub_count > 1 ) {
478 outXX.
fatal(CALL_INFO, 1,
"Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
479 slot_name.c_str(), my_info->getType().c_str(), sub_count);
482 return isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name,index);
501 template <
class T,
class... ARGS>
504 share_flags = share_flags & ComponentInfo::USER_FLAGS;
505 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
509 if ( sub_info ==
nullptr )
return nullptr;
512 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
513 auto ret = Factory::getFactory()->Create<T>(type, params, sub_info->id, params, args...);
533 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
549 template <
class T,
class... ARGS>
555 const std::map<ComponentId_t,ComponentInfo>& subcomps = my_info->getSubComponents();
558 for (
auto &ci : subcomps ) {
559 if ( ci.second.getSlotName() == slot_name ) {
560 index = ci.second.getSlotNum();
565 if ( sub_count > 1 ) {
567 outXX.
fatal(CALL_INFO, 1,
"Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
568 slot_name.c_str(), my_info->getType().c_str(), sub_count);
571 return loadUserSubComponentByIndex<T,ARGS...>(slot_name, index, share_flags, args...);
594 void fatal(uint32_t line,
const char* file,
const char* func,
596 const char* format, ...) const
597 __attribute__ ((format (printf, 6, 7))) ;
623 void sst_assert(
bool condition, uint32_t line, const
char* file, const
char* func,
625 const
char* format, ...) const
626 __attribute__ ((format (printf, 7, 8)));
630 void configureCollectionMode(Statistics::
StatisticBase* statistic, const SST::
Params& params,
631 const std::
string& name);
641 Statistics::
StatisticBase* createExplicitlyEnabledStatistic(SST::
Params& params, StatisticId_t
id,
642 const std::
string& name, const std::
string& statSubId,
643 StatCreateFunction create);
655 const std::
string& name, const std::
string& statSubId,
656 StatCreateFunction create);
658 Statistics::
StatisticBase* createEnabledAllStatistic(SST::
Params& params, const std::
string& name,
659 const std::
string& statSubId, StatCreateFunction create);
661 void configureAllowedStatParams(SST::
Params& params);
665 void pushValidParams(
Params& params, const std::
string& type);
667 template <class T, class... ARGS>
668 T* loadUserSubComponentByIndex(const std::
string& slot_name,
int slot_num,
int share_flags, ARGS... args) {
670 share_flags = share_flags & ComponentInfo::USER_FLAGS;
673 ComponentInfo* sub_info = my_info->findSubComponent(slot_name,slot_num);
674 if ( sub_info ==
nullptr )
return nullptr;
675 sub_info->share_flags = share_flags;
676 sub_info->parent_info = my_info;
678 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
679 auto ret = Factory::getFactory()->Create<T>(sub_info->type, *sub_info->params, sub_info->id, *sub_info->params, args...);
686 bool isUserSubComponentLoadableUsingAPIByIndex(
const std::string& slot_name,
int slot_num) {
688 ComponentInfo* sub_info = my_info->findSubComponent(slot_name,slot_num);
689 if ( sub_info ==
nullptr )
return false;
691 return isSubComponentLoadableUsingAPI<T>(sub_info->type);
695 void vfatal(uint32_t line,
const char* file,
const char* func,
697 const char* format, va_list arg)
const;
701 SubComponentSlotInfo* getSubComponentSlotInfo(
const std::string& name,
bool fatalOnEmptyIndex =
false);
705 return my_info->coordinates;
712 return my_info->isAnonymous();
716 return my_info->isUser();
721 my_info->defaultTimeBase = tc;
725 return my_info->defaultTimeBase;
728 const TimeConverter* getDefaultTimeBase()
const {
729 return my_info->defaultTimeBase;
732 bool doesSubComponentExist(
const std::string& type);
736 SharedRegion* getLocalSharedRegion(
const std::string& key,
size_t size) __attribute__ ((deprecated(
"SharedRegion and its accompanying classes have been deprecated and will be removed in SST 12. Please use the new SharedObject classes found in sst/core/shared.")));
737 SharedRegion* getGlobalSharedRegion(
const std::string& key,
size_t size, SharedRegionMerger *merger =
nullptr) __attribute__ ((deprecated("SharedRegion and its accompanying classes have been deprecated and will be removed in SST 12. Please use the new SharedObject classes found in sst/core/shared.")));
740 Simulation* getSimulation() const;
743 virtual
bool doesComponentInfoStatisticExist(const std::
string& statisticName) const;
745 uint8_t getComponentInfoStatisticEnableLevel(const std::
string& statisticName) const;
751 ComponentInfo* my_info;
754 void addSelfLink(const std::
string& name);
755 Link* getLinkFromParentSharedPort(const std::
string& port);
757 using StatNameMap = std::map<std::
string, std::map<std::
string, Statistics::
StatisticBase*>>;
759 std::map<StatisticId_t, Statistics::StatisticBase*> m_explicitlyEnabledSharedStats;
760 std::map<StatisticId_t, StatNameMap> m_explicitlyEnabledUniqueStats;
761 StatNameMap m_enabledAllStats;
763 BaseComponent* getParentComponent() {
764 ComponentInfo* base_info = my_info;
765 while (base_info->parent_info) {
766 base_info = base_info->parent_info;
768 return base_info->component;
781 std::string slot_name;
793 const std::map<ComponentId_t,ComponentInfo>& subcomps = comp->my_info->getSubComponents();
797 for (
auto &ci : subcomps ) {
798 if ( ci.second.getSlotName() == slot_name ) {
799 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
800 max_slot_index = ci.second.getSlotNum();
806 const std::string& getSlotName()
const {
810 bool isPopulated(
int slot_num)
const {
811 if ( slot_num > max_slot_index )
return false;
812 if ( comp->my_info->findSubComponent(slot_name,slot_num) == nullptr )
return false;
816 bool isAllPopulated()
const {
817 for (
int i = 0; i < max_slot_index; ++i ) {
818 if ( comp->my_info->findSubComponent(slot_name,i) == nullptr )
return false;
823 int getMaxPopulatedSlotNumber()
const {
824 return max_slot_index;
836 return comp->isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name,slot_num);
856 template <
typename T>
860 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
878 template <
class T,
class... ARGS>
879 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const {
880 return comp->loadUserSubComponentByIndex<T,ARGS...>(slot_name,slot_num, share_flags, args...);
902 template <
typename T,
class... ARGS>
903 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
904 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
905 T* sub = create<T>(i, share_flags, args...);
927 template <
typename T,
class... ARGS>
928 void createAllSparse(std::vector<std::pair<int,T*> >& vec, uint64_t share_flags, ARGS... args)
const {
929 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
930 T* sub = create<T>(i, share_flags, args...);
931 if ( sub !=
nullptr ) vec.push_back(i,sub);
951 template <
typename T,
class... ARGS>
952 void createAllSparse(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
953 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
954 T* sub = create<T>(i, share_flags, args...);
955 if ( sub !=
nullptr ) vec.push_back(sub);
965 #endif // SST_CORE_BASECOMPONENT_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
Statistics::Statistic< T > * registerStatistic(SST::Params ¶ms, const std::string &statName, const std::string &statSubId="", bool inserting=false)
Registers a statistic.
Definition: baseComponent.h:333
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:89
virtual void complete(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:97
virtual void printStatus(Output &UNUSED(out))
Called by the Simulation to request that the component print it's current status. ...
Definition: baseComponent.h:113
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: baseComponent.h:448
ComponentId_t getId() const
Returns unique component ID.
Definition: baseComponent.h:73
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:879
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:25
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:952
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:903
virtual void finish()
Called after simulation completes, but before objects are destroyed.
Definition: baseComponent.h:103
T * loadUserSubComponent(const std::string &slot_name)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:532
Forms the base class for statistics gathering within SST.
Definition: statbase.h:64
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:502
ComponentExtension is a class that can be loaded using loadComponentExtension<T>(...).
Definition: componentExtension.h:29
virtual void emergencyShutdown(void)
Called when SIGINT or SIGTERM has been seen.
Definition: baseComponent.h:81
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:422
uint8_t getStatisticLoadLevel() const
Returns Component Statistic load level.
Definition: baseComponent.h:76
const std::vector< double > & getCoordinates() const
Retrieve the X,Y,Z coordinates of this component.
Definition: baseComponent.h:704
virtual void setup()
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: baseComponent.h:100
bool isUserSubComponentLoadableUsingAPI(const std::string &slot_name)
Check to see if the element type loaded by the user into the.
Definition: baseComponent.h:462
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:550
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:928
Definition: rankInfo.h:21
Functor classes for Clock handling.
Definition: clock.h:41
Main component object for the simulation.
Definition: baseComponent.h:53
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:835
virtual bool Status()
Currently unused function.
Definition: baseComponent.h:106
Parameter store.
Definition: params.h:44
Functor classes for Event handling.
Definition: event.h:102
Definition: componentInfo.h:40
Used to load SubComponents when multiple SubComponents are loaded into a single slot (will also also ...
Definition: baseComponent.h:778
T * create(int slot_num) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:857
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:52
const std::string & getName() const
Returns Component/SubComponent Name.
Definition: baseComponent.h:85
Performs Unit math in full precision.
Definition: unitAlgebra.h:107
void setDefaultTimeBase(TimeConverter *tc)
Manually set the default detaulTimeBase.
Definition: baseComponent.h:720
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29
SimTime_t getCurrentSimTime() const
return the time since the simulation began in the default timebase
Definition: baseComponent.h:137
Link between two components.
Definition: link.h:32
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:94