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.")));
332 template <
class T,
class... ARGS>
336 return Factory::getFactory()->Create<T>(type, params, params, args...);
347 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...)).")));
350 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...)).")));
351 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...)).")));
360 template <
class T,
class... ARGS>
361 T* loadComponentExtension(ARGS... args) {
363 return static_cast<T*
>(ret);
373 return Factory::getFactory()->isSubComponentLoadableUsingAPI<T>(type);
392 template <
class T,
class... ARGS>
395 share_flags = share_flags & ComponentInfo::USER_FLAGS;
396 ComponentId_t cid = my_info->addAnonymousSubComponent(my_info, type, slot_name, slot_num, share_flags);
400 if ( sub_info == NULL )
return NULL;
403 if ( isSubComponentLoadableUsingAPI<T>(type) ) {
404 auto ret = Factory::getFactory()->Create<T>(type, params, sub_info->id, params, args...);
408 SubComponent* ret = loadLegacySubComponentPrivate(cid,type,params);
409 return dynamic_cast<T*
>(ret);
427 return loadUserSubComponent<T>(slot_name, ComponentInfo::SHARE_NONE);
443 template <
class T,
class... ARGS>
449 const std::map<ComponentId_t,ComponentInfo>& subcomps = my_info->getSubComponents();
452 for (
auto &ci : subcomps ) {
453 if ( ci.second.getSlotName() == slot_name ) {
454 index = ci.second.getSlotNum();
459 if ( sub_count > 1 ) {
461 outXX.
fatal(CALL_INFO, 1,
"Error: ComponentSlot \"%s\" in component \"%s\" only allows for one SubComponent, %d provided.\n",
462 slot_name.c_str(), my_info->getType().c_str(), sub_count);
465 return loadUserSubComponentByIndex<T,ARGS...>(slot_name, index, share_flags, args...);
470 SubComponent* loadNamedSubComponent(std::string name,
int slot_num);
476 SubComponent* loadLegacySubComponentPrivate(ComponentId_t cid,
const std::string& type,
Params& params);
486 void pushValidParams(
Params& params,
const std::string& type);
488 template <
class T,
class... ARGS>
489 T* loadUserSubComponentByIndex(std::string slot_name,
int slot_num,
int share_flags, ARGS... args) {
491 share_flags = share_flags & ComponentInfo::USER_FLAGS;
494 ComponentInfo* sub_info = my_info->findSubComponent(slot_name,slot_num);
495 if ( sub_info == NULL )
return NULL;
496 sub_info->share_flags = share_flags;
497 sub_info->parent_info = my_info;
501 if ( sub_info->getParams() != NULL ) {
502 myParams.
insert(*sub_info->getParams());
505 if ( isSubComponentLoadableUsingAPI<T>(sub_info->type) ) {
506 auto ret = Factory::getFactory()->Create<T>(sub_info->type, myParams, sub_info->id, myParams, args...);
510 SubComponent* ret = loadNamedSubComponentLegacyPrivate(sub_info,myParams);
511 return dynamic_cast<T*
>(ret);
517 ComponentInfo* getCurrentlyLoadingSubComponentInfo() {
return currentlyLoadingSubComponent; }
518 ComponentId_t getCurrentlyLoadingSubComponentID() {
return currentlyLoadingSubComponentID; }
522 SubComponentSlotInfo* getSubComponentSlotInfo(std::string name,
bool fatalOnEmptyIndex =
false);
526 return my_info->coordinates;
533 return my_info->isAnonymous();
537 return my_info->isUser();
542 my_info->defaultTimeBase = tc;
546 return my_info->defaultTimeBase;
549 bool doesSubComponentExist(std::string type);
553 SharedRegion* getLocalSharedRegion(
const std::string &key,
size_t size);
554 SharedRegion* getGlobalSharedRegion(
const std::string &key,
size_t size, SharedRegionMerger *merger = NULL);
557 Simulation* getSimulation()
const {
return sim; }
560 virtual bool doesComponentInfoStatisticExist(
const std::string &statisticName)
const;
562 uint8_t getComponentInfoStatisticEnableLevel(
const std::string &statisticName)
const;
567 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.")));
578 bool loadedWithLegacyAPI;
589 bool wasLoadedWithLegacyAPI()
const {
590 return loadedWithLegacyAPI;
597 ComponentId_t currentlyLoadingSubComponentID;
600 void addSelfLink(std::string name);
601 Link* getLinkFromParentSharedPort(
const std::string& port);
603 using CreateFxn = std::function<
StatisticBase*(
const std::string&,
607 const std::string& statName,
const std::string& statSubId,
608 fieldType_t fieldType, CreateFxn&& fxn);
610 Component* getTrueComponentPrivate()
const;
623 std::string slot_name;
629 if ( slot_num > max_slot_index )
return NULL;
631 return comp->loadNamedSubComponent(slot_name, slot_num, params);
645 const std::map<ComponentId_t,ComponentInfo>& subcomps = comp->my_info->getSubComponents();
649 for (
auto &ci : subcomps ) {
650 if ( ci.second.getSlotName() == slot_name ) {
651 if ( ci.second.getSlotNum() >
static_cast<int>(max_slot_index) ) {
652 max_slot_index = ci.second.getSlotNum();
658 const std::string& getSlotName()
const {
662 bool isPopulated(
int slot_num)
const {
663 if ( slot_num > max_slot_index )
return false;
664 if ( comp->my_info->findSubComponent(slot_name,slot_num) == NULL )
return false;
668 bool isAllPopulated()
const {
669 for (
int i = 0; i < max_slot_index; ++i ) {
670 if ( comp->my_info->findSubComponent(slot_name,i) == NULL )
return false;
675 int getMaxPopulatedSlotNumber()
const {
676 return max_slot_index;
682 template <
typename T>
683 __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.")))
684 T* create(
int slot_num,
Params& params)
const
686 return private_create<T>(slot_num,params);
689 template <
typename T>
690 __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.")))
691 void createAll(
Params& params, std::vector<T*>& vec,
bool insertNulls =
true)
const
693 return private_createAll<T>(params, vec, insertNulls);
696 template <
typename T>
697 __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.")))
698 void createAll(std::vector<T*>& vec,
bool insertNulls =
true)
const
701 return private_createAll<T>(empty, vec, insertNulls);
721 template <
typename T>
725 return comp->loadUserSubComponentByIndex<T>(slot_name, slot_num, ComponentInfo::SHARE_NONE);
743 template <
class T,
class... ARGS>
744 T*
create(
int slot_num, uint64_t share_flags, ARGS... args)
const {
745 return comp->loadUserSubComponentByIndex<T,ARGS...>(slot_name,slot_num, share_flags, args...);
767 template <
typename T,
class... ARGS>
768 void createAll(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
769 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
770 T* sub = create<T>(i, share_flags, args...);
792 template <
typename T,
class... ARGS>
793 void createAllSparse(std::vector<std::pair<int,T*> >& vec, uint64_t share_flags, ARGS... args)
const {
794 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
795 T* sub = create<T>(i, share_flags, args...);
796 if ( sub !=
nullptr ) vec.push_back(i,sub);
816 template <
typename T,
class... ARGS>
817 void createAllSparse(std::vector<T*>& vec, uint64_t share_flags, ARGS... args)
const {
818 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
819 T* sub = create<T>(i, share_flags, args...);
820 if ( sub !=
nullptr ) vec.push_back(sub);
828 template <
typename T>
829 T* private_create(
int slot_num,
Params& params)
const
836 T* cast_sub =
dynamic_cast<T*
>(sub);
837 if ( cast_sub == NULL ) {
841 "%s, index %d, which is not castable to correct time\n",
842 getSlotName().c_str(),slot_num);
847 template <
typename T>
848 void private_createAll(Params& params, std::vector<T*>& vec,
bool insertNulls =
true)
const
850 for (
int i = 0; i <= getMaxPopulatedSlotNumber(); ++i ) {
851 T* sub = create<T>(i, params);
852 if ( sub != NULL || insertNulls ) vec.push_back(sub);
862 #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:744
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:817
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:768
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:393
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:525
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:444
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:793
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:372
Definition: componentInfo.h:36
Used to load SubComponents when multiple SubComponents are loaded into a single slot (will also also ...
Definition: baseComponent.h:620
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:722
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:541
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 * loadModule(std::string type, Params ¶ms, ARGS...args)
Loads a module from an element Library.
Definition: baseComponent.h:333
T * loadUserSubComponent(std::string slot_name)
Loads a user defined subcomponent (defined in input file to SST run).
Definition: baseComponent.h:426
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