SST  15.1.0
StructuralSimulationToolkit
coreTest_Checkpoint.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_CHECKPOINT_H
13 #define SST_CORE_CORETEST_CHECKPOINT_H
14 
15 #include "sst/core/component.h"
16 #include "sst/core/event.h"
17 #include "sst/core/link.h"
18 #include "sst/core/rng/distrib.h"
19 #include "sst/core/rng/rng.h"
20 #include "sst/core/shared/sharedArray.h"
21 #include "sst/core/shared/sharedMap.h"
22 #include "sst/core/shared/sharedSet.h"
23 
24 #include <cstdint>
25 #include <string>
26 
27 namespace SST::CoreTestCheckpoint {
28 
29 // Very simple starting case
30 // Expected to have two components in simulation.
31 // The components ping-pong an event until its count reaches 0
32 
34 {
35 public:
37  SST::Event(),
38  counter(1000)
39  {}
40 
41  explicit coreTestCheckpointEvent(uint32_t c) :
42  SST::Event(),
43  counter(c)
44  {}
45 
47 
48  bool decCount()
49  {
50  if ( counter != 0 ) counter--;
51  return counter == 0;
52  }
53 
54  uint32_t getCount() { return counter; }
55 
56 private:
57  uint32_t counter;
58 
59  void serialize_order(SST::Core::Serialization::serializer& ser) override
60  {
61  Event::serialize_order(ser);
62  SST_SER(counter);
63  }
64 
66 };
67 
68 
70 {
71 public:
72  SST_ELI_REGISTER_COMPONENT(
74  "coreTestElement",
75  "coreTestCheckpoint",
76  SST_ELI_ELEMENT_VERSION(1,0,0),
77  "CoreTest Test Checkpoint",
78  COMPONENT_CATEGORY_UNCATEGORIZED
79  )
80 
81  SST_ELI_DOCUMENT_PARAMS(
82  { "starter", "Whether this component initiates the ping-pong", "T"},
83  { "count", "Number of times to bounce the message back and forth", "1000" },
84  { "test_string", "A test string", ""},
85  { "clock_frequency", "Frequency for clock", "100kHz"},
86  { "clock_duty_cycle", "Number of cycles to keep clock on and off", "10"},
87  // Testing output options
88  { "output_prefix", "Prefix for output", ""},
89  { "output_verbose", "Verbosity for output", "0"},
90  { "output_frequency", "How often, in terms of clock cycles, to generate output", "1"},
91  // Testing RNG & distributions
92  { "rng_seed_w", "The first seed for marsaglia", "7" },
93  { "rng_seed_z", "The second seed for marsaglia", "5" },
94  { "rng_seed", "The seed for mersenne and xorshift", "11" },
95  { "dist_const", "Constant for ConstantDistribution", "1.5" },
96  { "dist_discrete_probs", "Probabilities in discrete distribution", "[1.0]"},
97  { "dist_exp_lambda", "Lambda for exponentional distribution", "1.0"},
98  { "dist_gauss_mean", "Mean for Gaussian distribution", "1.0"},
99  { "dist_gauss_stddev", "Standard deviation for Gaussian distribution", "0.2"},
100  { "dist_poisson_lambda", "Lambda for Poisson distribution", "1.0"},
101  { "dist_uni_bins", "Number of proability bins for the uniform distribution", "4"}
102  )
103 
104  SST_ELI_DOCUMENT_PORTS(
105  {"port_left", "Link to another coreTestCheckpoint", { "coreTestElement.coreTestCheckpointEvent", "" } },
106  {"port_right", "Link to another coreTestCheckpoint", { "coreTestElement.coreTestCheckpointEvent", "" } }
107  )
108 
109  SST_ELI_DOCUMENT_STATISTICS(
110  {"eventcount", "Total number of events received", "events", 1},
111  {"rngvals", "Numbers from RNG", "number", 2},
112  {"distvals", "Numbers from distribution", "number", 3},
113  {"nullstat", "Test that non-enabled stats are checkpointed correctly", "number", 5}
114  )
115 
116  SST_ELI_IS_CHECKPOINTABLE()
117 
118  coreTestCheckpoint(ComponentId_t id, SST::Params& params);
120 
121  void init(unsigned phase) override;
122 
123  void setup() override;
124 
125  void complete(unsigned phase) override;
126 
127  void finish() override;
128 
129  void printStatus(Output& out) override;
130 
131  void emergencyShutdown() override;
132 
133  // Serialization functions and macro
135  Component()
136  {} // For serialization only
137  void serialize_order(SST::Core::Serialization::serializer& ser) override;
138  ImplementSerializable(SST::CoreTestCheckpoint::coreTestCheckpoint)
139 
140 private:
141  void handleEvent(SST::Event* ev);
142  bool handleClock(Cycle_t cycle);
143  void restartClock(SST::Event* ev);
144 
145  SST::Link* link_left;
146  SST::Link* link_right;
147  SST::Link* self_link;
148  TimeConverter clock_tc;
149  Clock::HandlerBase* clock_handler;
150  int duty_cycle; // Used to count clock on and off cycles
151  int duty_cycle_count; // Used to count clock on and off cycles
152  uint32_t counter; // Unused after setup
153  std::string test_string; // Test that string got serialized
154  Output* output;
155  int output_frequency;
156 
157  RNG::Random* mersenne = nullptr;
158  RNG::Random* marsaglia = nullptr;
159  RNG::Random* xorshift = nullptr;
160  RNG::RandomDistribution* dist_const = nullptr;
161  RNG::RandomDistribution* dist_discrete = nullptr;
162  RNG::RandomDistribution* dist_expon = nullptr;
163  RNG::RandomDistribution* dist_gauss = nullptr;
164  RNG::RandomDistribution* dist_poisson = nullptr;
165  RNG::RandomDistribution* dist_uniform = nullptr;
166  Statistic<uint32_t>* stat_eventcount = nullptr;
167  Statistic<uint32_t>* stat_rng = nullptr;
168  Statistic<double>* stat_dist = nullptr;
169  Statistic<uint32_t>* stat_null = nullptr;
170 
171 
172  Shared::SharedArray<int> shared_array;
173  Shared::SharedArray<int> shared_array_uninit;
174  Shared::SharedSet<int> shared_set;
175  Shared::SharedSet<int> shared_set_uninit;
176  Shared::SharedMap<int, int> shared_map;
177  Shared::SharedMap<int, int> shared_map_uninit;
178 };
179 
180 } // namespace SST::CoreTestCheckpoint
181 
182 #endif // SST_CORE_CORETEST_CHECKPOINT_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
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
Base template for handlers which take a class defined argument.
Definition: ssthandler.h:109
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:27
Main component object for the simulation.
Definition: component.h:30
Definition: coreTest_Checkpoint.h:33
Definition: coreTest_Checkpoint.h:69
void setup() override
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: coreTest_Checkpoint.cc:144
Definition: coreTest_Checkpoint.h:27
Parameter store.
Definition: params.h:63
void finish() override
Called after complete phase, but before objects are destroyed.
Definition: coreTest_Checkpoint.cc:161
Base class of statistical distributions in SST.
Definition: distrib.h:23
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:40
void emergencyShutdown() override
Called when SIGINT or SIGTERM has been seen.
Definition: coreTest_Checkpoint.cc:270