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");
 
   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);
 
  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); }
 
  207         Data(
const std::string& name) : 
SharedObjectData(name), change_set(nullptr), verify(VERIFY_UNINITIALIZED)
 
  212         ~Data() { 
delete change_set; }
 
  216             if ( v_type != verify && verify != VERIFY_UNINITIALIZED ) {
 
  218                     CALL_INFO, 1, 
"ERROR: Type different verify_types specified for SharedSet %s\n", name.c_str());
 
  221             if ( change_set ) change_set->setVerify(v_type);
 
  224         size_t getSize()
 const 
  226             std::lock_guard<std::mutex> 
lock(mtx);
 
  230         void update_write(
const valT& value)
 
  235             auto success = set.insert(value);
 
  236             if ( !success.second ) {
 
  238                 if ( verify != NO_VERIFY && !(value == *(success.first)) ) {
 
  240                         CALL_INFO, 1, 
"ERROR: wrote two non-equal values to same set item in SharedSet %s\n",
 
  246         void write(
const valT& value)
 
  249             check_lock_for_write(
"SharedSet");
 
  251             if ( change_set ) change_set->addChange(value);
 
  260         inline const_iterator 
find(
const valT& value) { 
return set.find(value); }
 
  263         inline const valT& 
mutex_find(
const valT& value)
 
  265             std::lock_guard<std::mutex> 
lock(mtx);
 
  266             auto                        ret = set.find(value);
 
  271         virtual SharedObjectChangeSet* getChangeSet()
 override { 
return change_set; }
 
  272         virtual void                   resetChangeSet()
 override { change_set->clear(); }
 
  275         class ChangeSet : 
public SharedObjectChangeSet
 
  278             std::set<valT> changes;
 
  283                 SharedObjectChangeSet::serialize_order(ser);
 
  292             ChangeSet() : SharedObjectChangeSet(), verify(VERIFY_UNINITIALIZED) {}
 
  293             ChangeSet(
const std::string& name) : SharedObjectChangeSet(name), verify(VERIFY_UNINITIALIZED) {}
 
  295             void addChange(
const valT& value) { changes.insert(value); }
 
  297             void setVerify(
verify_type v_type) { verify = v_type; }
 
  299             void applyChanges(SharedObjectDataManager* manager)
 override 
  301                 auto data = manager->getSharedObjectData<Data>(
getName());
 
  302                 data->setVerify(verify);
 
  303                 for ( 
auto x : changes ) {
 
  304                     data->update_write(x);
 
  308             void clear()
 override { changes.clear(); }
 
  316 #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:34
 
Definition: sharedObject.h:253
 
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:30
 
void lock()
Called by the core when writing to shared regions is no longer allowed. 
Definition: sharedObject.h:179
 
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 std::string & getName()
Get the name of the shared data the changeset should be applied to. 
Definition: sharedObject.h:65
 
const_iterator begin() const 
Get const_iterator to beginning of underlying set. 
Definition: sharedSet.h:107
 
const_iterator end() const 
Get const_iterator to end of underlying set. 
Definition: sharedSet.h:112
 
verify_type
Enum of verify types. 
Definition: sharedObject.h:260
 
const_reverse_iterator rend() const 
Get const_reverse_iterator to end of underlying set. 
Definition: sharedSet.h:122
 
const_reverse_iterator rbegin() const 
Get const_reverse_iterator to beginning of underlying set. 
Definition: sharedSet.h:117
 
bool isFullyPublished()
Check whether all instances of this SharedSet have called publish(). 
Definition: sharedSet.h:143
 
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:177
 
void publish()
Indicate that the calling element has written all the data it plans to write. 
Definition: sharedSet.h:129
 
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:189
 
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:80
 
bool empty() const 
Tests if the set is empty. 
Definition: sharedSet.h:94