Skip to content

Commit

Permalink
Merge Pull Request sstsimulator#2401 from bliu1013/sst-elements/seria…
Browse files Browse the repository at this point in the history
…lization

Automatically Merged using SST Pull Request AutoTester
PR Title: b'Update simpleElementExample for checkpointing'
PR Author: bliu1013
  • Loading branch information
sst-autotester authored Sep 30, 2024
2 parents aabc90a + 6f707e3 commit 5ae55c8
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 19 deletions.
30 changes: 25 additions & 5 deletions src/sst/elements/simpleElementExample/basicClocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ basicClocks::basicClocks(ComponentId_t id, Params& params) : Component(id) {

// Main clock (clock 0)
// Clock can be registered with a string or UnitAlgebra, here we use the string
registerClock(clock0Freq, new Clock::Handler<basicClocks>(this, &basicClocks::mainTick));
registerClock(clock0Freq, new Clock::Handler2<basicClocks, &basicClocks::mainTick>(this));

out->output("Registering clock0 at %s\n", clock0Freq.c_str());

Expand All @@ -74,13 +74,13 @@ basicClocks::basicClocks(ComponentId_t id, Params& params) : Component(id) {
// pass unique IDs in to it to differentiate
// We also save the registerClock return value (a TimeConverter) so that we can use it later (see mainTick)
clock1converter = registerClock(clock1Freq_ua,
new Clock::Handler<basicClocks, uint32_t>(this, &basicClocks::otherTick, 1));
new Clock::Handler2<basicClocks, &basicClocks::otherTick, uint32_t>(this, 1));

out->output("Registering clock1 at %s (that's %s or %s if we convert the UnitAlgebra to string)\n",
clock1Freq.c_str(), clock1Freq_ua.toString().c_str(), clock1Freq_ua.toStringBestSI().c_str());

// Last clock, as with clock1, the handler has an extra parameter and we save the registerClock return parameter
Clock::HandlerBase* handler = new Clock::Handler<basicClocks, uint32_t>(this, &basicClocks::otherTick, 2);
Clock::HandlerBase* handler = new Clock::Handler2<basicClocks, &basicClocks::otherTick, uint32_t>(this, 2);
clock2converter = registerClock(clock2Freq, handler);

out->output("Registering clock2 at %s\n", clock2Freq.c_str());
Expand All @@ -92,7 +92,6 @@ basicClocks::basicClocks(ComponentId_t id, Params& params) : Component(id) {
printInterval = 1;
}


/*
* Destructor, clean up our output
*/
Expand All @@ -101,7 +100,6 @@ basicClocks::~basicClocks()
delete out;
}


/*
* Main clock (clock0) handler
* Every 'printInterval' cycles, this handler prints the time & cycle count for all clocks
Expand Down Expand Up @@ -148,3 +146,25 @@ bool basicClocks::otherTick( Cycle_t cycles, uint32_t id )
return false; // Keep calling this handler if it hasn't been 10 cycles yet
}
}

/*
* Default constructor
*/
basicClocks::basicClocks() : Component() {}

/*
* Serialization function
*/
void basicClocks::serialize_order(SST::Core::Serialization::serializer& ser) {
Component::serialize_order(ser);

SST_SER(clock1converter);
SST_SER(clock2converter);
SST_SER(clock2Handler);
SST_SER(cycleCount);
SST_SER(clock0Freq);
SST_SER(clock1Freq);
SST_SER(clock2Freq);
SST_SER(out);
SST_SER(printInterval);
}
6 changes: 6 additions & 0 deletions src/sst/elements/simpleElementExample/basicClocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*/

#include <sst/core/component.h>
#include <sst/core/timeConverter.h>

namespace SST {
namespace simpleElementExample {
Expand Down Expand Up @@ -92,6 +93,11 @@ class basicClocks : public SST::Component
// Destructor
~basicClocks();

// Serialization
basicClocks();
void serialize_order(SST::Core::Serialization::serializer& ser) override;
ImplementSerializable(SST::simpleElementExample::basicClocks)

private:

// Clock handler for clock0
Expand Down
30 changes: 27 additions & 3 deletions src/sst/elements/simpleElementExample/basicLinks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ basicLinks::basicLinks(ComponentId_t id, Params& params) : Component(id) {
primaryComponentDoNotEndSim();

//set our clock. The simulator will call 'clockTic' at a 1GHz frequency
registerClock("1GHz", new Clock::Handler<basicLinks>(this, &basicLinks::clockTic));
registerClock("1GHz", new Clock::Handler2<basicLinks, &basicLinks::clockTic>(this));

// This simulation will end when we have sent 'eventsToSend' events and received a 'LAST' event on every link
lastEventReceived = 0;
Expand All @@ -77,7 +77,7 @@ basicLinks::basicLinks(ComponentId_t id, Params& params) : Component(id) {
*/

// 1. These links share
linkHandler = configureLink("port_handler", new Event::Handler<basicLinks>(this, &basicLinks::handleEvent));
linkHandler = configureLink("port_handler", new Event::Handler2<basicLinks, &basicLinks::handleEvent>(this));
sst_assert(linkHandler, CALL_INFO, -1, "Error in %s: Link configuration for 'port_handler' failed\n", getName().c_str());


Expand All @@ -88,7 +88,7 @@ basicLinks::basicLinks(ComponentId_t id, Params& params) : Component(id) {
std::string linkname = linkprefix + "0";
int portnum = 0;
while (isPortConnected(linkname)) {
SST::Link* link = configureLink(linkname, new Event::Handler<basicLinks, int>(this, &basicLinks::handleEventWithID, portnum));
SST::Link* link = configureLink(linkname, new Event::Handler2<basicLinks, &basicLinks::handleEventWithID, int>(this, portnum));

if (!link)
out->fatal(CALL_INFO, -1, "Error in %s: unable to configure link %s\n", getName().c_str(), linkname.c_str());
Expand Down Expand Up @@ -278,3 +278,27 @@ bool basicLinks::clockTic( Cycle_t cycleCount)
// Return false to indicate the clock handler should not be disabled
return false;
}

/*
* Default constructor
*/
basicLinks::basicLinks() : Component() {}

/*
* Serialization function
*/
void basicLinks::serialize_order(SST::Core::Serialization::serializer& ser) {
Component::serialize_order(ser);

SST_SER(eventsToSend);
SST_SER(eventSize);
SST_SER(lastEventReceived);
SST_SER(rng);
SST_SER(out);
SST_SER(linkHandler);
SST_SER(linkPolled);
SST_SER(linkVector);
SST_SER(stat_portHandler);
SST_SER(stat_portPolled);
SST_SER(stat_portVector);
}
5 changes: 5 additions & 0 deletions src/sst/elements/simpleElementExample/basicLinks.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class basicLinks : public SST::Component
// Destructor
~basicLinks();

// Serialization
basicLinks();
void serialize_order(SST::Core::Serialization::serializer& ser) override;
ImplementSerializable(SST::simpleElementExample::basicLinks)

private:
// Event handler, called when an event is received on the handler link
void handleEvent(SST::Event *ev);
Expand Down
15 changes: 14 additions & 1 deletion src/sst/elements/simpleElementExample/basicParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ basicParams::basicParams(ComponentId_t id, Params& params) : Component(id) {
primaryComponentDoNotEndSim();

// Register a clock
registerClock("1MHz", new Clock::Handler<basicParams>(this, &basicParams::tick));
registerClock("1MHz", new Clock::Handler2<basicParams, &basicParams::tick>(this));

}

Expand Down Expand Up @@ -119,3 +119,16 @@ bool basicParams::tick( Cycle_t cycles)
return false;
}

/*
* Default constructor
*/
basicParams::basicParams() : Component() {}

/*
* Serialization function
*/
void basicParams::serialize_order(SST::Core::Serialization::serializer& ser) {
Component::serialize_order(ser);

SST_SER(out);
}
5 changes: 5 additions & 0 deletions src/sst/elements/simpleElementExample/basicParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ class basicParams : public SST::Component
int value;
};

// Serialization
basicParams();
void serialize_order(SST::Core::Serialization::serializer& ser) override;
ImplementSerializable(SST::simpleElementExample::basicParams)

private:

// Clock handler
Expand Down
47 changes: 45 additions & 2 deletions src/sst/elements/simpleElementExample/basicSimLifeCycle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ basicSimLifeCycle::basicSimLifeCycle(ComponentId_t id, Params& params) : Compone
verbose = params.find<bool>("verbose", false);

// configure our links with a callback function that will be called whenever an event arrives
leftLink = configureLink("left", new Event::Handler<basicSimLifeCycle>(this, &basicSimLifeCycle::handleEvent));
rightLink = configureLink("right", new Event::Handler<basicSimLifeCycle>(this, &basicSimLifeCycle::handleEvent));
leftLink = configureLink("left", new Event::Handler2<basicSimLifeCycle, &basicSimLifeCycle::handleEvent>(this));
rightLink = configureLink("right", new Event::Handler2<basicSimLifeCycle, &basicSimLifeCycle::handleEvent>(this));

// Make sure we successfully configured the links
// Failure usually means the user didn't connect the port in the input file
Expand Down Expand Up @@ -295,3 +295,46 @@ void basicSimLifeCycle::printStatus(Output& sim_out) {
sim_out.output("%s reporting. I have sent %u messages, received %u, and forwarded %u.\n",
getName().c_str(), eventsSent, eventsReceived, eventsForwarded);
}

/*
* Default constructor
*/
basicSimLifeCycle::basicSimLifeCycle() : Component() {}

/*
* Serialization function
*/
void basicSimLifeCycle::serialize_order(SST::Core::Serialization::serializer& ser) {
Component::serialize_order(ser);

SST_SER(eventsToSend);
SST_SER(verbose);

SST_SER(eventsReceived);
SST_SER(eventsForwarded);
SST_SER(eventsSent);
SST_SER(neighbors);

SST_SER(leftMsg);
SST_SER(rightMsg);

SST_SER(out);

SST_SER(leftLink);
SST_SER(rightLink);

// Handle 'iter' neighbor iterator
switch ( ser.mode() ) {
case SST::Core::Serialization::serializer::SIZER:
case SST::Core::Serialization::serializer::PACK:
case SST::Core::Serialization::serializer::UNPACK:
{
//Reinitialize iter from neighbors
int index = eventsSent % neighbors.size();
iter = neighbors.begin();
std::advance(iter, index);

break;
}
}
}
4 changes: 4 additions & 0 deletions src/sst/elements/simpleElementExample/basicSimLifeCycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class basicSimLifeCycle : public SST::Component
// Event handler, called when an event is received
void handleEvent(SST::Event *ev);

// Serialization
basicSimLifeCycle();
void serialize_order(SST::Core::Serialization::serializer& ser) override;
ImplementSerializable(SST::simpleElementExample::basicSimLifeCycle)

// SSTSnippet::component-header::start
private:
Expand Down
29 changes: 28 additions & 1 deletion src/sst/elements/simpleElementExample/basicStatistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ basicStatistics::basicStatistics(ComponentId_t id, Params& params) : Component(i
primaryComponentDoNotEndSim();

//set our clock. The simulator will call 'clockTic' at a 4GHz frequency
registerClock("4 GHz", new Clock::Handler<basicStatistics>(this, &basicStatistics::clockTic));
registerClock("4 GHz", new Clock::Handler2<basicStatistics, &basicStatistics::clockTic>(this));

// Initialize the random number generators
rng0 = new SST::RNG::MarsagliaRNG(mars_z, mars_w);
Expand Down Expand Up @@ -126,3 +126,30 @@ bool basicStatistics::clockTic( Cycle_t cycleCount)
// Return false to indicate the clock handler should not be disabled
return false;
}

/*
* Default constructor
*/
basicStatistics::basicStatistics() : Component() {}

/*
* Serialization function
*/
void basicStatistics::serialize_order(SST::Core::Serialization::serializer& ser) {
Component::serialize_order(ser);

SST_SER(runcycles);

SST_SER(stat_U64);
SST_SER(stat_I32);
SST_SER(stat_I64);

SST_SER(stat_U32);
SST_SER(stat_U32_duplicate);
SST_SER(stat_U32_single);

SST_SER(stat_subid);

SST_SER(rng0);
SST_SER(rng1);
}
5 changes: 5 additions & 0 deletions src/sst/elements/simpleElementExample/basicStatistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class basicStatistics : public SST::Component
// Destructor
~basicStatistics();

// Serialization
basicStatistics();
void serialize_order(SST::Core::Serialization::serializer& ser) override;
ImplementSerializable(SST::simpleElementExample::basicStatistics)

private:
// Clock handler, called on each clock cycle
virtual bool clockTic(SST::Cycle_t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ basicSubComponent_Component::basicSubComponent_Component(ComponentId_t id, Param
"Error: The parameter 'value' is a required parameter and was not found in the input configuration\n");

// Configure our links to call our event handler when an event arrives
leftLink = configureLink("left", new Event::Handler<basicSubComponent_Component>(this, &basicSubComponent_Component::handleEvent));
rightLink = configureLink("right", new Event::Handler<basicSubComponent_Component>(this, &basicSubComponent_Component::handleEvent));
leftLink = configureLink("left", new Event::Handler2<basicSubComponent_Component, &basicSubComponent_Component::handleEvent>(this));
rightLink = configureLink("right", new Event::Handler2<basicSubComponent_Component, &basicSubComponent_Component::handleEvent>(this));

// Check that the links were configured correctly
sst_assert(leftLink, CALL_INFO, -1,
Expand Down Expand Up @@ -147,3 +147,23 @@ void basicSubComponent_Component::handleEvent(SST::Event* ev)
leftLink->send(event);
}
}

/*
* Default constructor
*/
basicSubComponent_Component::basicSubComponent_Component() : Component() {}

/*
* Serialization function
*/
void basicSubComponent_Component::serialize_order(SST::Core::Serialization::serializer& ser) {
Component::serialize_order(ser);

SST_SER(out);
SST_SER(value);

SST_SER(leftLink);
SST_SER(rightLink);

SST_SER(computeUnit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ class basicSubComponent_Component : public SST::Component
// Event handler, called when an event is received on either link
void handleEvent(SST::Event* ev);

// Serialization
basicSubComponent_Component();
void serialize_order(SST::Core::Serialization::serializer& ser) override;
ImplementSerializable(SST::simpleElementExample::basicSubComponent_Component)

private:

// SST Output object, for printing, error messages, etc.
Expand Down
Loading

0 comments on commit 5ae55c8

Please sign in to comment.