SST  12.0.1
StructuralSimulationToolkit
exit.h
1 // Copyright 2009-2022 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-2022, 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 
18 #include <cinttypes>
19 #include <unordered_set>
20 
21 namespace SST {
22 
23 #define _EXIT_DBG(fmt, args...) __DBG(DBG_EXIT, Exit, fmt, ##args)
24 
25 class Simulation;
26 class TimeConverter;
27 
28 /**
29  * Exit Event Action
30  *
31  * Causes the simulation to halt
32  */
33 class Exit : public Action
34 {
35 public:
36  /**
37  * Create a new ExitEvent
38  * @param sim - Simulation Object
39  * @param single_rank - True if there are no parallel ranks
40  *
41  * Exit needs to register a handler during constructor time, which
42  * requires a simulation object. But the simulation class creates
43  * an Exit object during it's construction, meaning that
44  * Simulation::getSimulation() won't work yet. So Exit is the one
45  * exception to the "constructors shouldn't take simulation
46  * pointers" rule. However, it still needs to follow the "classes
47  * shouldn't contain pointers back to Simulation" rule.
48  */
49  Exit(int num_threads, bool single_rank);
50  ~Exit();
51 
52  /** Increment Reference Count for a given Component ID */
53  bool refInc(ComponentId_t, uint32_t thread);
54  /** Decrement Reference Count for a given Component ID */
55  bool refDec(ComponentId_t, uint32_t thread);
56 
57  unsigned int getRefCount();
58  SimTime_t getEndTime() { return end_time; }
59  void setEndTime(SimTime_t time) { end_time = time; }
60 
61  SimTime_t computeEndTime();
62  void execute(void) override;
63  void check();
64 
65  void print(const std::string& header, Output& out) const override
66  {
67  out.output(
68  "%s Exit Action to be delivered at %" PRIu64 " with priority %d\n", header.c_str(), getDeliveryTime(),
69  getPriority());
70  }
71 
72  unsigned int getGlobalCount() { return global_count; }
73 
74 private:
75  Exit() {} // for serialization only
76  Exit(const Exit&); // Don't implement
77  void operator=(Exit const&); // Don't implement
78 
79  // bool handler( Event* );
80 
81  // EventHandler< Exit, bool, Event* >* m_functor;
82  int num_threads;
83  unsigned int m_refCount;
84  unsigned int* m_thread_counts;
85  unsigned int global_count;
86  std::unordered_set<ComponentId_t> m_idSet;
87  SimTime_t end_time;
88 
89  Core::ThreadSafe::Spinlock slock;
90 
91  bool single_rank;
92 };
93 
94 } // namespace SST
95 
96 #endif // SST_CORE_EXIT_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:51
An Action is a schedulable Activity which is not an Event.
Definition: action.h:26
bool refInc(ComponentId_t, uint32_t thread)
Increment Reference Count for a given Component ID.
Definition: exit.cc:52
bool refDec(ComponentId_t, uint32_t thread)
Decrement Reference Count for a given Component ID.
Definition: exit.cc:87
void print(const std::string &header, Output &out) const override
Generic print-print function for this Activity.
Definition: exit.h:65
Exit Event Action.
Definition: exit.h:33
SimTime_t getDeliveryTime() const
Return the time at which this Activity will be delivered.
Definition: activity.h:145
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:182
Exit(int num_threads, bool single_rank)
Create a new ExitEvent.
Definition: exit.cc:31
int getPriority() const
Return the Priority of this Activity.
Definition: activity.h:148
void execute(void) override
Function which will be called when the time for this Activity comes to pass.
Definition: exit.cc:133