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