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