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"
26extern int main(
int argc,
char** argv);
34using namespace SST::Core::Serialization;
37Output& getSimulationOutput();
38RankInfo getNumRanks();
55 SharedObjectChangeSet() {}
56 explicit SharedObjectChangeSet(
const std::string& name) :
81 const std::string&
getName() {
return name; }
84 void serialize_order(
serializer& ser)
override { SST_SER(name); }
86 ImplementVirtualSerializable(SharedObjectChangeSet);
99 friend class SharedObjectDataManager;
100 friend class SharedObject;
139 bool fully_published;
143 mutable std::mutex mtx;
146 inline void check_lock_for_write(
const std::string& obj)
149 Private::getSimulationOutput().fatal(
150 CALL_INFO_LONG, 1,
"ERROR: attempt to write to %s %s after init phase\n", obj.c_str(), name.c_str());
162 std::lock_guard<std::mutex>
lock(mtx);
163 int ret = share_count;
173 std::lock_guard<std::mutex>
lock(mtx);
206 fully_published(false),
217 void serialize_order(
serializer& ser)
override { SST_SER(name); }
222class SharedObjectDataManager
225 std::map<std::string, SharedObjectData*> shared_data;
228 static inline std::mutex mtx;
229 static inline std::mutex update_mtx;
234 SharedObjectDataManager() :
238 ~SharedObjectDataManager()
240 for (
auto x : shared_data ) {
245 template <
typename T>
246 T* getSharedObjectData(
const std::string name)
250 std::lock_guard<std::mutex> lock(mtx);
252 Private::getSimulationOutput().fatal(
253 CALL_INFO, 1,
"Attempting to initialize SharedObject %s after the init() phase\n", name.c_str());
255 auto obj = shared_data.find(name);
256 if ( obj == shared_data.end() ) {
258 auto ret =
new T(name);
259 shared_data[name] = ret;
264 auto obj_cast =
dynamic_cast<T*
>(obj->second);
266 if ( obj_cast ==
nullptr ) {
267 Private::getSimulationOutput().fatal(
268 CALL_INFO, 1,
"ERROR: Shared object %s requested with two different types\n", name.c_str());
274 void updateState(
bool finalize);
276 void serialize_order(
serializer& ser) { SST_SER(shared_data); }
286 enum verify_type { VERIFY_UNINITIALIZED, FE_VERIFY, INIT_VERIFY, NO_VERIFY };
289 virtual ~SharedObject() {}
291 virtual void serialize_order(
serializer& UNUSED(ser))
override {}
292 ImplementSerializable(SharedObject)
295 friend class SST::Simulation;
298 friend int ::main(
int argc,
char** argv);
300 static inline SharedObjectDataManager manager;
302 void incPublishCount(SharedObjectData* data) { data->incPublishCount(); }
304 int incShareCount(SharedObjectData* data) {
return data->incShareCount(); }
Definition serializable.h:25
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
This is the base class for holding data on changes made to the shared data on each rank.
Definition sharedObject.h:52
const std::string & getName()
Get the name of the shared data the changeset should be applied to.
Definition sharedObject.h:81
virtual void clear()=0
Clears the data.
virtual void applyChanges(SharedObjectDataManager *manager)=0
Apply the changes to the name shared data.
Definition sharedObject.h:223
virtual int getPublishCount()
Get the number of instances that have called publish() on their instance of the shared object.
Definition sharedObject.h:133
virtual void incPublishCount()
Increment the count of instances that have called publish.
Definition sharedObject.h:171
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:118
virtual SharedObjectChangeSet * getChangeSet()=0
Gets the changeset for this data on this rank.
virtual int incShareCount()
Increment the count of sharers.
Definition sharedObject.h:160
virtual ~SharedObjectData()
Destructor for SharedObjectData.
Definition sharedObject.h:215
const std::string & getName()
Get the name of the SharedObject for this data.
Definition sharedObject.h:108
virtual int getShareCount()
Get the number of sharers for this data.
Definition sharedObject.h:125
SharedObjectData(const std::string &name)
Constructor for SharedObjectData.
Definition sharedObject.h:202
void lock()
Called by the core when writing to shared regions is no longer allowed.
Definition sharedObject.h:195
Definition sharedObject.h:280
verify_type
Enum of verify types.
Definition sharedObject.h:286
Main control class for a SST Simulation.
Definition simulation.h:121