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/statapi/statengine.h>
22 #include <sst/core/statapi/statbase.h>
23 #include <sst/core/event.h>
24 #include <sst/core/clock.h>
25 #include <sst/core/oneshot.h>
26 #include <sst/core/componentInfo.h>
27 #include <sst/core/simulation.h>
28 #include <sst/core/eli/elementinfo.h>
30 using namespace SST::Statistics;
43 class SharedRegionMerger;
45 class ComponentExtension;
47 class SubComponentSlotInfo;
66 BaseComponent*
getParent() const __attribute__ ((deprecated("getParent() will be removed in SST version 10.0. With the new subcomponent structure, direct access to your parent is not allowed.")))
67 {
return my_info->parent_info->component; }
69 const std::string& getType()
const {
return my_info->getType(); }
72 inline ComponentId_t
getId()
const {
return my_info->id; }
82 inline const std::string&
getName()
const {
return my_info->getName(); }
87 virtual void init(
unsigned int UNUSED(phase)) {}
90 virtual void complete(
unsigned int UNUSED(phase)) {}
109 bool isPortConnected(
const std::string &name)
const;
194 TimeConverter* registerTimeBase( std::string base,
bool regAll =
true);
205 return getCurrentSimTime(my_info->defaultTimeBase);
209 SimTime_t getCurrentSimTime(std::string base);
212 SimTime_t getCurrentSimTimeNano()
const;
214 SimTime_t getCurrentSimTimeMicro()
const;
216 SimTime_t getCurrentSimTimeMilli()
const;
218 bool isStatisticShared(
const std::string& statName,
bool include_me =
false) {
220 if ( doesComponentInfoStatisticExist(statName)) {
224 if ( my_info->sharesStatistics() ) {
225 return my_info->parent_info->component->isStatisticShared(statName,
true);
249 template <
typename T>
254 if (
false == doesComponentInfoStatisticExist(statName)) {
256 if ( my_info->sharesStatistics() ) {
257 return my_info->parent_info->component->registerStatistic<T>(params, statName, statSubId);
260 printf(
"Error: Statistic %s name %s is not found in ElementInfoStatistic, exiting...\n",
261 StatisticBase::buildStatisticFullName(getName().c_str(), statName, statSubId).c_str(),
267 auto* engine = StatisticProcessingEngine::getInstance();
272 auto makeInstance = [=](
const std::string& type,
BaseComponent* comp,
273 const std::string& name,
const std::string& subName,
275 return engine->createStatistic<T>(comp, type, name, subName, params);
278 std::move(makeInstance));
283 template <
typename T>
284 Statistic<T>* registerStatistic(
const std::string& statName,
const std::string& statSubId =
"")
287 return registerStatistic<T>(empty, statName, statSubId);
290 template <
typename... Args>
291 Statistic<std::tuple<Args...>>* registerMultiStatistic(
const std::string& statName,
const std::string& statSubId =
"")
294 return registerStatistic<std::tuple<Args...>>(empty, statName, statSubId);
297 template <
typename... Args>
298 Statistic<std::tuple<Args...>>* registerMultiStatistic(
SST::Params& params,
const std::string& statName,
299 const std::string& statSubId =
"")
301 return registerStatistic<std::tuple<Args...>>(params, statName, statSubId);
304 template <
typename T>
305 Statistic<T>* registerStatistic(
const char* statName,
const char* statSubId =
"")
307 return registerStatistic<T>(std::string(statName), std::string(statSubId));
316 Module* loadModule(std::string type, Params& params);
324 Module* loadModuleWithComponent(std::string type, Component* comp, Params& params) __attribute__ ((deprecated(
"loadModuleWithComponent will be removed in SST version 10.0. If the module needs access to the parent component, please use SubComponents instead of Modules.")));
333 SubComponent* loadSubComponent(std::string type, Component* comp, Params& params) __attribute__ ((deprecated(
"This version of loadSubComponent will be removed in SST version 10.0. Please switch to new user defined API (LoadUserSubComponent(std::string, int, ARGS...)).")));
336 SubComponent* loadNamedSubComponent(std::string name) __attribute__ ((deprecated(
"This version of loadNamedSubComponent will be removed in SST version 10.0. Please switch to new user defined API (LoadUserSubComponent(std::string, int, ARGS...)).")));
337 SubComponent* loadNamedSubComponent(std::string name, Params& params) __attribute__ ((deprecated(
"This version of loadNamedSubComponent will be removed in SST version 10.0. Please switch to new user defined API (LoadUserSubComponent(std::string, int, ARGS...)).")));
346 template <
class T,
class... ARGS>
347 T* loadComponentExtension(ARGS... args) {
348 ComponentExtension* ret =
new T(my_info->id, args...);
349 return static_cast<T*
>(ret);
359 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
378 template <
class T,
class... ARGS>
381 share_flags = share_flags & ComponentInfo::USER_FLAGS;
382 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
386 if ( sub_info == NULL )
return NULL;
389 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
390 auto ret = Factory::getFactory()->Create<T>(type, params, sub_info->id, params, args...);
394 SubComponent* ret = loadLegacySubComponentPrivate(cid,type,params);
395 return dynamic_cast<T*
>(ret);
413 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
429 template <
class T,
class... ARGS>
435 const std::map<ComponentId_t,ComponentInfo>& subcomps = my_info->getSubComponents();
438 for (
auto &ci : subcomps ) {
439 if ( ci.second.getSlotName() == slot_name ) {
440 index = ci.second.getSlotNum();
445 if ( sub_count > 1 ) {
447 outXX.
fatal(CALL_INFO, 1,
"Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
448 slot_name.c_str(), my_info->getType().c_str(), sub_count);
451 return loadUserSubComponentByIndex<T,ARGS...>(slot_name, index, share_flags, args...);
456 SubComponent* loadNamedSubComponent(std::string name,
int slot_num);
462 SubComponent* loadLegacySubComponentPrivate(ComponentId_t cid,
const std::string& type,
Params& params);
472 void pushValidParams(
Params& params,
const std::string& type);
474 template <
class T,
class... ARGS>
475 T* loadUserSubComponentByIndex(std::string slot_name,
int slot_num,
int share_flags, ARGS... args) {
477 share_flags = share_flags & ComponentInfo::USER_FLAGS;
480 ComponentInfo* sub_info = my_info->findSubComponent(slot_name,slot_num);
481 if ( sub_info == NULL )
return NULL;
482 sub_info->share_flags = share_flags;
483 sub_info->parent_info = my_info;
487 if ( sub_info->getParams() != NULL ) {
488 myParams.
insert(*sub_info->getParams());
491 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
492 auto ret = Factory::getFactory()->Create<T>(sub_info->type, myParams, sub_info->id, myParams, args...);
496 SubComponent* ret = loadNamedSubComponentLegacyPrivate(sub_info,myParams);
497 return dynamic_cast<T*
>(ret);
503 ComponentInfo* getCurrentlyLoadingSubComponentInfo() {
return currentlyLoadingSubComponent; }
504 ComponentId_t getCurrentlyLoadingSubComponentID() {
return currentlyLoadingSubComponentID; }
508 SubComponentSlotInfo* getSubComponentSlotInfo(std::string name,
bool fatalOnEmptyIndex =
false);
512 return my_info->coordinates;
519 return my_info->isAnonymous();
523 return my_info->isUser();
528 my_info->defaultTimeBase = tc;
532 return my_info->defaultTimeBase;
535 bool doesSubComponentExist(std::string type);
539 SharedRegion* getLocalSharedRegion(
const std::string &key,
size_t size);
540 SharedRegion* getGlobalSharedRegion(
const std::string &key,
size_t size, SharedRegionMerger *merger = NULL);
543 Simulation* getSimulation()
const {
return sim; }
546 virtual bool doesComponentInfoStatisticExist(
const std::string &statisticName)
const;
548 uint8_t getComponentInfoStatisticEnableLevel(
const std::string &statisticName)
const;
553 Component* getTrueComponent() const __attribute__ ((deprecated("getTrueParent will be removed in SST version 10.0. With the new subcomponent structure, direct access to your parent component is not allowed.")));
564 bool loadedWithLegacyAPI;
575 bool wasLoadedWithLegacyAPI()
const {
576 return loadedWithLegacyAPI;
583 ComponentId_t currentlyLoadingSubComponentID;
586 void addSelfLink(std::string name);
587 Link* getLinkFromParentSharedPort(
const std::string& port);
589 using CreateFxn = std::function<
StatisticBase*(
const std::string&,
593 const std::string& statName,
const std::string& statSubId,
594 fieldType_t fieldType, CreateFxn&& fxn);
596 Component* getTrueComponentPrivate()
const;
609 std::string slot_name;
615 if ( slot_num > max_slot_index )
return NULL;
617 return comp->loadNamedSubComponent(slot_name, slot_num, params);
631 const std::map<ComponentId_t,ComponentInfo>& subcomps = comp->my_info->getSubComponents();
635 for (
auto &ci : subcomps ) {
636 if ( ci.second.getSlotName() == slot_name ) {
637 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
638 max_slot_index = ci.second.getSlotNum();
644 const std::string& getSlotName()
const {
648 bool isPopulated(
int slot_num)
const {
649 if ( slot_num > max_slot_index )
return false;
650 if ( comp->my_info->findSubComponent(slot_name,slot_num) == NULL )
return false;
654 bool isAllPopulated()
const {
655 for (
int i = 0; i < max_slot_index; ++i ) {
656 if ( comp->my_info->findSubComponent(slot_name,i) == NULL )
return false;
661 int getMaxPopulatedSlotNumber()
const {
662 return max_slot_index;
668 template <
typename T>
669 __attribute__ ((deprecated(
"This version of create will be removed in SST version 10.0. Please switch to the new user defined API, which includes the share flags.")))
670 T* create(
int slot_num,
Params& params)
const
672 return private_create<T>(slot_num,params);
675 template <
typename T>
676 __attribute__ ((deprecated(
"This version of createAll will be removed in SST version 10.0. Please switch to the new user defined API, which includes the share flags and optional constructor arguments.")))
677 void createAll(
Params& params, std::vector<T*>& vec,
bool insertNulls =
true)
const
679 return private_createAll<T>(params, vec, insertNulls);
682 template <
typename T>
683 __attribute__ ((deprecated(
"This version of createAll will be removed in SST version 10.0. Please switch to the new user defined API, which includes the share flags and optional constructor arguments.")))
684 void createAll(std::vector<T*>& vec,
bool insertNulls =
true)
const
687 return private_createAll<T>(empty, vec, insertNulls);
707 template <
typename T>
711 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
729 template <
class T,
class... ARGS>
730 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const {
731 return comp->loadUserSubComponentByIndex<T,ARGS...>(slot_name,slot_num, share_flags, args...);
753 template <
typename T,
class... ARGS>
754 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
755 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
756 T* sub = create<T>(i, share_flags, args...);
778 template <
typename T,
class... ARGS>
779 void createAllSparse(std::vector<std::pair<int,T*> >& vec, uint64_t share_flags, ARGS... args)
const {
780 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
781 T* sub = create<T>(i, share_flags, args...);
782 if ( sub !=
nullptr ) vec.push_back(i,sub);
802 template <
typename T,
class... ARGS>
803 void createAllSparse(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
804 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
805 T* sub = create<T>(i, share_flags, args...);
806 if ( sub !=
nullptr ) vec.push_back(sub);
814 template <
typename T>
815 T* private_create(
int slot_num,
Params& params)
const
822 T* cast_sub =
dynamic_cast<T*
>(sub);
823 if ( cast_sub == NULL ) {
827 "%s, index %d, which is not castable to correct time\n",
828 getSlotName().c_str(),slot_num);
833 template <
typename T>
834 void private_createAll(Params& params, std::vector<T*>& vec,
bool insertNulls =
true)
const
836 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
837 T* sub = create<T>(i, params);
838 if ( sub != NULL || insertNulls ) vec.push_back(sub);
848 #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:90
BaseComponent * getParent() const
Returns a pointer to the parent BaseComponent.
Definition: baseComponent.h:66
virtual void printStatus(Output &UNUSED(out))
Called by the Simulation to request that the component print it's current status. ...
Definition: baseComponent.h:106
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:730
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:803
Main component object for the simulation.
Definition: component.h:32
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:754
void insert(std::string key, std::string value, bool overwrite=true)
Add a key value pair into the param object.
Definition: params.cc:99
virtual void finish()
Called after simulation completes, but before objects are destroyed.
Definition: baseComponent.h:96
Forms the base class for statistics gathering within SST.
Definition: statbase.h:63
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:77
T * loadAnonymousSubComponent(std::string type, 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:379
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:43
const std::vector< double > & getCoordinates() const
Retrieve the X,Y,Z coordinates of this component.
Definition: baseComponent.h:511
static Output & getSimulationOutput()
Return the base simulation Output class instance.
Definition: simulation.h:178
virtual void setup()
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: baseComponent.h:93
T * loadUserSubComponent(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:430
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
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:779
Functor classes for Clock handling.
Definition: clock.h:44
Main component object for the simulation.
Definition: baseComponent.h:52
virtual bool Status()
Currently unused function.
Definition: baseComponent.h:99
Parameter store.
Definition: params.h:45
Statistic< T > * registerStatistic(SST::Params ¶ms, const std::string &statName, const std::string &statSubId="")
Registers a statistic.
Definition: baseComponent.h:250
Functor classes for Event handling.
Definition: event.h:86
bool isSubComponentLoadableUsingAPI(std::string type)
Check to see if a given element type is loadable with a particular API.
Definition: baseComponent.h:358
Definition: componentInfo.h:36
Used to load SubComponents when multiple SubComponents are loaded into a single slot (will also also ...
Definition: baseComponent.h:606
Definition: statfieldinfo.h:51
T * create(int slot_num) const
Create a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:708
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 Name.
Definition: baseComponent.h:82
Performs Unit math in full precision.
Definition: unitAlgebra.h:104
void setDefaultTimeBase(TimeConverter *tc)
Manually set the default detaulTimeBase.
Definition: baseComponent.h:527
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:30
SimTime_t getCurrentSimTime() const
return the time since the simulation began in the default timebase
Definition: baseComponent.h:204
Link between two components.
Definition: link.h:33
T * loadUserSubComponent(std::string slot_name)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:412
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:87
Functor classes for OneShot handling.
Definition: oneshot.h:39