SST  15.1.0
StructuralSimulationToolkit
syncQueue.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_SYNC_SYNCQUEUE_H
13 #define SST_CORE_SYNC_SYNCQUEUE_H
14 
15 #include "sst/core/activityQueue.h"
16 #include "sst/core/rankInfo.h"
17 #include "sst/core/threadsafe.h"
18 
19 #include <cstddef>
20 #include <cstdint>
21 #include <vector>
22 
23 namespace SST {
24 
25 /**
26  \class SyncQueue
27 
28  Internal API
29 
30  Base class for all Sync Queues
31 */
32 class SyncQueue : public ActivityQueue
33 {
34 public:
35  explicit SyncQueue(RankInfo to_rank) :
36  ActivityQueue(),
37  to_rank(to_rank)
38  {}
39  ~SyncQueue() {}
40 
41  /** Accessor method to get to_rank */
42  RankInfo getToRank() { return to_rank; }
43 
44 private:
45  RankInfo to_rank;
46 };
47 
48 /**
49  * \class SyncQueue
50  *
51  * Internal API
52  *
53  * Activity Queue for use by Sync Objects
54  */
55 class RankSyncQueue : public SyncQueue
56 {
57 public:
58  struct Header
59  {
60  uint32_t mode;
61  uint32_t count;
62  uint32_t buffer_size;
63  };
64 
65  explicit RankSyncQueue(RankInfo to_rank);
66  ~RankSyncQueue() = default;
67 
68  bool empty() override;
69  int size() override;
70  void insert(Activity* activity) override;
71  Activity* pop() override; // Not a good idea for this particular class
72  Activity* front() override;
73 
74  // Not part of the ActivityQueue interface
75  /** Clear elements from the queue */
76  void clear();
77  /** Accessor method to the internal queue */
78  char* getData();
79 
80  uint64_t getDataSize() { return buf_size + (activities.capacity() * sizeof(Activity*)); }
81 
82 private:
83  char* buffer;
84  size_t buf_size;
85  std::vector<Activity*> activities;
86 
88 };
89 
90 class ThreadSyncQueue : public SyncQueue
91 {
92 public:
93  explicit ThreadSyncQueue(RankInfo to_rank) :
94  SyncQueue(to_rank)
95  {}
96  ~ThreadSyncQueue() {}
97 
98  /** Returns true if the queue is empty */
99  bool empty() override { return activities.empty(); }
100 
101  /** Returns the number of activities in the queue */
102  int size() override { return activities.size(); }
103 
104  /** Not supported */
105  Activity* pop() override
106  {
107  // Need to fatal
108  return nullptr;
109  }
110 
111  /** Insert a new activity into the queue */
112  void insert(Activity* activity) override { activities.push_back(activity); }
113 
114  /** Not supported */
115  Activity* front() override
116  {
117  // Need to fatal
118  return nullptr;
119  }
120 
121  void clear() { activities.clear(); }
122 
123  std::vector<Activity*>& getVector() { return activities; }
124 
125 private:
126  std::vector<Activity*> activities;
127 };
128 
129 } // namespace SST
130 
131 #endif // SST_CORE_SYNC_SYNCQUEUE_H
Activity * front() override
Returns the next activity.
Definition: syncQueue.cc:77
Base class for all Activities in the SST Event Queue.
Definition: activity.h:47
int size() override
Returns the number of activities in the queue.
Definition: syncQueue.h:102
Activity * pop() override
Remove and return the next activity.
Definition: syncQueue.cc:65
bool empty() override
Returns true if the queue is empty.
Definition: syncQueue.h:99
Definition: action.cc:18
RankInfo getToRank()
Accessor method to get to_rank.
Definition: syncQueue.h:42
Activity * pop() override
Not supported.
Definition: syncQueue.h:105
void insert(Activity *activity) override
Insert a new activity into the queue.
Definition: syncQueue.h:112
Definition: rankInfo.h:23
int size() override
Returns the number of activities in the queue.
Definition: syncQueue.cc:51
Definition: syncQueue.h:90
Definition: threadsafe.h:135
void clear()
Clear elements from the queue.
Definition: syncQueue.cc:84
bool empty() override
Returns true if the queue is empty.
Definition: syncQueue.cc:44
char * getData()
Accessor method to the internal queue.
Definition: syncQueue.cc:91
Internal API.
Definition: syncQueue.h:32
Definition: syncQueue.h:55
void insert(Activity *activity) override
Insert a new activity into the queue.
Definition: syncQueue.cc:58
Activity * front() override
Not supported.
Definition: syncQueue.h:115
Base Class for a queue of Activities.
Definition: activityQueue.h:21
Definition: syncQueue.h:58