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);
404 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
423 template <
class T,
class... ARGS>
426 share_flags = share_flags & ComponentInfo::USER_FLAGS;
427 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
431 if ( sub_info ==
nullptr )
return nullptr;
434 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
435 auto ret = Factory::getFactory()->Create<T>(type, params, sub_info->id, params, args...);
455 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
471 template <
class T,
class... ARGS>
477 const std::map<ComponentId_t,ComponentInfo>& subcomps = my_info->getSubComponents();
480 for (
auto &ci : subcomps ) {
481 if ( ci.second.getSlotName() == slot_name ) {
482 index = ci.second.getSlotNum();
487 if ( sub_count > 1 ) {
489 outXX.
fatal(CALL_INFO, 1,
"Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
490 slot_name.c_str(), my_info->getType().c_str(), sub_count);
493 return loadUserSubComponentByIndex<T,ARGS...>(slot_name, index, share_flags, args...);
517 void fatal(uint32_t line,
const char* file,
const char* func,
519 const char* format, ...) const
520 __attribute__ ((format (printf, 6, 7))) ;
546 void sst_assert(
bool condition, uint32_t line, const
char* file, const
char* func,
548 const
char* format, ...) const
549 __attribute__ ((format (printf, 7, 8)));
556 void pushValidParams(
Params& params, const std::
string& type);
558 template <class T, class... ARGS>
559 T* loadUserSubComponentByIndex(const std::
string& slot_name,
int slot_num,
int share_flags, ARGS... args) {
561 share_flags = share_flags & ComponentInfo::USER_FLAGS;
564 ComponentInfo* sub_info = my_info->findSubComponent(slot_name,slot_num);
565 if ( sub_info ==
nullptr )
return nullptr;
566 sub_info->share_flags = share_flags;
567 sub_info->parent_info = my_info;
571 if ( sub_info->getParams() != nullptr ) {
572 myParams.
insert(*sub_info->getParams());
575 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
576 auto ret = Factory::getFactory()->Create<T>(sub_info->type, myParams, sub_info->id, myParams, args...);
584 SubComponentSlotInfo* getSubComponentSlotInfo(
const std::string& name,
bool fatalOnEmptyIndex =
false);
588 return my_info->coordinates;
595 return my_info->isAnonymous();
599 return my_info->isUser();
604 my_info->defaultTimeBase = tc;
608 return my_info->defaultTimeBase;
611 bool doesSubComponentExist(
const std::string& type);
615 SharedRegion* getLocalSharedRegion(
const std::string& key,
size_t size);
616 SharedRegion* getGlobalSharedRegion(
const std::string& key,
size_t size, SharedRegionMerger *merger =
nullptr);
619 Simulation* getSimulation()
const {
return sim; }
622 virtual bool doesComponentInfoStatisticExist(
const std::string& statisticName)
const;
624 uint8_t getComponentInfoStatisticEnableLevel(
const std::string& statisticName)
const;
636 ComponentInfo* my_info;
639 void addSelfLink(
const std::string& name);
640 Link* getLinkFromParentSharedPort(
const std::string& port);
642 using CreateFxn = std::function<
StatisticBase*(
const std::string&,
643 BaseComponent*,
const std::string&,
const std::string&,
SST::Params&)>;
646 const std::string& statName,
const std::string& statSubId,
647 fieldType_t fieldType, CreateFxn&& fxn);
660 std::string slot_name;
672 const std::map<ComponentId_t,ComponentInfo>& subcomps = comp->my_info->getSubComponents();
676 for (
auto &ci : subcomps ) {
677 if ( ci.second.getSlotName() == slot_name ) {
678 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
679 max_slot_index = ci.second.getSlotNum();
685 const std::string& getSlotName()
const {
689 bool isPopulated(
int slot_num)
const {
690 if ( slot_num > max_slot_index )
return false;
691 if ( comp->my_info->findSubComponent(slot_name,slot_num) == nullptr )
return false;
695 bool isAllPopulated()
const {
696 for (
int i = 0; i < max_slot_index; ++i ) {
697 if ( comp->my_info->findSubComponent(slot_name,i) == nullptr )
return false;
702 int getMaxPopulatedSlotNumber()
const {
703 return max_slot_index;
723 template <
typename T>
727 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
745 template <
class T,
class... ARGS>
746 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const {
747 return comp->loadUserSubComponentByIndex<T,ARGS...>(slot_name,slot_num, share_flags, args...);
769 template <
typename T,
class... ARGS>
770 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
771 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
772 T* sub = create<T>(i, share_flags, args...);
794 template <
typename T,
class... ARGS>
795 void createAllSparse(std::vector<std::pair<int,T*> >& vec, uint64_t share_flags, ARGS... args)
const {
796 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
797 T* sub = create<T>(i, share_flags, args...);
798 if ( sub !=
nullptr ) vec.push_back(i,sub);
818 template <
typename T,
class... ARGS>
819 void createAllSparse(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
820 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
821 T* sub = create<T>(i, share_flags, args...);
822 if ( sub !=
nullptr ) vec.push_back(sub);
834 #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:403
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:746
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:819
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:770
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:454
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:424
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:587
virtual void setup()
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: baseComponent.h:89
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:472
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:795
Definition: rankInfo.h:21
Functor classes for Clock handling.
Definition: clock.h:41
Main component object for the simulation.
Definition: baseComponent.h:52
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:657
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:724
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:603
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