12 #ifndef SST_CORE_SHARED_SHAREDOBJECT_H
13 #define SST_CORE_SHARED_SHAREDOBJECT_H
15 #include "sst/core/serialization/serializable.h"
16 #include "sst/core/simulation.h"
17 #include "sst/core/sst_types.h"
23 class Simulation_impl;
30 class SharedObjectDataManager;
57 virtual void clear() = 0;
65 const std::string&
getName() {
return name; }
70 ImplementVirtualSerializable(SharedObjectChangeSet);
92 const std::string&
getName() {
return name; }
123 bool fully_published;
127 mutable std::mutex mtx;
130 inline void check_lock_for_write(
const std::string& obj)
134 CALL_INFO_LONG, 1,
"ERROR: attempt to write to %s %s after init phase\n", obj.c_str(), name.c_str());
146 std::lock_guard<std::mutex>
lock(mtx);
147 int ret = share_count;
157 std::lock_guard<std::mutex>
lock(mtx);
190 fully_published(false),
203 std::map<std::string, SharedObjectData*> shared_data;
206 static std::mutex mtx;
207 static std::mutex update_mtx;
216 for (
auto x : shared_data ) {
221 template <
typename T>
222 T* getSharedObjectData(
const std::string name)
226 std::lock_guard<std::mutex> lock(mtx);
229 CALL_INFO, 1,
"Attempting to initialize SharedObject %s after the init() phase\n", name.c_str());
231 auto obj = shared_data.find(name);
232 if ( obj == shared_data.end() ) {
234 auto ret =
new T(name);
235 shared_data[name] = ret;
240 auto obj_cast =
dynamic_cast<T*
>(obj->second);
242 if ( obj_cast ==
nullptr ) {
244 CALL_INFO, 1,
"ERROR: Shared object %s requested with two different types\n", name.c_str());
250 void updateState(
bool finalize);
260 enum verify_type { VERIFY_UNINITIALIZED, FE_VERIFY, INIT_VERIFY, NO_VERIFY };
263 virtual ~SharedObject() {}
267 static SharedObjectDataManager manager;
269 void incPublishCount(SharedObjectData* data) { data->incPublishCount(); }
271 int incShareCount(SharedObjectData* data) {
return data->incShareCount(); }
277 #endif // SST_CORE_SHARED_SHAREDOBJECT_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
virtual SharedObjectChangeSet * getChangeSet()=0
Gets the changeset for this data on this rank.
virtual int getShareCount()
Get the number of sharers for this data.
Definition: sharedObject.h:109
void lock()
Called by the core when writing to shared regions is no longer allowed.
Definition: sharedObject.h:179
bool isFullyPublished()
Checks to see if all instances of this SharedObject have called publish().
Definition: sharedObject.h:102
const std::string & getName()
Get the name of the shared data the changeset should be applied to.
Definition: sharedObject.h:65
SharedObjectData(const std::string &name)
Constructor for SharedObjectData.
Definition: sharedObject.h:186
verify_type
Enum of verify types.
Definition: sharedObject.h:260
Definition: serializable.h:118
virtual void incPublishCount()
Increment the count of instances that have called publish.
Definition: sharedObject.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
Definition: sharedObject.h:200
Main control class for a SST Simulation.
Definition: simulation_impl.h:74
virtual int getPublishCount()
Get the number of instances that have called publish() on their instance of the shared object...
Definition: sharedObject.h:117
virtual int incShareCount()
Increment the count of sharers.
Definition: sharedObject.h:144
const std::string & getName()
Get the name of the SharedObject for this data.
Definition: sharedObject.h:92
virtual void clear()=0
Clears the data.
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
virtual void resetChangeSet()=0
Resets the changeset for this data on this rank.
This is the base class for holding data on changes made to the shared data on each rank...
Definition: sharedObject.h:37
Base class for holding SharedObject data.
Definition: sharedObject.h:80
virtual ~SharedObjectData()
Destructor for SharedObjectData.
Definition: sharedObject.h:197