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" 25 extern int main(
int argc,
char** argv);
29 class Simulation_impl;
34 Output& getSimulationOutput();
35 RankInfo getNumRanks();
41 class SharedObjectDataManager;
70 virtual void clear() = 0;
78 const std::string&
getName() {
return name; }
83 ImplementVirtualSerializable(SharedObjectChangeSet);
136 bool fully_published;
140 mutable std::mutex mtx;
143 inline void check_lock_for_write(
const std::string& obj)
146 Private::getSimulationOutput().fatal(
147 CALL_INFO_LONG, 1,
"ERROR: attempt to write to %s %s after init phase\n", obj.c_str(), name.c_str());
159 std::lock_guard<std::mutex>
lock(mtx);
160 int ret = share_count;
170 std::lock_guard<std::mutex>
lock(mtx);
203 fully_published(false),
216 ImplementVirtualSerializable(SharedObjectData);
222 std::map<std::string, SharedObjectData*> shared_data;
225 static std::mutex mtx;
226 static std::mutex update_mtx;
237 for (
auto x : shared_data ) {
242 template <
typename T>
243 T* getSharedObjectData(
const std::string name)
247 std::lock_guard<std::mutex> lock(mtx);
249 Private::getSimulationOutput().fatal(
250 CALL_INFO, 1,
"Attempting to initialize SharedObject %s after the init() phase\n", name.c_str());
252 auto obj = shared_data.find(name);
253 if ( obj == shared_data.end() ) {
255 auto ret =
new T(name);
256 shared_data[name] = ret;
261 auto obj_cast =
dynamic_cast<T*
>(obj->second);
263 if ( obj_cast ==
nullptr ) {
264 Private::getSimulationOutput().fatal(
265 CALL_INFO, 1,
"ERROR: Shared object %s requested with two different types\n", name.c_str());
271 void updateState(
bool finalize);
283 enum verify_type { VERIFY_UNINITIALIZED, FE_VERIFY, INIT_VERIFY, NO_VERIFY };
286 virtual ~SharedObject() {}
295 friend int ::main(
int argc,
char** argv);
297 static SharedObjectDataManager manager;
299 void incPublishCount(SharedObjectData* data) { data->incPublishCount(); }
301 int incShareCount(SharedObjectData* data) {
return data->incShareCount(); }
307 #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:42
virtual void applyChanges(SharedObjectDataManager *manager)=0
Apply the changes to the name shared data.
Definition: sharedObject.h:276
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:122
void lock()
Called by the core when writing to shared regions is no longer allowed.
Definition: sharedObject.h:192
bool isFullyPublished()
Checks to see if all instances of this SharedObject have called publish().
Definition: sharedObject.h:115
const std::string & getName()
Get the name of the shared data the changeset should be applied to.
Definition: sharedObject.h:78
SharedObjectData(const std::string &name)
Constructor for SharedObjectData.
Definition: sharedObject.h:199
verify_type
Enum of verify types.
Definition: sharedObject.h:283
Definition: serializable.h:23
virtual void incPublishCount()
Increment the count of instances that have called publish.
Definition: sharedObject.h:168
Definition: sharedObject.h:219
Main control class for a SST Simulation.
Definition: simulation_impl.h:122
virtual int getPublishCount()
Get the number of instances that have called publish() on their instance of the shared object...
Definition: sharedObject.h:130
virtual int incShareCount()
Increment the count of sharers.
Definition: sharedObject.h:157
const std::string & getName()
Get the name of the SharedObject for this data.
Definition: sharedObject.h:105
virtual void clear()=0
Clears the data.
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:48
Base class for holding SharedObject data.
Definition: sharedObject.h:93
virtual ~SharedObjectData()
Destructor for SharedObjectData.
Definition: sharedObject.h:212