SST 15.0
Structural Simulation Toolkit
exit.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_CORE_EXIT_H
13#define SST_CORE_CORE_EXIT_H
14
15#include "sst/core/action.h"
16#include "sst/core/sst_types.h"
17#include "sst/core/threadsafe.h"
18
19#include <cinttypes>
20#include <string>
21#include <unordered_set>
22
23namespace SST {
24
25#define _EXIT_DBG(fmt, args...) __DBG(DBG_EXIT, Exit, fmt, ##args)
26
27class Simulation;
28class TimeConverter;
29
30/**
31 * Exit Event Action
32 *
33 * Causes the simulation to halt
34 */
35class Exit : public Action
36{
37public:
38 /**
39 * Create a new ExitEvent
40 * @param sim Simulation object
41 * @param single_rank True if there are no parallel ranks
42 *
43 * Exit needs to register a handler during constructor time, which
44 * requires a simulation object. But the simulation class creates
45 * an Exit object during it's construction, meaning that
46 * Simulation::getSimulation() won't work yet. So Exit is the one
47 * exception to the "constructors shouldn't take simulation
48 * pointers" rule. However, it still needs to follow the "classes
49 * shouldn't contain pointers back to Simulation" rule.
50 */
51 Exit(int num_threads, bool single_rank);
52 ~Exit();
53
54 /** Increment Reference Count for a given Component ID */
55 bool refInc(ComponentId_t, uint32_t thread);
56 /** Decrement Reference Count for a given Component ID */
57 bool refDec(ComponentId_t, uint32_t thread);
58
59 unsigned int getRefCount();
60
61 /** Gets the end time of the simulation
62 * @return Time when simulation ends
63 */
64 SimTime_t getEndTime() { return end_time; }
65
66 /** Stores the time the simulation has ended
67 * @param time Current simulation time
68 * @return void
69 */
70 void setEndTime(SimTime_t time) { end_time = time; }
71
72 /** Computes the end time of the simulation
73 * @return End time of the simulation
74 */
75 SimTime_t computeEndTime();
76 void execute() override;
77 void check();
78
79 /**
80 * @param header String to preface the exit action log
81 * @param out SST Output logger object
82 * @return void
83 */
84 void print(const std::string& header, Output& out) const override
85 {
86 out.output("%s Exit Action to be delivered at %" PRIu64 " with priority %d\n", header.c_str(),
88 }
89
90
91 unsigned int getGlobalCount() { return global_count; }
92
93 /**
94 *
95 * TODO to enable different partitioning on restart, will need to associate m_thread_counts and
96 * m_idSet back to components so that a new Exit event can be generated on restart
97 */
99 ImplementSerializable(SST::Exit)
100
101private:
102 Exit() = default; // for serialization only
103 Exit(const Exit&) = delete; // Don't implement
104 Exit& operator=(const Exit&) = delete; // Don't implement
105
106 // bool handler( Event* );
107
108 // EventHandler< Exit, bool, Event* >* m_functor;
109 int num_threads;
110 unsigned int m_refCount;
111 unsigned int* m_thread_counts;
112 unsigned int global_count;
113 std::unordered_set<ComponentId_t> m_idSet;
114 SimTime_t end_time;
115
116 Core::ThreadSafe::Spinlock slock;
117
118 bool single_rank;
119};
120
121} // namespace SST
122
123#endif // SST_CORE_EXIT_H
SimTime_t getDeliveryTime() const
Return the time at which this Activity will be delivered.
Definition activity.h:148
int getPriority() const
Return the Priority of this Activity.
Definition activity.h:151
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45
Exit Event Action.
Definition exit.h:36
Exit(int num_threads, bool single_rank)
Create a new ExitEvent.
Definition exit.cc:25
void print(const std::string &header, Output &out) const override
Definition exit.h:84
bool refDec(ComponentId_t, uint32_t thread)
Decrement Reference Count for a given Component ID.
Definition exit.cc:81
SimTime_t computeEndTime()
Computes the end time of the simulation.
Definition exit.cc:137
void execute() override
Function which will be called when the time for this Activity comes to pass.
Definition exit.cc:127
bool refInc(ComponentId_t, uint32_t thread)
Increment Reference Count for a given Component ID.
Definition exit.cc:46
void serialize_order(SST::Core::Serialization::serializer &ser) override
TODO to enable different partitioning on restart, will need to associate m_thread_counts and m_idSet ...
Definition exit.cc:188
void setEndTime(SimTime_t time)
Stores the time the simulation has ended.
Definition exit.h:70
SimTime_t getEndTime()
Gets the end time of the simulation.
Definition exit.h:64
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition output.h:54
void output(uint32_t line, const char *file, const char *func, const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition output.h:185
A class to convert between a component's view of time and the core's view of time.
Definition timeConverter.h:28