12 #ifndef SST_CORE_CORE_SHARED_SHAREDSET_H
13 #define SST_CORE_CORE_SHARED_SHAREDSET_H
15 #include "sst/core/sst_types.h"
16 #include "sst/core/shared/sharedObject.h"
27 template <
typename valT>
29 static_assert(!std::is_pointer<valT>::value,
"Cannot use a pointer type as value with SharedSet");
70 CALL_INFO,1,
"ERROR: called initialize() of SharedSet %s more than once\n",obj_name.c_str());
73 data = manager.getSharedObjectData<Data>(obj_name);
74 int ret = incShareCount(data);
75 data->setVerify(v_type);
80 typedef typename std::set<valT>::const_iterator const_iterator;
81 typedef typename std::set<valT>::const_reverse_iterator const_reverse_iterator;
88 inline size_t size()
const {
return data->getSize(); }
95 inline bool empty()
const {
return data->set.empty(); }
104 size_t count (
const valT& k)
const {
105 return data->set.count(k);
112 return data->set.cbegin();
118 const_iterator
end()
const {
119 return data->set.cend();
126 return data->set.crbegin();
132 const_reverse_iterator
rend()
const {
133 return data->set.crend();
143 if ( published )
return;
145 incPublishCount(data);
156 return data->isFullyPublished();
169 CALL_INFO,1,
"ERROR: insert into SharedSet %s after publish() was called\n",
170 data->getName().c_str());
172 return data->write(value);
192 inline const_iterator
find(
const valT& value)
const {
193 return data->find(value);
207 return data->mutex_read(value);
228 Data(
const std::string& name) :
231 verify(VERIFY_UNINITIALIZED)
243 if ( v_type != verify && verify != VERIFY_UNINITIALIZED ) {
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 {
252 std::lock_guard<std::mutex>
lock(mtx);
256 void update_write(
const valT& value) {
260 auto success = set.insert(value);
261 if ( !success.second ) {
263 if ( verify != NO_VERIFY && !(value == *(success.first)) ) {
265 CALL_INFO, 1,
"ERROR: wrote two non-equal values to same set item in SharedSet %s\n",name.c_str());
270 void write(
const valT& value) {
272 check_lock_for_write(
"SharedSet");
274 if ( change_set ) change_set->addChange(value);
283 inline const_iterator
find(
const valT& value) {
284 return set.find(value);
288 inline const valT&
mutex_find(
const valT& value) {
289 std::lock_guard<std::mutex>
lock(mtx);
290 auto ret = set.find(value);
295 virtual SharedObjectChangeSet* getChangeSet()
override {
298 virtual void resetChangeSet()
override {
303 class ChangeSet :
public SharedObjectChangeSet {
305 std::set<valT> changes;
309 SharedObjectChangeSet::serialize_order(ser);
319 SharedObjectChangeSet(),
320 verify(VERIFY_UNINITIALIZED)
322 ChangeSet(
const std::string& name) :
323 SharedObjectChangeSet(name),
324 verify(VERIFY_UNINITIALIZED)
327 void addChange(
const valT& value) {
328 changes.insert(value);
335 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 {
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:263
static Simulation * getSimulation()
Return a pointer to the singleton instance of the Simulation.
Definition: simulation.cc:52
SharedSet class.
Definition: sharedSet.h:28
Definition: sharedRegionImpl.h:31
void lock()
Called by the core when writing to shared regions is no longer allowed.
Definition: sharedObject.h:185
size_t size() const
Get the size of the set.
Definition: sharedSet.h:88
size_t count(const valT &k) const
Counts elements with a specific value.
Definition: sharedSet.h:104
const std::string & getName()
Get the name of the shared data the changeset should be applied to.
Definition: sharedObject.h:68
const_iterator begin() const
Get const_iterator to beginning of underlying set.
Definition: sharedSet.h:111
const_iterator end() const
Get const_iterator to end of underlying set.
Definition: sharedSet.h:118
verify_type
Enum of verify types.
Definition: sharedObject.h:271
const_reverse_iterator rend() const
Get const_reverse_iterator to end of underlying set.
Definition: sharedSet.h:132
const_reverse_iterator rbegin() const
Get const_reverse_iterator to beginning of underlying set.
Definition: sharedSet.h:125
bool isFullyPublished()
Check whether all instances of this SharedSet have called publish().
Definition: sharedSet.h:155
void fatal(uint32_t line, const char *file, const char *func, int exit_code, const char *format,...) const
Output the fatal message with formatting as specified by the format parameter.
Definition: output.cc:155
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:192
void publish()
Indicate that the calling element has written all the data it plans to write.
Definition: sharedSet.h:142
virtual void applyChanges(SharedObjectDataManager *UNUSED(manager))=0
Apply the changes to the name shared data.
static Output & getSimulationOutput()
Return the base simulation Output class instance.
Definition: simulation.cc:70
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:206
int initialize(const std::string &obj_name, verify_type v_type)
Initialize the SharedSet.
Definition: sharedSet.h:67
void insert(const valT &value)
Insert data to the set.
Definition: sharedSet.h:166
Base class for holding SharedObject data.
Definition: sharedObject.h:87
bool empty() const
Tests if the set is empty.
Definition: sharedSet.h:95