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" 27 template <
typename valT>
30 static_assert(!std::is_pointer<valT>::value,
"Cannot use a pointer type as value with SharedSet");
68 Private::getSimulationOutput().fatal(
69 CALL_INFO, 1,
"ERROR: called initialize() of SharedSet %s more than once\n", obj_name.c_str());
72 data = manager.getSharedObjectData<Data>(obj_name);
73 int ret = incShareCount(data);
74 data->setVerify(v_type);
79 typedef typename std::set<valT>::const_iterator const_iterator;
80 typedef typename std::set<valT>::const_reverse_iterator const_reverse_iterator;
87 inline size_t size()
const {
return data->getSize(); }
94 inline bool empty()
const {
return data->set.empty(); }
102 size_t count(
const valT& k)
const {
return data->set.count(k); }
107 const_iterator
begin()
const {
return data->set.cbegin(); }
112 const_iterator
end()
const {
return data->set.cend(); }
117 const_reverse_iterator
rbegin()
const {
return data->set.crbegin(); }
122 const_reverse_iterator
rend()
const {
return data->set.crend(); }
131 if ( published )
return;
133 incPublishCount(data);
154 Private::getSimulationOutput().fatal(
155 CALL_INFO, 1,
"ERROR: insert into SharedSet %s after publish() was called\n", data->
getName().c_str());
157 return data->write(value);
177 inline const_iterator
find(
const valT& value)
const {
return data->find(value); }
189 inline const valT&
mutex_find(
const valT& value)
const {
return data->mutex_read(value); }
193 SST::Shared::SharedObject::serialize_order(ser);
195 switch ( ser.mode() ) {
196 case SST::Core::Serialization::serializer::SIZER:
197 case SST::Core::Serialization::serializer::PACK:
199 std::string name = data->
getName();
203 case SST::Core::Serialization::serializer::UNPACK:
207 data = manager.getSharedObjectData<Data>(name);
226 ChangeSet* change_set;
231 Data(
const std::string& name) :
SharedObjectData(name), change_set(
nullptr), verify(VERIFY_UNINITIALIZED)
233 if ( Private::getNumRanks().rank > 1 ) { change_set =
new ChangeSet(name); }
238 if ( change_set )
delete change_set;
243 if ( v_type != verify && verify != VERIFY_UNINITIALIZED ) {
244 Private::getSimulationOutput().fatal(
245 CALL_INFO, 1,
"ERROR: Type different verify_types specified for SharedSet %s\n", name.c_str());
248 if ( change_set ) change_set->setVerify(v_type);
251 size_t getSize()
const 253 std::lock_guard<std::mutex>
lock(mtx);
257 void update_write(
const valT& value)
262 auto success =
set.insert(value);
263 if ( !success.second ) {
265 if ( verify != NO_VERIFY && !(value == *(success.first)) ) {
266 Private::getSimulationOutput().fatal(
267 CALL_INFO, 1,
"ERROR: wrote two non-equal values to same set item in SharedSet %s\n",
273 void write(
const valT& value)
276 check_lock_for_write(
"SharedSet");
278 if ( change_set ) change_set->addChange(value);
287 inline const_iterator find(
const valT& value) {
return set.find(value); }
290 inline const valT& mutex_find(
const valT& value)
292 std::lock_guard<std::mutex>
lock(mtx);
293 auto ret =
set.find(value);
303 SharedObjectData::serialize_order(ser);
313 std::set<valT> changes;
318 SharedObjectChangeSet::serialize_order(ser);
327 ChangeSet() : SharedObjectChangeSet(), verify(VERIFY_UNINITIALIZED) {}
328 ChangeSet(
const std::string& name) : SharedObjectChangeSet(name), verify(VERIFY_UNINITIALIZED) {}
330 void addChange(
const valT& value) { changes.insert(value); }
332 void setVerify(
verify_type v_type) { verify = v_type; }
334 void applyChanges(SharedObjectDataManager* manager)
override 336 auto data = manager->getSharedObjectData<Data>(
getName());
337 data->setVerify(verify);
338 for (
auto x : changes ) {
339 data->update_write(x);
343 void clear()
override { changes.clear(); }
351 #endif // SST_CORE_SHARED_SHAREDSET_H This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
Definition: sharedObject.h:269
const valT & 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:189
SharedSet class.
Definition: sharedSet.h:28
void lock()
Called by the core when writing to shared regions is no longer allowed.
Definition: sharedObject.h:186
virtual SharedObjectChangeSet * getChangeSet() override
Gets the changeset for this data on this rank.
Definition: sharedSet.h:298
bool isFullyPublished()
Checks to see if all instances of this SharedObject have called publish().
Definition: sharedObject.h:109
bool empty() const
Tests if the set is empty.
Definition: sharedSet.h:94
const_reverse_iterator rend() const
Get const_reverse_iterator to end of underlying set.
Definition: sharedSet.h:122
const_iterator begin() const
Get const_iterator to beginning of underlying set.
Definition: sharedSet.h:107
virtual void resetChangeSet() override
Resets the changeset for this data on this rank.
Definition: sharedSet.h:299
verify_type
Enum of verify types.
Definition: sharedObject.h:276
Definition: sharedSet.h:218
bool isFullyPublished()
Check whether all instances of this SharedSet have called publish().
Definition: sharedSet.h:143
const_iterator end() const
Get const_iterator to end of underlying set.
Definition: sharedSet.h:112
void publish()
Indicate that the calling element has written all the data it plans to write.
Definition: sharedSet.h:129
const std::string & getName()
Get the name of the SharedObject for this data.
Definition: sharedObject.h:99
virtual void applyChanges(SharedObjectDataManager *UNUSED(manager))=0
Apply the changes to the name shared data.
This is the base class for holding data on changes made to the shared data on each rank...
Definition: sharedObject.h:44
int initialize(const std::string &obj_name, verify_type v_type)
Initialize the SharedSet.
Definition: sharedSet.h:65
void insert(const valT &value)
Insert data to the set.
Definition: sharedSet.h:151
Base class for holding SharedObject data.
Definition: sharedObject.h:87
const_reverse_iterator rbegin() const
Get const_reverse_iterator to beginning of underlying set.
Definition: sharedSet.h:117
size_t size() const
Get the size of the set.
Definition: sharedSet.h:87
size_t count(const valT &k) const
Counts elements with a specific value.
Definition: sharedSet.h:102
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:177