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;
43 class SharedRegionMerger;
45 class ComponentExtension;
47 class SubComponentSlotInfo;
65 const std::string& getType()
const {
return my_info->getType(); }
68 inline ComponentId_t
getId()
const {
return my_info->id; }
78 inline const std::string&
getName()
const {
return my_info->getName(); }
83 virtual void init(
unsigned int UNUSED(phase)) {}
86 virtual void complete(
unsigned int UNUSED(phase)) {}
106 SimTime_t getCurrentSimCycle()
const;
108 int getCurrentPriority()
const;
118 Output& getSimulationOutput()
const;
127 return getCurrentSimTime(my_info->defaultTimeBase);
131 SimTime_t getCurrentSimTime(
const std::string& base)
const;
134 SimTime_t getCurrentSimTimeNano()
const;
136 SimTime_t getCurrentSimTimeMicro()
const;
138 SimTime_t getCurrentSimTimeMilli()
const;
144 bool isPortConnected(
const std::string& name)
const;
160 Link* configureLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
182 Link* configureSelfLink(
const std::string& name,
const std::string& time_base,
Event::HandlerBase* handler =
nullptr);
239 TimeConverter* registerOneShot(
const std::string& timeDelay,
OneShot::HandlerBase* handler) __attribute__ ((deprecated(
"registerOneShot is deprecated and will be removed in SST 11. Please use configureSelfLink to create a mechanism for waking up Component/SubComponents")));
240 TimeConverter* registerOneShot(
const UnitAlgebra& timeDelay,
OneShot::HandlerBase* handler) __attribute__ ((deprecated(
"registerOneShot is deprecated and will be removed in SST 11. Please use configureSelfLink to create a mechanism for waking up Component/SubComponents")));
250 TimeConverter* registerTimeBase(
const std::string& base,
bool regAll =
true);
252 TimeConverter* getTimeConverter(
const std::string& base )
const;
260 bool isStatisticShared(
const std::string& statName,
bool include_me =
false) {
262 if ( doesComponentInfoStatisticExist(statName)) {
266 if ( my_info->sharesStatistics() ) {
267 return my_info->parent_info->component->isStatisticShared(statName,
true);
291 template <
typename T>
296 if (
false == doesComponentInfoStatisticExist(statName)) {
298 if ( my_info->sharesStatistics() ) {
299 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId);
302 printf(
"Error: Statistic %s name %s is not found in ElementInfoStatistic, exiting...\n",
303 StatisticBase::buildStatisticFullName(getName().c_str(), statName, statSubId).c_str(),
309 auto* engine = StatisticProcessingEngine::getInstance();
314 auto makeInstance = [=](
const std::string& type,
BaseComponent* comp,
315 const std::string& name,
const std::string& subName,
317 return engine->createStatistic<T>(comp, type, name, subName, params);
320 std::move(makeInstance));
325 template <
typename T>
326 Statistic<T>* registerStatistic(
const std::string& statName,
const std::string& statSubId =
"")
329 return registerStatistic<T>(empty, statName, statSubId);
332 template <
typename... Args>
333 Statistic<std::tuple<Args...>>* registerMultiStatistic(
const std::string& statName,
const std::string& statSubId =
"")
336 return registerStatistic<std::tuple<Args...>>(empty, statName, statSubId);
339 template <
typename... Args>
340 Statistic<std::tuple<Args...>>* registerMultiStatistic(
SST::Params& params,
const std::string& statName,
341 const std::string& statSubId =
"")
343 return registerStatistic<std::tuple<Args...>>(params, statName, statSubId);
346 template <
typename T>
347 Statistic<T>* registerStatistic(
const char* statName,
const char* statSubId =
"")
349 return registerStatistic<T>(std::string(statName), std::string(statSubId));
363 void performGlobalStatisticOutput();
370 Module* loadModule(
const std::string& type, Params& params);
377 template <
class T,
class... ARGS>
381 return Factory::getFactory()->Create<T>(type, params, params, args...);
391 template <
class T,
class... ARGS>
392 T* loadComponentExtension(ARGS... args) {
394 return static_cast<T*
>(ret);
405 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
422 const std::map<ComponentId_t,ComponentInfo>& subcomps = my_info->getSubComponents();
425 for (
auto &ci : subcomps ) {
426 if ( ci.second.getSlotName() == slot_name ) {
427 index = ci.second.getSlotNum();
432 if ( sub_count > 1 ) {
434 outXX.
fatal(CALL_INFO, 1,
"Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
435 slot_name.c_str(), my_info->getType().c_str(), sub_count);
438 return isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name,index);
457 template <
class T,
class... ARGS>
460 share_flags = share_flags & ComponentInfo::USER_FLAGS;
461 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
465 if ( sub_info ==
nullptr )
return nullptr;
468 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
469 auto ret = Factory::getFactory()->Create<T>(type, params, sub_info->id, params, args...);
489 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
505 template <
class T,
class... ARGS>
511 const std::map<ComponentId_t,ComponentInfo>& subcomps = my_info->getSubComponents();
514 for (
auto &ci : subcomps ) {
515 if ( ci.second.getSlotName() == slot_name ) {
516 index = ci.second.getSlotNum();
521 if ( sub_count > 1 ) {
523 outXX.
fatal(CALL_INFO, 1,
"Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
524 slot_name.c_str(), my_info->getType().c_str(), sub_count);
527 return loadUserSubComponentByIndex<T,ARGS...>(slot_name, index, share_flags, args...);
550 void fatal(uint32_t line,
const char* file,
const char* func,
552 const char* format, ...) const
553 __attribute__ ((format (printf, 6, 7))) ;
579 void sst_assert(
bool condition, uint32_t line, const
char* file, const
char* func,
581 const
char* format, ...) const
582 __attribute__ ((format (printf, 7, 8)));
589 void pushValidParams(
Params& params, const std::
string& type);
591 template <class T, class... ARGS>
592 T* loadUserSubComponentByIndex(const std::
string& slot_name,
int slot_num,
int share_flags, ARGS... args) {
594 share_flags = share_flags & ComponentInfo::USER_FLAGS;
597 ComponentInfo* sub_info = my_info->findSubComponent(slot_name,slot_num);
598 if ( sub_info ==
nullptr )
return nullptr;
599 sub_info->share_flags = share_flags;
600 sub_info->parent_info = my_info;
604 if ( sub_info->getParams() != nullptr ) {
605 myParams.
insert(*sub_info->getParams());
608 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
609 auto ret = Factory::getFactory()->Create<T>(sub_info->type, myParams, sub_info->id, myParams, args...);
616 bool isUserSubComponentLoadableUsingAPIByIndex(
const std::string& slot_name,
int slot_num) {
618 ComponentInfo* sub_info = my_info->findSubComponent(slot_name,slot_num);
619 if ( sub_info ==
nullptr )
return false;
621 return isSubComponentLoadableUsingAPI<T>(sub_info->type);
625 void vfatal(uint32_t line,
const char* file,
const char* func,
627 const char* format, va_list arg)
const;
631 SubComponentSlotInfo* getSubComponentSlotInfo(
const std::string& name,
bool fatalOnEmptyIndex =
false);
635 return my_info->coordinates;
642 return my_info->isAnonymous();
646 return my_info->isUser();
651 my_info->defaultTimeBase = tc;
655 return my_info->defaultTimeBase;
658 bool doesSubComponentExist(
const std::string& type);
662 SharedRegion* getLocalSharedRegion(
const std::string& key,
size_t size);
663 SharedRegion* getGlobalSharedRegion(
const std::string& key,
size_t size, SharedRegionMerger *merger =
nullptr);
666 Simulation* getSimulation()
const {
return sim; }
669 virtual bool doesComponentInfoStatisticExist(
const std::string& statisticName)
const;
671 uint8_t getComponentInfoStatisticEnableLevel(
const std::string& statisticName)
const;
683 ComponentInfo* my_info;
686 void addSelfLink(
const std::string& name);
687 Link* getLinkFromParentSharedPort(
const std::string& port);
689 using CreateFxn = std::function<
StatisticBase*(
const std::string&,
690 BaseComponent*,
const std::string&,
const std::string&,
SST::Params&)>;
693 const std::string& statName,
const std::string& statSubId,
694 fieldType_t fieldType, CreateFxn&& fxn);
707 std::string slot_name;
719 const std::map<ComponentId_t,ComponentInfo>& subcomps = comp->my_info->getSubComponents();
723 for (
auto &ci : subcomps ) {
724 if ( ci.second.getSlotName() == slot_name ) {
725 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
726 max_slot_index = ci.second.getSlotNum();
732 const std::string& getSlotName()
const {
736 bool isPopulated(
int slot_num)
const {
737 if ( slot_num > max_slot_index )
return false;
738 if ( comp->my_info->findSubComponent(slot_name,slot_num) == nullptr )
return false;
742 bool isAllPopulated()
const {
743 for (
int i = 0; i < max_slot_index; ++i ) {
744 if ( comp->my_info->findSubComponent(slot_name,i) == nullptr )
return false;
749 int getMaxPopulatedSlotNumber()
const {
750 return max_slot_index;
762 return comp->isUserSubComponentLoadableUsingAPIByIndex<T>(slot_name,slot_num);
782 template <
typename T>
786 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
804 template <
class T,
class... ARGS>
805 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const {
806 return comp->loadUserSubComponentByIndex<T,ARGS...>(slot_name,slot_num, share_flags, args...);
828 template <
typename T,
class... ARGS>
829 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
830 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
831 T* sub = create<T>(i, share_flags, args...);
853 template <
typename T,
class... ARGS>
854 void createAllSparse(std::vector<std::pair<int,T*> >& vec, uint64_t share_flags, ARGS... args)
const {
855 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
856 T* sub = create<T>(i, share_flags, args...);
857 if ( sub !=
nullptr ) vec.push_back(i,sub);
877 template <
typename T,
class... ARGS>
878 void createAllSparse(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
879 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
880 T* sub = create<T>(i, share_flags, args...);
881 if ( sub !=
nullptr ) vec.push_back(sub);
893 #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
virtual void complete(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:86
virtual void printStatus(Output &UNUSED(out))
Called by the Simulation to request that the component print it's current status. ...
Definition: baseComponent.h:102
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: baseComponent.h:404
ComponentId_t getId() const
Returns unique component ID.
Definition: baseComponent.h:68
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:805
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:878
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:829
virtual void finish()
Called after simulation completes, but before objects are destroyed.
Definition: baseComponent.h:92
T * loadUserSubComponent(const std::string &slot_name)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:488
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:458
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:73
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:378
const std::vector< double > & getCoordinates() const
Retrieve the X,Y,Z coordinates of this component.
Definition: baseComponent.h:634
virtual void setup()
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: baseComponent.h:89
bool isUserSubComponentLoadableUsingAPI(const std::string &slot_name)
Check to see if the element type loaded by the user into the.
Definition: baseComponent.h:418
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:506
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:854
Definition: rankInfo.h:21
Functor classes for Clock handling.
Definition: clock.h:41
Main component object for the simulation.
Definition: baseComponent.h:52
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:761
virtual bool Status()
Currently unused function.
Definition: baseComponent.h:95
Parameter store.
Definition: params.h:44
Statistic< T > * registerStatistic(SST::Params ¶ms, const std::string &statName, const std::string &statSubId="")
Registers a statistic.
Definition: baseComponent.h:292
Functor classes for Event handling.
Definition: event.h:86
Definition: componentInfo.h:36
Used to load SubComponents when multiple SubComponents are loaded into a single slot (will also also ...
Definition: baseComponent.h:704
Definition: statfieldinfo.h:52
T * create(int slot_num) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:783
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:52
void insert(const std::string &key, const std::string &value, bool overwrite=true)
Add a key value pair into the param object.
Definition: params.cc:99
const std::string & getName() const
Returns component Name.
Definition: baseComponent.h:78
Performs Unit math in full precision.
Definition: unitAlgebra.h:107
void setDefaultTimeBase(TimeConverter *tc)
Manually set the default detaulTimeBase.
Definition: baseComponent.h:650
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:126
Link between two components.
Definition: link.h:32
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:83
Functor classes for OneShot handling.
Definition: oneshot.h:39