SST 16.0.0
Structural Simulation Toolkit
exit.h
1// Copyright 2009-2026 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-2026, 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 <cstdint>
21#include <string>
22#include <unordered_set>
23
24namespace SST {
25
26class Simulation;
27
28/**
29 Exit Action
30
31 Tracks the number of components that have requested DoNotEndSim.
32 Once that count reaches 0, the Exit object will end the simulation.
33 */
34class Exit : public Action
35{
36public:
37 /**
38 Create a new ExitEvent
39
40 @param num_threads number of threads on the rank
41 @param single_rank True if there are no other ranks
42 */
43 Exit(int num_threads, bool single_rank);
44
45 ~Exit();
46
47 /**
48 Increment reference count on a given thread
49
50 @param thread number of Component making call
51 */
52 void refInc(uint32_t thread);
53
54 /**
55 Decrement reference count on a given thread
56
57 @param thread number of Component making call
58 */
59 void refDec(uint32_t thread);
60
61 /**
62 Get the current local reference count
63
64 @return current local reference count
65 */
66 unsigned int getRefCount();
67
68 /**
69 Gets the end time of the simulation
70
71 @return Time when simulation ends
72 */
73 SimTime_t getEndTime() { return end_time_; }
74
75 /**
76 Stores the time the simulation has ended
77
78 @param time Current simulation time
79 */
80 void setEndTime(SimTime_t time) { end_time_ = time; }
81
82 /**
83 Computes the end time of the simulation. This call
84 synchronizes across ranks.
85
86 @return End time of the simulation
87 */
88 SimTime_t computeEndTime();
89
90 /**
91 Function called when Exit fires in the TimeVortex
92 */
93 void execute() override;
94
95 /**
96 Function called by SyncManager to check to see if it's time to
97 exit. This call synchronizes across ranks.
98 */
99 void check();
100
101 /**
102 Creates a string representation of the Exit object
103
104 @return string representation of Exit object
105 */
106 std::string toString() const override;
107
108 /**
109 Get the global ref_count. This is only valid after check() is
110 called
111
112 @return global ref_count
113 */
114 unsigned int getGlobalCount() { return global_count_; }
115
116 // Exit should not be serialized. It will be created new on
117 // restart and Components store there primary component state and
118 // reregister with Exit on restart.
119 NotSerializable(SST::Exit)
120
121private:
122 Exit() = delete;
123 Exit(const Exit&) = delete;
124 Exit& operator=(const Exit&) = delete;
125
126 int num_threads_ = 0;
127 unsigned int ref_count_ = 0;
128 unsigned int* thread_counts_ = nullptr;
129 unsigned int global_count_ = 0;
130 SimTime_t end_time_ = 0;
131 bool single_rank_ = true;
132
134};
135
136} // namespace SST
137
138#endif // SST_CORE_EXIT_H
Definition threadsafe.h:138
Exit Action.
Definition exit.h:35
void check()
Function called by SyncManager to check to see if it's time to exit.
Definition exit.cc:112
Exit(int num_threads, bool single_rank)
Create a new ExitEvent.
Definition exit.cc:28
void refInc(uint32_t thread)
Increment reference count on a given thread.
Definition exit.cc:46
void refDec(uint32_t thread)
Decrement reference count on a given thread.
Definition exit.cc:54
std::string toString() const override
Creates a string representation of the Exit object.
Definition exit.cc:135
SimTime_t computeEndTime()
Computes the end time of the simulation.
Definition exit.cc:95
unsigned int getRefCount()
Get the current local reference count.
Definition exit.cc:82
unsigned int getGlobalCount()
Get the global ref_count.
Definition exit.h:114
void execute() override
Function called when Exit fires in the TimeVortex.
Definition exit.cc:88
void setEndTime(SimTime_t time)
Stores the time the simulation has ended.
Definition exit.h:80
SimTime_t getEndTime()
Gets the end time of the simulation.
Definition exit.h:73
Main control class for a SST Simulation.
Definition simulation.h:121