SST 15.0
Structural Simulation Toolkit
activity.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_ACTIVITY_H
13#define SST_CORE_ACTIVITY_H
14
15#include "sst/core/mempool.h"
16#include "sst/core/output.h"
17#include "sst/core/serialization/serializable.h"
18#include "sst/core/sst_types.h"
19#include "sst/core/warnmacros.h"
20
21#include <cinttypes>
22#include <cstring>
23#include <errno.h>
24#include <sstream>
25
26// Default Priority Settings
27#define INTERACTIVEPRIOIRTY 0
28#define THREADSYNCPRIORITY 20
29#define SYNCPRIORITY 25
30#define STOPACTIONPRIORITY 30
31#define CLOCKPRIORITY 40
32#define EVENTPRIORITY 50
33#define MEMEVENTPRIORITY 50
34#define BARRIERPRIORITY 75
35#define ONESHOTPRIORITY 80
36#define STATISTICCLOCKPRIORITY 85
37#define FINALEVENTPRIORITY 98
38#define EXITPRIORITY 99
39
40extern int main(int argc, char** argv);
41
42namespace SST {
43
44/** Base class for all Activities in the SST Event Queue */
45class Activity : public SST::Core::MemPoolItem
46{
47public:
48 Activity() :
49 delivery_time(0),
50 priority_order(0),
51 queue_order(0)
52 {}
53 virtual ~Activity() {}
54
55 /**
56 Class to use as the less than operator for STL functions or
57 sorting algorithms. If a template parameter is set to true,
58 then that variable will be included in the comparison. The
59 parameters are: T - delivery time, P - priority and order tag,
60 Q - queue order.
61 */
62 template <bool T, bool P, bool Q>
63 class less
64 {
65 public:
66 inline bool operator()(const Activity* lhs, const Activity* rhs) const
67 {
68 if ( T && lhs->delivery_time != rhs->delivery_time ) return lhs->delivery_time < rhs->delivery_time;
69 if ( P && lhs->priority_order != rhs->priority_order ) return lhs->priority_order < rhs->priority_order;
70 return Q && lhs->queue_order < rhs->queue_order;
71 }
72
73 // // Version without branching. Still need to test to see if
74 // // this is faster than the above implementation for "real"
75 // // simulations. For the sst-benchmark, the above is slightly
76 // // faster. Uses the bitwise operator because there are no
77 // // early outs. For bools, this is logically equivalent to the
78 // // logical operators
79 // inline bool operator()(const Activity* lhs, const Activity* rhs) const
80 // {
81 // return ( T & lhs->delivery_time < rhs->delivery_time ) |
82 // (P & lhs->delivery_time == rhs->delivery_time & lhs->priority_order < rhs->priority_order) |
83 // (Q & lhs->delivery_time == rhs->delivery_time & lhs->priority_order == rhs->priority_order &
84 // lhs->queue_order < rhs->queue_order);
85 // }
86
87 // // Version without ifs, but with early outs in the logic.
88 // inline bool operator()(const Activity* lhs, const Activity* rhs) const
89 // {
90 // return ( T && lhs->delivery_time < rhs->delivery_time ) |
91 // (P && lhs->delivery_time == rhs->delivery_time && lhs->priority_order < rhs->priority_order) |
92 // (Q && lhs->delivery_time == rhs->delivery_time && lhs->priority_order == rhs->priority_order &&
93 // lhs->queue_order < rhs->queue_order);
94 // }
95 };
96
97 /**
98 Class to use as the greater than operator for STL functions or
99 sorting algorithms (used if you want to sort opposite the
100 natural soring order). If a template parameter is set to true,
101 then that variable will be included in the comparison. The
102 parameters are: T - delivery time, P - priority and order tag,
103 Q - queue order.
104 */
105 template <bool T, bool P, bool Q>
107 {
108 public:
109 inline bool operator()(const Activity* lhs, const Activity* rhs) const
110 {
111 if ( T && lhs->delivery_time != rhs->delivery_time ) return lhs->delivery_time > rhs->delivery_time;
112 if ( P && lhs->priority_order != rhs->priority_order ) return lhs->priority_order > rhs->priority_order;
113 return Q && lhs->queue_order > rhs->queue_order;
114 }
115
116 // // Version without branching. Still need to test to see if
117 // // this is faster than the above implementation for "real"
118 // // simulations. For the sst-benchmark, the above is slightly
119 // // faster. Uses the bitwise operator because there are no
120 // // early outs. For bools, this is logically equivalent to the
121 // // logical operators
122 // inline bool operator()(const Activity* lhs, const Activity* rhs) const
123 // {
124 // return ( T & lhs->delivery_time > rhs->delivery_time ) |
125 // (P & lhs->delivery_time == rhs->delivery_time & lhs->priority_order > rhs->priority_order) |
126 // (Q & lhs->delivery_time == rhs->delivery_time & lhs->priority_order == rhs->priority_order &
127 // lhs->queue_order > rhs->queue_order);
128 // }
129
130 // // Version without ifs, but with early outs in the logic.
131 // inline bool operator()(const Activity* lhs, const Activity* rhs) const
132 // {
133 // return ( T && lhs->delivery_time > rhs->delivery_time ) |
134 // (P && lhs->delivery_time == rhs->delivery_time && lhs->priority_order > rhs->priority_order) |
135 // (Q && lhs->delivery_time == rhs->delivery_time && lhs->priority_order == rhs->priority_order &&
136 // lhs->queue_order > rhs->queue_order);
137 // }
138 };
139
140
141 /** Function which will be called when the time for this Activity comes to pass. */
142 virtual void execute() = 0;
143
144 /** Set the time for which this Activity should be delivered */
145 inline void setDeliveryTime(SimTime_t time) { delivery_time = time; }
146
147 /** Return the time at which this Activity will be delivered */
148 inline SimTime_t getDeliveryTime() const { return delivery_time; }
149
150 /** Return the Priority of this Activity */
151 inline int getPriority() const { return (int)(priority_order >> 32); }
152
153 /** Sets the order tag */
154 inline void setOrderTag(uint32_t tag) { priority_order = (priority_order & 0xFFFFFFFF00000000ul) | (uint64_t)tag; }
155
156 /** Return the order tag associated with this activity */
157 inline uint32_t getOrderTag() const { return (uint32_t)(priority_order & 0xFFFFFFFFul); }
158
159 /** Returns the queue order associated with this activity */
160 inline uint64_t getQueueOrder() const { return queue_order; }
161
162 virtual bool isEvent() { return false; }
163 virtual bool isAction() { return false; }
164
165 /** Get a string represenation of the event. The default version
166 * will just use the name of the class, retrieved through the
167 * cls_name() function inherited from the serialzable class, which
168 * will return the name of the last class to call one of the
169 * serialization macros (ImplementSerializable(),
170 * ImplementVirtualSerializable(), or NotSerializable()).
171 * Subclasses can override this function if they want to add
172 * additional information.
173 */
174 std::string toString() const override
175 {
176 std::stringstream buf;
177
178 buf << cls_name() << " to be delivered at " << getDeliveryTimeInfo();
179 return buf.str();
180 }
181
182#ifdef __SST_DEBUG_EVENT_TRACKING__
183 virtual void printTrackingInfo(const std::string& UNUSED(header), Output& UNUSED(out)) const {}
184#endif
185
186 /** Set a new Queue order */
187 void setQueueOrder(uint64_t order) { queue_order = order; }
188
189 virtual void copyAllDeliveryInfo(const Activity* act)
190 {
191 delivery_time = act->delivery_time;
192 priority_order = act->priority_order;
193 queue_order = act->queue_order;
194 }
195
196protected:
197 /** Set the priority of the Activity */
198 void setPriority(uint64_t priority) { priority_order = (priority_order & 0x00000000FFFFFFFFul) | (priority << 32); }
199
200 /**
201 Gets the delivery time info as a string. To be used in
202 inherited classes if they'd like to overwrite the default print
203 or toString()
204 */
205 std::string getDeliveryTimeInfo() const
206 {
207 std::stringstream buf;
208 buf << "time: " << delivery_time << ", priority: " << getPriority() << ", order tag: " << getOrderTag()
209 << ", queue order: " << getQueueOrder();
210 return buf.str();
211 }
212
213
214 // Function used by derived classes to serialize data members.
215 // This class is not serializable, because not all class that
216 // inherit from it need to be serializable.
217 void serialize_order(SST::Core::Serialization::serializer& ser) override
218 {
219 SST_SER(delivery_time);
220 SST_SER(priority_order);
221 SST_SER(queue_order);
222 }
223
224 ImplementVirtualSerializable(SST::Activity);
225
226private:
227 // Data members
228 SimTime_t delivery_time;
229
230 // This will hold both the priority (high bits) and the link order
231 // (low_bits)
232 uint64_t priority_order;
233
234 // Used for TimeVortex implementations that don't naturally keep
235 // the insertion order
236 uint64_t queue_order;
237};
238
239} // namespace SST
240
241#endif // SST_CORE_ACTIVITY_H
Class to use as the greater than operator for STL functions or sorting algorithms (used if you want t...
Definition activity.h:107
Class to use as the less than operator for STL functions or sorting algorithms.
Definition activity.h:64
Base class for all Activities in the SST Event Queue.
Definition activity.h:46
std::string toString() const override
Get a string represenation of the event.
Definition activity.h:174
void setQueueOrder(uint64_t order)
Set a new Queue order.
Definition activity.h:187
void setPriority(uint64_t priority)
Set the priority of the Activity.
Definition activity.h:198
SimTime_t getDeliveryTime() const
Return the time at which this Activity will be delivered.
Definition activity.h:148
void setDeliveryTime(SimTime_t time)
Set the time for which this Activity should be delivered.
Definition activity.h:145
uint64_t getQueueOrder() const
Returns the queue order associated with this activity.
Definition activity.h:160
void setOrderTag(uint32_t tag)
Sets the order tag.
Definition activity.h:154
virtual void execute()=0
Function which will be called when the time for this Activity comes to pass.
uint32_t getOrderTag() const
Return the order tag associated with this activity.
Definition activity.h:157
std::string getDeliveryTimeInfo() const
Gets the delivery time info as a string.
Definition activity.h:205
int getPriority() const
Return the Priority of this Activity.
Definition activity.h:151
Definition mempool.h:30
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition output.h:54