SST  7.1.0
StructuralSimulationToolkit
component.h
1 // Copyright 2009-2017 Sandia Corporation. Under the terms
2 // of Contract DE-NA0003525 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2017, Sandia Corporation
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/sst_types.h>
16 
17 #include <map>
18 #include <string>
19 
20 #include <sst/core/baseComponent.h>
21 
22 
23 using namespace SST::Statistics;
24 
25 namespace SST {
26 class SubComponent;
27 
28 /**
29  * Main component object for the simulation.
30  * All models inherit from this.
31  */
32 class Component: public BaseComponent {
33 public:
34 
35  /** Constructor. Generally only called by the factory class.
36  @param id Unique component ID
37  */
38  Component( ComponentId_t id );
39  virtual ~Component();
40 
41 
42  /** Register that the simulation should not end until this
43  component says it is OK to. Calling this function (generally
44  done in Component::setup() or in component constructor)
45  increments a global counter. Calls to
46  Component::unregisterExit() decrements the counter. The
47  simulation cannot end unless this counter reaches zero, or the
48  simulation time limit is reached. This counter is synchonized
49  periodically with the other nodes.
50 
51  @sa Component::unregisterExit()
52  */
53  bool registerExit();
54 
55  /** Indicate permission for the simulation to end. This function is
56  the mirror of Component::registerExit(). It decrements the
57  global counter, which, upon reaching zero, indicates that the
58  simulation can terminate. @sa Component::registerExit() */
59  bool unregisterExit();
60 
61  /** Register as a primary component, which allows the component to
62  specifiy when it is and is not OK to end simulation. The
63  simulator will not end simulation natuarally (through use of
64  the Exit object) while any primary component has specified
65  primaryComponentDoNotEndSim(). However, it is still possible
66  for Actions other than Exit to end simulation. Once all
67  primary components have specified
68  primaryComponentOKToEndSim(), the Exit object will trigger and
69  end simulation.
70 
71  This must be called during simulation wireup (i.e during the
72  constructor for the component). By default, the state of the
73  primary component is set to OKToEndSim.
74 
75  If no component registers as a primary component, then the
76  Exit object will not be used for that simulation and
77  simulation termination must be accomplished through some other
78  mechanism (e.g. --stopAt flag, or some other Action object).
79 
80  @sa Component::primaryComponentDoNotEndSim()
81  @sa Component::primaryComponentOKToEndSim()
82  */
83  void registerAsPrimaryComponent();
84 
85  /** Tells the simulation that it should not exit. The component
86  will remain in this state until a call to
87  primaryComponentOKToEndSim().
88 
89  @sa Component::registerAsPrimaryComponent()
90  @sa Component::primaryComponentOKToEndSim()
91  */
92  void primaryComponentDoNotEndSim();
93 
94  /** Tells the simulation that it is now OK to end simulation.
95  Simulation will not end until all primary components have
96  called this function.
97 
98  @sa Component::registerAsPrimaryComponent()
99  @sa Component::primaryComponentDoNotEndSim()
100  */
101  void primaryComponentOKToEndSim();
102 
103 
104 protected:
105  friend class SubComponent;
106  Component() {} // Unused, but previously available
107 
108  Component* getTrueComponent() const final override { return const_cast<Component*>(this); }
109  BaseComponent* getStatisticOwner() const final override { return const_cast<Component*>(this); }
110 
111 
112  // Does the statisticName exist in the ElementInfoStatistic
113  virtual bool doesComponentInfoStatisticExist(const std::string &statisticName) const final override;
114 
115 private:
116 
117  /** Unique ID */
118  ComponentId_t id;
119 
120 };
121 
122 } //namespace SST
123 
124 #endif // SST_CORE_COMPONENT_H
BaseComponent * getStatisticOwner() const final override
Returns self if Component If sub-component, returns self if a "modern" subcomponent otherwise...
Definition: component.h:109
Main component object for the simulation.
Definition: component.h:32
Definition: action.cc:17
Main component object for the simulation.
Definition: baseComponent.h:104
Definition: componentInfo.h:30
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29