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;
41 class SharedRegionMerger;
42 class Simulation_impl;
44 class SubComponentSlotInfo;
62 const std::string& ,
const std::string& ,
Params&)>;
69 const std::string& getType()
const {
return my_info->getType(); }
72 inline ComponentId_t
getId()
const {
return my_info->id; }
83 inline const std::string&
getName()
const {
return my_info->getName(); }
91 virtual void init(
unsigned int UNUSED(phase)) {}
94 virtual void complete(
unsigned int UNUSED(phase)) {}
113 SimTime_t getCurrentSimCycle()
const;
115 int getCurrentPriority()
const;
125 Output& getSimulationOutput()
const;
135 SimTime_t getCurrentSimTime(
const std::string& base)
const;
138 SimTime_t getCurrentSimTimeNano()
const;
140 SimTime_t getCurrentSimTimeMicro()
const;
142 SimTime_t getCurrentSimTimeMilli()
const;
146 bool isPortConnected(
const std::string& name)
const;
162 Link* configureLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
192 configureSelfLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
256 TimeConverter* registerTimeBase(
const std::string& base,
bool regAll =
true);
258 TimeConverter* getTimeConverter(
const std::string& base)
const;
265 bool isStatisticShared(
const std::string& statName,
bool include_me =
false)
268 if ( doesComponentInfoStatisticExist(statName) ) {
return true; }
270 if ( my_info->sharesStatistics() ) {
271 return my_info->parent_info->component->isStatisticShared(statName,
true);
278 template <
typename T>
279 Statistics::Statistic<T>*
280 createStatistic(
SST::Params& params, StatisticId_t
id,
const std::string& name,
const std::string& statSubId)
289 StatCreateFunction create = [=](BaseComponent* comp, Statistics::StatisticProcessingEngine* engine,
290 const std::string& type,
const std::string& name,
const std::string& subId,
291 SST::Params& params) -> Statistics::StatisticBase* {
292 return engine->createStatistic<T>(comp, type, name, subId, params);
299 Statistics::StatisticBase* base_stat =
300 id == STATALL_ID ? createEnabledAllStatistic(params, name, statSubId, std::move(create))
301 : getParentComponent()->createExplicitlyEnabledStatistic(
302 params, id, name, statSubId, std::move(create));
305 auto* statistic =
dynamic_cast<Statistics::Statistic<T>*
>(base_stat);
306 if ( statistic ) {
return statistic; }
309 __LINE__, __FILE__,
"createStatistic", 1,
"failed to cast created statistic '%s' to expected type",
315 template <
typename T>
316 Statistics::Statistic<T>*
317 createNullStatistic(
SST::Params& params,
const std::string& name,
const std::string& statSubId =
"")
319 auto* engine = Statistics::StatisticProcessingEngine::getInstance();
320 return engine->createStatistic<T>(my_info->component,
"sst.NullStatistic", name, statSubId, params);
339 template <
typename T>
341 SST::Params& params,
const std::string& statName,
const std::string& statSubId =
"",
bool inserting =
false)
343 if ( my_info->enabledStatNames ) {
344 auto iter = my_info->enabledStatNames->find(statName);
345 if ( iter != my_info->enabledStatNames->end() ) {
349 StatisticId_t
id = iter->second;
350 return createStatistic<T>(params, id, statName, statSubId);
355 if ( inserting || doesComponentInfoStatisticExist(statName) ) {
357 if ( my_info->enabledAllStats ) {
return createStatistic<T>(params, STATALL_ID, statName, statSubId); }
358 else if ( my_info->parent_info && my_info->canInsertStatistics() ) {
362 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId,
true);
366 return my_info->component->createNullStatistic<T>(params, statName, statSubId);
369 else if ( my_info->parent_info && my_info->sharesStatistics() ) {
372 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId);
377 __LINE__, __FILE__,
"registerStatistic", 1,
"attempting to register unknown statistic '%s'",
383 template <
typename T>
387 return registerStatistic<T>(empty, statName, statSubId);
390 template <
typename... Args>
391 Statistics::Statistic<std::tuple<Args...>>*
392 registerMultiStatistic(
const std::string& statName,
const std::string& statSubId =
"")
395 return registerStatistic<std::tuple<Args...>>(empty, statName, statSubId);
398 template <
typename... Args>
399 Statistics::Statistic<std::tuple<Args...>>*
400 registerMultiStatistic(
SST::Params& params,
const std::string& statName,
const std::string& statSubId =
"")
402 return registerStatistic<std::tuple<Args...>>(params, statName, statSubId);
405 template <
typename T>
406 Statistics::Statistic<T>* registerStatistic(
const char* statName,
const char* statSubId =
"")
408 return registerStatistic<T>(std::string(statName), std::string(statSubId));
415 void performStatisticOutput(Statistics::StatisticBase* stat);
422 void performGlobalStatisticOutput();
429 Module* loadModule(
const std::string& type, Params& params);
436 template <
class T,
class... ARGS>
441 return Factory::getFactory()->CreateWithParams<T>(type, params, params, args...);
450 template <
class T,
class... ARGS>
451 T* loadComponentExtension(ARGS... args)
454 return static_cast<T*
>(ret);
466 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
484 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
487 for (
auto& ci : subcomps ) {
488 if ( ci.second.getSlotName() == slot_name ) {
489 index = ci.second.getSlotNum();
494 if ( sub_count > 1 ) {
498 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
499 slot_name.c_str(), my_info->getType().c_str(), sub_count);
502 return isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, index);
521 template <
class T,
class... ARGS>
523 const std::string& type,
const std::string& slot_name,
int slot_num, uint64_t share_flags,
Params& params,
527 share_flags = share_flags & ComponentInfo::USER_FLAGS;
528 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
532 if ( sub_info ==
nullptr )
return nullptr;
535 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
536 auto ret = Factory::getFactory()->CreateWithParams<T>(type, params, sub_info->id, params, args...);
556 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
572 template <
class T,
class... ARGS>
579 const std::map<ComponentId_t, ComponentInfo>& subcomps = my_info->getSubComponents();
582 for (
auto& ci : subcomps ) {
583 if ( ci.second.getSlotName() == slot_name ) {
584 index = ci.second.getSlotNum();
589 if ( sub_count > 1 ) {
593 "Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
594 slot_name.c_str(), my_info->getType().c_str(), sub_count);
597 return loadUserSubComponentByIndex<T, ARGS...>(slot_name, index, share_flags, args...);
620 void fatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, ...) const
621 __attribute__((format(printf, 6, 7)));
647 bool condition, uint32_t line, const
char* file, const
char* func,
int exit_code, const
char* format, ...) const
648 __attribute__((format(printf, 7, 8)));
652 configureCollectionMode(Statistics::
StatisticBase* statistic, const SST::
Params& params, const std::
string& name);
663 SST::
Params& params, StatisticId_t
id, const std::
string& name, const std::
string& statSubId,
664 StatCreateFunction create);
676 SST::
Params& cpp_params, const SST::
Params& python_params, const std::
string& name,
677 const std::
string& statSubId, StatCreateFunction create);
680 SST::
Params& params, const std::
string& name, const std::
string& statSubId, StatCreateFunction create);
682 void configureAllowedStatParams(SST::
Params& params);
686 void pushValidParams(
Params& params, const std::
string& type);
688 template <class T, class... ARGS>
689 T* loadUserSubComponentByIndex(const std::
string& slot_name,
int slot_num,
int share_flags, ARGS... args)
692 share_flags = share_flags & ComponentInfo::USER_FLAGS;
695 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
696 if ( sub_info ==
nullptr )
return nullptr;
697 sub_info->share_flags = share_flags;
698 sub_info->parent_info = my_info;
700 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
701 auto ret = Factory::getFactory()->CreateWithParams<T>(
702 sub_info->type, *sub_info->params, sub_info->id, *sub_info->params, args...);
709 bool isUserSubComponentLoadableUsingAPIByIndex(
const std::string& slot_name,
int slot_num)
712 ComponentInfo* sub_info = my_info->findSubComponent(slot_name, slot_num);
713 if ( sub_info ==
nullptr )
return false;
715 return isSubComponentLoadableUsingAPI<T>(sub_info->type);
720 vfatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, va_list arg)
const;
723 SubComponentSlotInfo* getSubComponentSlotInfo(
const std::string& name,
bool fatalOnEmptyIndex =
false);
726 const std::vector<double>&
getCoordinates()
const {
return my_info->coordinates; }
731 bool isAnonymous() {
return my_info->isAnonymous(); }
733 bool isUser() {
return my_info->isUser(); }
738 TimeConverter* getDefaultTimeBase() {
return my_info->defaultTimeBase; }
740 const TimeConverter* getDefaultTimeBase()
const {
return my_info->defaultTimeBase; }
742 bool doesSubComponentExist(
const std::string& type);
745 SharedRegion* getLocalSharedRegion(
const std::string& key,
size_t size)
746 __attribute__((deprecated(
"SharedRegion and its accompanying classes have been deprecated and will be removed "
747 "in SST 12. Please use the new SharedObject classes found in sst/core/shared.")));
748 SharedRegion* getGlobalSharedRegion(
const std::string& key,
size_t size, SharedRegionMerger* merger =
nullptr)
749 __attribute__((deprecated("SharedRegion and its accompanying classes have been deprecated and will be removed "
750 "in SST 12. Please use the new SharedObject classes found in sst/core/shared.")));
753 Simulation* getSimulation() const;
756 virtual
bool doesComponentInfoStatisticExist(const std::
string& statisticName) const;
758 uint8_t getComponentInfoStatisticEnableLevel(const std::
string& statisticName) const;
763 ComponentInfo* my_info;
766 void addSelfLink(const std::
string& name);
767 Link* getLinkFromParentSharedPort(const std::
string& port);
769 using StatNameMap = std::map<std::
string, std::map<std::
string, Statistics::
StatisticBase*>>;
771 std::map<StatisticId_t, Statistics::StatisticBase*> m_explicitlyEnabledSharedStats;
772 std::map<StatisticId_t, StatNameMap> m_explicitlyEnabledUniqueStats;
773 StatNameMap m_enabledAllStats;
775 BaseComponent* getParentComponent()
777 ComponentInfo* base_info = my_info;
778 while ( base_info->parent_info ) {
779 base_info = base_info->parent_info;
781 return base_info->component;
794 std::string slot_name;
802 const std::map<ComponentId_t, ComponentInfo>& subcomps = comp->my_info->getSubComponents();
806 for (
auto& ci : subcomps ) {
807 if ( ci.second.getSlotName() == slot_name ) {
808 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
809 max_slot_index = ci.second.getSlotNum();
815 const std::string& getSlotName()
const {
return slot_name; };
817 bool isPopulated(
int slot_num)
const
819 if ( slot_num > max_slot_index )
return false;
820 if ( comp->my_info->findSubComponent(slot_name, slot_num) == nullptr )
return false;
824 bool isAllPopulated()
const
826 for (
int i = 0; i < max_slot_index; ++i ) {
827 if ( comp->my_info->findSubComponent(slot_name, i) == nullptr )
return false;
832 int getMaxPopulatedSlotNumber()
const {
return max_slot_index; }
844 return comp->isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name, slot_num);
863 template <
typename T>
867 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
884 template <
class T,
class... ARGS>
885 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const
887 return comp->loadUserSubComponentByIndex<T, ARGS...>(slot_name, slot_num, share_flags, args...);
908 template <
typename T,
class... ARGS>
909 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const
911 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
912 T* sub = create<T>(i, share_flags, args...);
934 template <
typename T,
class... ARGS>
935 void createAllSparse(std::vector<std::pair<int, T*>>& vec, uint64_t share_flags, ARGS... args)
const
937 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
938 T* sub = create<T>(i, share_flags, args...);
939 if ( sub !=
nullptr ) vec.push_back(i, sub);
959 template <
typename T,
class... ARGS>
962 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
963 T* sub = create<T>(i, share_flags, args...);
964 if ( sub !=
nullptr ) vec.push_back(sub);
971 #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:340
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:87
virtual void complete(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:94
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:464
ComponentId_t getId() const
Returns unique component ID.
Definition: baseComponent.h:72
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:885
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:960
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:909
virtual void finish()
Called after simulation completes, 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:554
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:522
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:80
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:437
uint8_t getStatisticLoadLevel() const
Returns Component Statistic load level.
Definition: baseComponent.h:75
const std::vector< double > & getCoordinates() const
Retrieve the X,Y,Z coordinates of this component.
Definition: baseComponent.h:726
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:479
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:573
Definition: rankInfo.h:21
Main component object for the simulation.
Definition: baseComponent.h:51
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:842
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:935
Parameter store.
Definition: params.h:43
Definition: componentInfo.h:39
Used to load SubComponents when multiple SubComponents are loaded into a single slot (will also also ...
Definition: baseComponent.h:790
T * create(int slot_num) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:864
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:83
Performs Unit math in full precision.
Definition: unitAlgebra.h:106
void setDefaultTimeBase(TimeConverter *tc)
Manually set the default detaulTimeBase.
Definition: baseComponent.h:736
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:132
Link between two components.
Definition: link.h:31
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:91