SST  14.1.0
StructuralSimulationToolkit
coreTest_Checkpoint.h
1 // Copyright 2009-2024 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-2024, 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 
21 namespace SST {
22 namespace CoreTestCheckpoint {
23 
24 // Very simple starting case
25 // Expected to have two components in simulation.
26 // The components ping-pong an event until its count reaches 0
27 
29 {
30 public:
31  coreTestCheckpointEvent() : SST::Event(), counter(1000) {}
32 
33  coreTestCheckpointEvent(uint32_t c) : SST::Event(), counter(c) {}
34 
36 
37  bool decCount()
38  {
39  if ( counter != 0 ) counter--;
40  return counter == 0;
41  }
42 
43  uint32_t getCount() { return counter; }
44 
45 private:
46  uint32_t counter;
47 
48  void serialize_order(SST::Core::Serialization::serializer& ser) override
49  {
50  Event::serialize_order(ser);
51  SST_SER(counter)
52  }
53 
55 };
56 
57 
59 {
60 public:
61  SST_ELI_REGISTER_COMPONENT(
63  "coreTestElement",
64  "coreTestCheckpoint",
65  SST_ELI_ELEMENT_VERSION(1,0,0),
66  "CoreTest Test Checkpoint",
67  COMPONENT_CATEGORY_UNCATEGORIZED
68  )
69 
70  SST_ELI_DOCUMENT_PARAMS(
71  { "starter", "Whether this component initiates the ping-pong", "T"},
72  { "count", "Number of times to bounce the message back and forth", "1000" },
73  { "test_string", "A test string", ""},
74  { "clock_frequency", "Frequency for clock", "100kHz"},
75  { "clock_duty_cycle", "Number of cycles to keep clock on and off", "10"},
76  // Testing output options
77  { "output_prefix", "Prefix for output", ""},
78  { "output_verbose", "Verbosity for output", "0"},
79  { "output_frequency", "How often, in terms of clock cycles, to generate output", "1"},
80  // Testing RNG & distributions
81  { "rng_seed_w", "The first seed for marsaglia", "7" },
82  { "rng_seed_z", "The second seed for marsaglia", "5" },
83  { "rng_seed", "The seed for mersenne and xorshift", "11" },
84  { "dist_const", "Constant for ConstantDistribution", "1.5" },
85  { "dist_discrete_probs", "Probabilities in discrete distribution", "[1.0]"},
86  { "dist_exp_lambda", "Lambda for exponentional distribution", "1.0"},
87  { "dist_gauss_mean", "Mean for Gaussian distribution", "1.0"},
88  { "dist_gauss_stddev", "Standard deviation for Gaussian distribution", "0.2"},
89  { "dist_poisson_lambda", "Lambda for Poisson distribution", "1.0"},
90  { "dist_uni_bins", "Number of proability bins for the uniform distribution", "4"}
91  )
92 
93  SST_ELI_DOCUMENT_PORTS(
94  {"port_left", "Link to another coreTestCheckpoint", { "coreTestElement.coreTestCheckpointEvent", "" } },
95  {"port_right", "Link to another coreTestCheckpoint", { "coreTestElement.coreTestCheckpointEvent", "" } }
96  )
97 
98  SST_ELI_DOCUMENT_STATISTICS(
99  {"eventcount", "Total number of events received", "events", 1},
100  {"rngvals", "Numbers from RNG", "number", 2},
101  {"distvals", "Numbers from distribution", "number", 3}
102  )
103 
104  coreTestCheckpoint(ComponentId_t id, SST::Params& params);
105  virtual ~coreTestCheckpoint();
106 
107  void init(unsigned phase) override;
108 
109  void setup() override;
110 
111  void complete(unsigned phase) override;
112 
113  void finish() override;
114 
115  void printStatus(Output& out) override;
116 
117  void emergencyShutdown() override;
118 
119  // Serialization functions and macro
120  coreTestCheckpoint() : Component() {} // For serialization only
121  void serialize_order(SST::Core::Serialization::serializer& ser) override;
122  ImplementSerializable(SST::CoreTestCheckpoint::coreTestCheckpoint)
123 
124 private:
125  void handleEvent(SST::Event* ev);
126  bool handleClock(Cycle_t cycle);
127  void restartClock(SST::Event* ev);
128 
129  SST::Link* link_left;
130  SST::Link* link_right;
131  SST::Link* self_link;
132  TimeConverter* clock_tc;
133  Clock::HandlerBase* clock_handler;
134  int duty_cycle; // Used to count clock on and off cycles
135  int duty_cycle_count; // Used to count clock on and off cycles
136  uint32_t counter; // Unused after setup
137  std::string test_string; // Test that string got serialized
138  Output* output;
139  int output_frequency;
140 
141  RNG::Random* mersenne;
142  RNG::Random* marsaglia;
143  RNG::Random* xorshift;
144  RNG::RandomDistribution* dist_const;
145  RNG::RandomDistribution* dist_discrete;
146  RNG::RandomDistribution* dist_expon;
147  RNG::RandomDistribution* dist_gauss;
148  RNG::RandomDistribution* dist_poisson;
149  RNG::RandomDistribution* dist_uniform;
150 
151  Statistic<uint32_t>* stat_eventcount;
152  Statistic<uint32_t>* stat_rng;
153  Statistic<double>* stat_dist;
154 };
155 
156 } // namespace CoreTestCheckpoint
157 } // namespace SST
158 
159 #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:53
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:43
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:210
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: action.cc:18
Definition: coreTest_Checkpoint.h:28
Definition: coreTest_Checkpoint.h:58
void setup() override
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: coreTest_Checkpoint.cc:108
Parameter store.
Definition: params.h:55
void finish() override
Called after complete phase, but before objects are destroyed.
Definition: coreTest_Checkpoint.cc:122
Base class of statistical distributions in SST.
Definition: distrib.h:24
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:34
void emergencyShutdown() override
Called when SIGINT or SIGTERM has been seen.
Definition: coreTest_Checkpoint.cc:201