12#ifndef SST_CORE_SHARED_SHAREDOBJECT_H
13#define SST_CORE_SHARED_SHAREDOBJECT_H
15#include "sst/core/output.h"
16#include "sst/core/rankInfo.h"
17#include "sst/core/serialization/serializable.h"
18#include "sst/core/sst_types.h"
31Output& getSimulationOutput();
32RankInfo getNumRanks();
49 SharedObjectChangeSet() {}
50 explicit SharedObjectChangeSet(
const std::string& name) :
75 const std::string&
getName() {
return name; }
80 ImplementVirtualSerializable(SharedObjectChangeSet);
93 friend class SharedObjectDataManager;
94 friend class SharedObject;
133 bool fully_published;
137 mutable std::mutex mtx;
140 inline void check_lock_for_write(
const std::string& obj)
143 Private::getSimulationOutput().fatal(
144 CALL_INFO_LONG, 1,
"ERROR: attempt to write to %s %s after init phase\n", obj.c_str(), name.c_str());
156 std::lock_guard<std::mutex>
lock(mtx);
157 int ret = share_count;
167 std::lock_guard<std::mutex>
lock(mtx);
200 fully_published(false),
213 ImplementVirtualSerializable(SharedObjectData);
219 std::map<std::string, SharedObjectData*> shared_data;
222 static std::mutex mtx;
223 static std::mutex update_mtx;
228 SharedObjectDataManager() :
232 ~SharedObjectDataManager()
234 for (
auto x : shared_data ) {
239 template <
typename T>
240 T* getSharedObjectData(
const std::string name)
244 std::lock_guard<std::mutex> lock(mtx);
246 Private::getSimulationOutput().fatal(
247 CALL_INFO, 1,
"Attempting to initialize SharedObject %s after the init() phase\n", name.c_str());
249 auto obj = shared_data.find(name);
250 if ( obj == shared_data.end() ) {
252 auto ret =
new T(name);
253 shared_data[name] = ret;
258 auto obj_cast =
dynamic_cast<T*
>(obj->second);
260 if ( obj_cast ==
nullptr ) {
261 Private::getSimulationOutput().fatal(
262 CALL_INFO, 1,
"ERROR: Shared object %s requested with two different types\n", name.c_str());
268 void updateState(
bool finalize);
281 enum verify_type { VERIFY_UNINITIALIZED, FE_VERIFY, INIT_VERIFY, NO_VERIFY };
284 virtual ~SharedObject() {}
287 ImplementSerializable(SST::Shared::SharedObject)
290 friend class SST::Simulation_impl;
291 static SharedObjectDataManager manager;
293 void incPublishCount(SharedObjectData* data) { data->incPublishCount(); }
295 int incShareCount(SharedObjectData* data) {
return data->incShareCount(); }
Definition serializable.h:24
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
virtual void clear()=0
Clears the data.
virtual void applyChanges(SharedObjectDataManager *manager)=0
Apply the changes to the name shared data.
Definition sharedObject.h:217
Base class for holding SharedObject data.
Definition sharedObject.h:91
virtual int getPublishCount()
Get the number of instances that have called publish() on their instance of the shared object.
Definition sharedObject.h:127
virtual void incPublishCount()
Increment the count of instances that have called publish.
Definition sharedObject.h:165
virtual void resetChangeSet()=0
Resets the changeset for this data on this rank.
bool isFullyPublished()
Checks to see if all instances of this SharedObject have called publish().
Definition sharedObject.h:112
virtual SharedObjectChangeSet * getChangeSet()=0
Gets the changeset for this data on this rank.
virtual int incShareCount()
Increment the count of sharers.
Definition sharedObject.h:154
virtual ~SharedObjectData()
Destructor for SharedObjectData.
Definition sharedObject.h:209
const std::string & getName()
Get the name of the SharedObject for this data.
Definition sharedObject.h:102
virtual int getShareCount()
Get the number of sharers for this data.
Definition sharedObject.h:119
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
Definition sharedObject.h:275
verify_type
Enum of verify types.
Definition sharedObject.h:281
Main control class for a SST Simulation.
Definition simulation_impl.h:87