12#ifndef SST_CORE_SHARED_SHAREDSET_H
13#define SST_CORE_SHARED_SHAREDSET_H
15#include "sst/core/shared/sharedObject.h"
16#include "sst/core/sst_types.h"
23namespace SST::Shared {
29template <
typename valT>
30class SharedSet :
public SharedObject
32 static_assert(!std::is_pointer_v<valT>,
"Cannot use a pointer type as value with SharedSet");
74 Private::getSimulationOutput().fatal(
75 CALL_INFO, 1,
"ERROR: called initialize() of SharedSet %s more than once\n", obj_name.c_str());
78 data = manager.getSharedObjectData<
Data>(obj_name);
79 int ret = incShareCount(data);
80 data->setVerify(v_type);
85 using const_iterator =
typename std::set<valT>::const_iterator;
86 using const_reverse_iterator =
typename std::set<valT>::const_reverse_iterator;
93 inline size_t size()
const {
return data->getSize(); }
100 inline bool empty()
const {
return data->set.empty(); }
108 size_t count(
const valT& k)
const {
return data->set.count(k); }
113 const_iterator
begin()
const {
return data->set.cbegin(); }
118 const_iterator
end()
const {
return data->set.cend(); }
123 const_reverse_iterator
rbegin()
const {
return data->set.crbegin(); }
128 const_reverse_iterator
rend()
const {
return data->set.crend(); }
137 if ( published )
return;
139 incPublishCount(data);
160 Private::getSimulationOutput().fatal(
161 CALL_INFO, 1,
"ERROR: insert into SharedSet %s after publish() was called\n", data->getName().c_str());
163 return data->write(value);
183 inline const_iterator
find(
const valT& value)
const {
return data->find(value); }
195 inline const_iterator
mutex_find(
const valT& value)
const {
return data->mutex_find(value); }
199 SST::Shared::SharedObject::serialize_order(ser);
201 switch ( ser.mode() ) {
202 case SST::Core::Serialization::serializer::SIZER:
203 case SST::Core::Serialization::serializer::PACK:
205 std::string name = data->
getName();
209 case SST::Core::Serialization::serializer::UNPACK:
213 data = manager.getSharedObjectData<Data>(name);
216 case SST::Core::Serialization::serializer::MAP:
221 ImplementSerializable(SST::Shared::SharedSet<valT>)
235 ChangeSet* change_set;
242 verify(VERIFY_UNINITIALIZED)
244 explicit Data(
const std::string& name) :
247 verify(VERIFY_UNINITIALIZED)
249 if ( Private::getNumRanks().rank > 1 ) {
250 change_set =
new ChangeSet(name);
256 if ( change_set )
delete change_set;
261 if ( v_type != verify && verify != VERIFY_UNINITIALIZED ) {
262 Private::getSimulationOutput().fatal(
263 CALL_INFO, 1,
"ERROR: Type different verify_types specified for SharedSet %s\n", name.c_str());
266 if ( change_set ) change_set->setVerify(v_type);
269 size_t getSize()
const
271 std::lock_guard<std::mutex>
lock(mtx);
275 void update_write(
const valT& value)
280 auto success = set.insert(value);
281 if ( !success.second ) {
283 if ( verify != NO_VERIFY && !(value == *(success.first)) ) {
284 Private::getSimulationOutput().fatal(CALL_INFO, 1,
285 "ERROR: wrote two non-equal values to same set item in SharedSet %s\n", name.c_str());
290 void write(
const valT& value)
293 check_lock_for_write(
"SharedSet");
295 if ( change_set ) change_set->addChange(value);
304 inline const_iterator find(
const valT& value) {
return set.find(value); }
307 inline const_iterator mutex_find(
const valT& value)
309 std::lock_guard<std::mutex>
lock(mtx);
310 auto ret = set.find(value);
320 SharedObjectData::serialize_order(ser);
330 std::set<valT> changes;
335 SharedObjectChangeSet::serialize_order(ser);
340 ImplementSerializable(SST::Shared::SharedSet<valT>::Data::ChangeSet);
345 SharedObjectChangeSet(),
346 verify(VERIFY_UNINITIALIZED)
348 explicit ChangeSet(
const std::string& name) :
349 SharedObjectChangeSet(name),
350 verify(VERIFY_UNINITIALIZED)
353 void addChange(
const valT& value) { changes.insert(value); }
355 void setVerify(
verify_type v_type) { verify = v_type; }
357 void applyChanges(SharedObjectDataManager* manager)
override
359 auto data = manager->getSharedObjectData<Data>(
getName());
360 data->setVerify(verify);
361 for (
auto x : changes ) {
362 data->update_write(x);
366 void clear()
override { changes.clear(); }
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45
This is the base class for holding data on changes made to the shared data on each rank.
Definition sharedObject.h:46
const std::string & getName()
Get the name of the shared data the changeset should be applied to.
Definition sharedObject.h:75
const std::string & getName()
Get the name of the SharedObject for this data.
Definition sharedObject.h:102
SharedObjectData(const std::string &name)
Constructor for SharedObjectData.
Definition sharedObject.h:196
void lock()
Called by the core when writing to shared regions is no longer allowed.
Definition sharedObject.h:189
verify_type
Enum of verify types.
Definition sharedObject.h:281
Definition sharedSet.h:228
virtual void resetChangeSet() override
Resets the changeset for this data on this rank.
Definition sharedSet.h:316
virtual SharedObjectChangeSet * getChangeSet() override
Gets the changeset for this data on this rank.
Definition sharedSet.h:315
const_iterator mutex_find(const valT &value) const
Searches the SharedSet for an element equivalent to value and returns a const iterator to it if found...
Definition sharedSet.h:195
const_reverse_iterator rbegin() const
Get const_reverse_iterator to beginning of underlying set.
Definition sharedSet.h:123
const_iterator end() const
Get const_iterator to end of underlying set.
Definition sharedSet.h:118
int initialize(const std::string &obj_name, verify_type v_type=FE_VERIFY)
Initialize the SharedSet.
Definition sharedSet.h:71
const_iterator find(const valT &value) const
Searches the SharedSet for an element equivalent to value and returns a const iterator to it if found...
Definition sharedSet.h:183
bool isFullyPublished()
Check whether all instances of this SharedSet have called publish().
Definition sharedSet.h:149
const_reverse_iterator rend() const
Get const_reverse_iterator to end of underlying set.
Definition sharedSet.h:128
void publish()
Indicate that the calling element has written all the data it plans to write.
Definition sharedSet.h:135
void insert(const valT &value)
Insert data to the set.
Definition sharedSet.h:157
bool empty() const
Tests if the set is empty.
Definition sharedSet.h:100
const_iterator begin() const
Get const_iterator to beginning of underlying set.
Definition sharedSet.h:113
size_t count(const valT &k) const
Counts elements with a specific value.
Definition sharedSet.h:108
size_t size() const
Get the size of the set.
Definition sharedSet.h:93