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