SST  15.1.0
StructuralSimulationToolkit
coreTest_StatisticsComponent.h
1 // Copyright 2009-2025 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-2025, 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_CORETEST_STATISTICSCOMPONENT_H
13 #define SST_CORE_CORETEST_STATISTICSCOMPONENT_H
14 
15 #include "sst/core/component.h"
16 #include "sst/core/rng/rng.h"
17 
18 #include <string>
19 
20 using namespace SST;
21 using namespace SST::RNG;
22 using namespace SST::Statistics;
23 
25 
27 {
28 public:
29  // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
30  SST_ELI_REGISTER_COMPONENT(
32  "coreTestElement",
33  "StatisticsComponent.int",
34  SST_ELI_ELEMENT_VERSION(1,0,0),
35  "Statistics test component with ints",
36  COMPONENT_CATEGORY_UNCATEGORIZED
37  )
38 
39  SST_ELI_DOCUMENT_PARAMS(
40  { "seed_w", "The seed to use for the random number generator", "7" },
41  { "seed_z", "The seed to use for the random number generator", "5" },
42  { "seed", "The seed to use for the random number generator.", "11" },
43  { "rng", "The random number generator to use (Marsaglia or Mersenne), default is Mersenne", "Mersenne"},
44  { "count", "The number of random numbers to generate, default is 1000", "1000" },
45  { "dynamic_reg", "The cycle at which to dynamically register a statistic. 0 indicates none", "0"}
46  )
47 
48  SST_ELI_DOCUMENT_STATISTICS(
49  { "stat1_U32", "Test Statistic 1 - Collecting U32 Data", "units", 1},
50  { "stat2_U64", "Test Statistic 2 - Collecting U64 Data", "units", 2},
51  { "stat3_I32", "Test Statistic 3 - Collecting I32 Data", "units", 3},
52  { "stat4_I64", "Test Statistic 4 - Collecting I64 Data", "units", 4},
53  { "stat5_dyn", "Test Statistic 5 - Statistic registered during run loop", "units", 1}
54  )
55 
56  // Optional since there is nothing to document
57  SST_ELI_DOCUMENT_PORTS(
58  { "left", "left port", {""} },
59  { "right", "right port", {""} },
60  )
61 
62  // Optional since there is nothing to document
63  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
64  )
65 
66  SST_ELI_IS_CHECKPOINTABLE()
67 
68  StatisticsComponentInt(ComponentId_t id, Params& params);
69  StatisticsComponentInt(); // For checkpointing only
70  void setup() override {}
71  void finish() override {}
72 
73  void serialize_order(SST::Core::Serialization::serializer& ser) override;
74  ImplementSerializable(StatisticsComponentInt);
75 
76 private:
77  StatisticsComponentInt(const StatisticsComponentInt&) = delete; // do not implement
78  StatisticsComponentInt& operator=(const StatisticsComponentInt&) = delete; // do not implement
79 
80  virtual bool Clock1Tick(SST::Cycle_t);
81 
82  Random* rng;
83  std::string rng_type;
84  int rng_max_count;
85  int rng_count;
86  int dynamic_reg;
87  Output& output;
88 
89  Link* left;
90  Link* right;
91 
92  // Statistics
93  Statistic<uint32_t>* stat1_U32;
94  Statistic<uint64_t>* stat2_U64;
95  Statistic<int32_t>* stat3_I32;
96  Statistic<int64_t>* stat4_I64;
97  Statistic<int64_t>* stat5_dyn;
98 };
99 
101 {
102 public:
103  // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
104  SST_ELI_REGISTER_COMPONENT(
106  "coreTestElement",
107  "StatisticsComponent.float",
108  SST_ELI_ELEMENT_VERSION(1,0,0),
109  "Statistics test component with floats",
110  COMPONENT_CATEGORY_UNCATEGORIZED
111  )
112 
113  SST_ELI_DOCUMENT_PARAMS(
114  { "seed_w", "The seed to use for the random number generator", "7" },
115  { "seed_z", "The seed to use for the random number generator", "5" },
116  { "seed", "The seed to use for the random number generator.", "11" },
117  { "rng", "The random number generator to use (Marsaglia or Mersenne), default is Mersenne", "Mersenne"},
118  { "count", "The number of random numbers to generate, default is 1000", "1000" }
119  )
120 
121  SST_ELI_DOCUMENT_STATISTICS(
122  { "stat1_F32", "Test Statistic 1 - Collecting F32 Data", "units", 1},
123  { "stat2_F64", "Test Statistic 2 - Collecting F64 Data", "units", 2},
124  { "stat3_F64", "Test Statistic 2 - Collecting F64 Data", "units", 9},
125  )
126 
127  // Optional since there is nothing to document
128  SST_ELI_DOCUMENT_PORTS(
129  { "left", "left port", {""} },
130  { "right", "right port", {""} },
131  )
132 
133  // Optional since there is nothing to document
134  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
135  )
136 
137  SST_ELI_IS_CHECKPOINTABLE()
138 
139  StatisticsComponentFloat(ComponentId_t id, Params& params);
140  StatisticsComponentFloat(); // For serialization only
141  void setup() override {}
142  void finish() override {}
143 
144  void serialize_order(SST::Core::Serialization::serializer& ser) override;
145  ImplementSerializable(StatisticsComponentFloat);
146 
147 private:
148  StatisticsComponentFloat(const StatisticsComponentFloat&) = delete; // do not implement
149  void operator=(const StatisticsComponentFloat&) = delete; // do not implement
150 
151  virtual bool Clock1Tick(SST::Cycle_t);
152 
153  Random* rng;
154  std::string rng_type;
155  int rng_max_count;
156  int rng_count;
157  Output& output;
158 
159  Link* left;
160  Link* right;
161 
162  // Statistics
163  Statistic<float>* stat1_F32;
164  Statistic<double>* stat2_F64;
165  Statistic<double>* stat3_F64; // For testing stat sharing
166 };
167 
168 } // namespace SST::CoreTestStatisticsComponent
169 
170 #endif // SST_CORE_CORETEST_STATISTICSCOMPONENT_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:57
Implements the base class for random number generators for the SST core.
Definition: rng.h:29
Definition: constant.h:18
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
void setup() override
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: coreTest_StatisticsComponent.h:70
Main component object for the simulation.
Definition: component.h:30
Definition: action.cc:18
void finish() override
Called after complete phase, but before objects are destroyed.
Definition: coreTest_StatisticsComponent.h:71
void finish() override
Called after complete phase, but before objects are destroyed.
Definition: coreTest_StatisticsComponent.h:142
void setup() override
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: coreTest_StatisticsComponent.h:141
Definition: coreTest_StatisticsComponent.h:24
Parameter store.
Definition: params.h:63
Definition: coreTest_StatisticsComponent.h:100
Definition: coreTest_StatisticsComponent.h:26
Definition: elementinfo.h:44