SST  13.1.0
Structural Simulation Toolkit
component.h
1 // Copyright 2009-2023 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2023, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_COMPONENT_H
13 #define SST_CORE_COMPONENT_H
14 
15 #include "sst/core/baseComponent.h"
16 #include "sst/core/eli/elementinfo.h"
17 #include "sst/core/sst_types.h"
18 
19 #include <map>
20 
21 using namespace SST::Statistics;
22 
23 namespace SST {
24 class SubComponent;
25 
26 /**
27  * Main component object for the simulation.
28  * All models inherit from this.
29  */
30 class Component : public BaseComponent
31 {
32 public:
33  SST_ELI_DECLARE_BASE(Component)
34  // declare extern to limit compile times
35  SST_ELI_DECLARE_CTOR_EXTERN(ComponentId_t,SST::Params&)
36  // These categories will print in sst-info in the order they are
37  // listed here
38  SST_ELI_DECLARE_INFO_EXTERN(
39  ELI::ProvidesCategory,
40  ELI::ProvidesParams,
41  ELI::ProvidesPorts,
42  ELI::ProvidesSubComponentSlots,
43  ELI::ProvidesStats,
44  ELI::ProvidesProfilePoints,
45  ELI::ProvidesAttributes)
46 
47  /** Constructor. Generally only called by the factory class.
48  @param id Unique component ID
49  */
50  Component(ComponentId_t id);
51  virtual ~Component();
52 
53  /** Register as a primary component, which allows the component to
54  specify when it is and is not OK to end simulation. The
55  simulator will not end simulation naturally (through use of
56  the Exit object) while any primary component has specified
57  primaryComponentDoNotEndSim(). However, it is still possible
58  for Actions other than Exit to end simulation. Once all
59  primary components have specified
60  primaryComponentOKToEndSim(), the Exit object will trigger and
61  end simulation.
62 
63  This must be called during simulation wireup (i.e during the
64  constructor for the component). By default, the state of the
65  primary component is set to OKToEndSim.
66 
67  If no component registers as a primary component, then the
68  Exit object will not be used for that simulation and
69  simulation termination must be accomplished through some other
70  mechanism (e.g. --stopAt flag, or some other Action object).
71 
72  @sa Component::primaryComponentDoNotEndSim()
73  @sa Component::primaryComponentOKToEndSim()
74  */
75  void registerAsPrimaryComponent();
76 
77  /** Tells the simulation that it should not exit. The component
78  will remain in this state until a call to
79  primaryComponentOKToEndSim().
80 
81  @sa Component::registerAsPrimaryComponent()
82  @sa Component::primaryComponentOKToEndSim()
83  */
84  void primaryComponentDoNotEndSim();
85 
86  /** Tells the simulation that it is now OK to end simulation.
87  Simulation will not end until all primary components have
88  called this function.
89 
90  @sa Component::registerAsPrimaryComponent()
91  @sa Component::primaryComponentDoNotEndSim()
92  */
93  void primaryComponentOKToEndSim();
94 
95 protected:
96  friend class SubComponent;
97 };
98 
99 } // namespace SST
100 
101 // These macros allow you to register a base class for a set of
102 // components that have the same (or substantially the same) ELI
103 // information. ELI information can be defined in the base class, and
104 // will be inherited by the child classes.
105 #define SST_ELI_REGISTER_COMPONENT_BASE(cls) \
106  SST_ELI_DECLARE_NEW_BASE(SST::Component,::cls) \
107  SST_ELI_NEW_BASE_CTOR(SST::ComponentId_t,SST::Params&)
108 
109 #define SST_ELI_REGISTER_COMPONENT_DERIVED_BASE(cls, base) \
110  SST_ELI_DECLARE_NEW_BASE(::base,::cls) \
111  SST_ELI_NEW_BASE_CTOR(SST::ComponentId_t,SST::Params&)
112 
113 // 'x' is needed because you can't pass ##__VAR_ARGS__ as the first
114 // item to the macro or you end up with a leading comma that won't
115 // compile.
116 #define ELI_GET_COMPONENT_DEFAULT(x, arg1, ...) arg1
117 
118 #define SST_ELI_REGISTER_COMPONENT(cls, lib, name, version, desc, cat, ...) \
119  SST_ELI_REGISTER_DERIVED(ELI_GET_COMPONENT_DEFAULT(,##__VA_ARGS__,SST::Component),cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
120  SST_ELI_CATEGORY_INFO(cat)
121 
122 #endif // SST_CORE_COMPONENT_H
Main component object for the simulation.
Definition: baseComponent.h:52
Main component object for the simulation.
Definition: component.h:31
Parameter store.
Definition: params.h:56
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29