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