SST  14.0.0
StructuralSimulationToolkit
sharedArray.h
1 // Copyright 2009-2024 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2024, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_SHARED_SHAREDARRAY_H
13 #define SST_CORE_SHARED_SHAREDARRAY_H
14 
15 #include "sst/core/serialization/serializable.h"
16 #include "sst/core/shared/sharedObject.h"
17 #include "sst/core/sst_types.h"
18 
19 #include <vector>
20 
21 namespace SST {
22 namespace Shared {
23 
24 /**
25  SharedArray class. The class is templated to allow for an array
26  of any non-pointer type. The type must be serializable.
27  */
28 template <typename T>
29 class SharedArray : public SharedObject
30 {
31  static_assert(!std::is_pointer<T>::value, "Cannot use a pointer type with SharedArray");
32 
33  // Forward declaration. Defined below
34  class Data;
35 
36 public:
37  /**
38  Default constructor for SharedArray.
39  */
40  SharedArray() : SharedObject(), published(false), data(nullptr) {}
41 
42  /**
43  Shared Array Destructor
44  */
46  {
47  // data does not need to be deleted since the
48  // SharedObjectManager owns the pointer
49  }
50 
51  /**
52  Initialize the SharedArray.
53 
54  @param obj_name Name of the object. This name is how the
55  object is uniquely identified across ranks.
56 
57  @param length Length of the array. The length can be 0 if no
58  data is going to be written by the calling element, otherwise,
59  it must be large enough to write the desired data. The final
60  length of the array will be the maximum of the requested
61  lengths. The length of the array can be queried using the
62  size() method.
63 
64  @param init_value value that entries should be initialized to.
65  By default, each array item will be initialized using the
66  default constructor for the class being stored.
67 
68  @param verify_mode Specifies how multiply written data should
69  be verified. FE_VERIFY uses a full/empty bit for each entry
70  and if a value has previously been written, it will make sure
71  the two values match. INIT_VERIFY will simply compare writes
72  against the current value and will error unless the values
73  aren't the same or the existing value is the init_value. When
74  NO_VERIFY is passed, no verification will occur. This is
75  mostly useful when you can guarantee that multiple elements
76  won't write the same value and you want to do in-place
77  modifications as you initialize. VERIFY_UNINITIALIZED is a
78  reserved value and should not be passed.
79 
80  @return returns the number of instances that have intialized
81  themselve before this instance on this MPI rank.
82  */
83  int initialize(const std::string& obj_name, size_t length = 0, T init_value = T(), verify_type v_type = INIT_VERIFY)
84  {
85  if ( data ) {
86  Private::getSimulationOutput().fatal(
87  CALL_INFO, 1, "ERROR: called initialize() of SharedArray %s more than once\n", obj_name.c_str());
88  }
89 
90  if ( v_type == VERIFY_UNINITIALIZED ) {
91  Private::getSimulationOutput().fatal(
92  CALL_INFO, 1,
93  "ERROR: VERIFY_UNINITIALIZED passed into instance of SharedArray %s. "
94  "This is a reserved value and cannot be passed in here. \n",
95  obj_name.c_str());
96  }
97 
98  data = manager.getSharedObjectData<Data>(obj_name);
99  int ret = incShareCount(data);
100  if ( length != 0 ) data->setSize(length, init_value, v_type);
101  return ret;
102  }
103 
104  /*** Typedefs and functions to mimic parts of the vector API ***/
105 
106  typedef typename std::vector<T>::const_iterator const_iterator;
107  typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
108 
109  /**
110  Get the length of the array.
111 
112  @return length of the array
113  */
114  inline size_t size() const { return data->getSize(); }
115 
116  /**
117  Tests if array is empty.
118 
119  @return true if array is empty (size = 0), false otherwise
120  */
121  inline bool empty() const { return data->array.empty(); }
122 
123  /**
124  Get const_iterator to beginning of underlying map
125  */
126  const_iterator begin() const { return data->array.cbegin(); }
127 
128  /**
129  Get const_iterator to end of underlying map
130  */
131  const_iterator end() const { return data->array.cend(); }
132 
133  /**
134  Get const_reverse_iterator to beginning of underlying map
135  */
136  const_reverse_iterator rbegin() const { return data->array.crbegin(); }
137 
138  /**
139  Get const_reverse_iterator to end of underlying map
140  */
141  const_reverse_iterator rend() const { return data->array.crend(); }
142 
143  /**
144  Indicate that the calling element has written all the data it
145  plans to write. Writing to the array through this instance
146  after publish() is called will create an error.
147  */
148  void publish()
149  {
150  if ( published ) return;
151  published = true;
152  incPublishCount(data);
153  }
154 
155  /**
156  Check whether all instances of this SharedArray have called
157  publish(). NOTE: Is is possible that this could return true
158  one round, but false the next if a new instance of the
159  SharedArray was initialized but not published after the last
160  call.
161  */
162  bool isFullyPublished() { return data->isFullyPublished(); }
163 
164  /**
165  Write data to the array. This function is thread-safe, as a
166  mutex is used to ensure only one write at a time.
167 
168  @param index index of the write
169 
170  @param value value to be written
171  */
172  inline void write(int index, const T& value)
173  {
174  if ( published ) {
175  Private::getSimulationOutput().fatal(
176  CALL_INFO, 1, "ERROR: write to SharedArray %s after publish() was called\n", data->getName().c_str());
177  }
178  return data->write(index, value);
179  }
180 
181  /**
182  Read data from the array. This returns a const reference, so
183  is read only.
184 
185  NOTE: This function does not use a mutex, so it is possible to
186  get invalid results if another thread caused a resize of the
187  underlying data structure at the same time as the read.
188  However, after the init() phase of simulation is complete (in
189  setup() and beyond), this is always a safe operation. If
190  reading during init() and you can't guarantee that all elements
191  have already written all data to the SharedArray, use
192  mutex_read() to guarantee thread safety.
193 
194  @param index index to read
195 
196  @return const reference to data at index
197  */
198  inline const T& operator[](int index) const { return data->read(index); }
199 
200  /**
201  Read data from the array. This returns a const reference, so
202  is read only. This version of read is always thread safe (@see
203  operator[]).
204 
205  @param index index to read
206 
207  @return const reference to data at index
208  */
209  inline const T& mutex_read(int index) const { return data->mutex_read(index); }
210 
211  void serialize_order(SST::Core::Serialization::serializer& ser) override
212  {
213  SST::Shared::SharedObject::serialize_order(ser);
214  ser& published;
215  switch ( ser.mode() ) {
216  case SST::Core::Serialization::serializer::SIZER:
217  case SST::Core::Serialization::serializer::PACK:
218  {
219  std::string name = data->getName();
220  ser& name;
221  break;
222  }
223  case SST::Core::Serialization::serializer::UNPACK:
224  {
225  std::string name;
226  ser& name;
227  data = manager.getSharedObjectData<Data>(name);
228  break;
229  }
230  };
231  }
232  ImplementSerializable(SST::Shared::SharedArray<T>)
233 
234 private:
235  bool published;
236  Data* data;
237 
238  class Data : public SharedObjectData
239  {
240 
241  // Forward declaration. Defined below
242  class ChangeSet;
243 
244  public:
245  std::vector<T> array;
246  std::vector<bool> written;
247  ChangeSet* change_set;
248  T init;
249  verify_type verify;
250 
251  Data() : SharedObjectData(), change_set(nullptr), verify(VERIFY_UNINITIALIZED) {}
252  Data(const std::string& name) : SharedObjectData(name), change_set(nullptr), verify(VERIFY_UNINITIALIZED)
253  {
254  if ( Private::getNumRanks().rank > 1 ) { change_set = new ChangeSet(name); }
255  }
256 
257  ~Data()
258  {
259  if ( change_set ) delete change_set;
260  }
261 
262  /**
263  Set the size of the array. An element can only write up to the
264  current size (reading or writing beyond the size will create
265  undefined behavior). However, an element can put in the size
266  it needs for it's writes and it will end up being the largest
267  size requested. We use a vector underneatch the covers to
268  manage the memory/copying of data.
269  */
270  void setSize(size_t size, const T& init_data, verify_type v_type)
271  {
272  // If the data is uninitialized, then there is nothing to do
273  if ( v_type == VERIFY_UNINITIALIZED ) return;
274  std::lock_guard<std::mutex> lock(mtx);
275  if ( size > array.size() ) {
276  // Need to resize the vector
277  array.resize(size, init_data);
278  if ( v_type == FE_VERIFY ) { written.resize(size); }
279  if ( change_set ) change_set->setSize(size, init_data, v_type);
280  }
281  // init and verify must match across all intances. We can
282  // tell that they have been when verify is not
283  // VERIFY_UNINITIALIZED.
284  if ( verify != VERIFY_UNINITIALIZED ) {
285  if ( init != init_data ) {
286  Private::getSimulationOutput().fatal(
287  CALL_INFO, 1, "ERROR: Two different init_data values passed into SharedArray %s\n",
288  name.c_str());
289  }
290 
291  if ( verify != v_type ) {
292  Private::getSimulationOutput().fatal(
293  CALL_INFO, 1, "ERROR: Two different verify types passed into SharedArray %s\n", name.c_str());
294  }
295  }
296  init = init_data;
297  verify = v_type;
298  }
299 
300  size_t getSize()
301  {
302  std::lock_guard<std::mutex> lock(mtx);
303  return array.size();
304  }
305 
306  void update_write(int index, const T& data)
307  {
308  // Don't need to mutex because this is only ever called
309  // from one thread at a time, with barrier before and
310  // after, or from write(), which does mutex.
311  bool check = false;
312  switch ( verify ) {
313  case FE_VERIFY:
314  check = written[index];
315  break;
316  case INIT_VERIFY:
317  check = array[index] != init;
318  break;
319  default:
320  break;
321  }
322  if ( check && (array[index] != data) ) {
323  Private::getSimulationOutput().fatal(
324  CALL_INFO, 1, "ERROR: wrote two different values to index %d of SharedArray %s\n", index,
325  name.c_str());
326  }
327  array[index] = data;
328  if ( verify == FE_VERIFY ) written[index] = true;
329  }
330 
331  void write(int index, const T& data)
332  {
333  std::lock_guard<std::mutex> lock(mtx);
334  check_lock_for_write("SharedArray");
335  update_write(index, data);
336  if ( verify == FE_VERIFY ) written[index] = true;
337  if ( change_set ) change_set->addChange(index, data);
338  }
339 
340  // Inline the read since it may be called often during run().
341  // This read is not protected from data races in the case where
342  // the array may be resized by another thread. If there is a
343  // danger of the array being resized during init, use the
344  // mutex_read function until after the init phase.
345  inline const T& read(int index) const { return array[index]; }
346 
347  // Mutexed read for use if you are resizing the array as you go
348  inline const T& mutex_read(int index) const
349  {
350  std::lock_guard<std::mutex> lock(mtx);
351  auto ret = array[index];
352  return ret;
353  }
354 
355  // Functions inherited from SharedObjectData
356  virtual SharedObjectChangeSet* getChangeSet() override { return change_set; }
357  virtual void resetChangeSet() override { change_set->clear(); }
358 
359  void serialize_order(SST::Core::Serialization::serializer& ser) override
360  {
361  SharedObjectData::serialize_order(ser);
362  ser& array;
363  }
364 
365  ImplementSerializable(SST::Shared::SharedArray<T>::Data);
366 
367  private:
368  class ChangeSet : public SharedObjectChangeSet
369  {
370 
371  std::vector<std::pair<int, T>> changes;
372  size_t size;
373  T init;
374  verify_type verify;
375 
376  void serialize_order(SST::Core::Serialization::serializer& ser) override
377  {
378  SharedObjectChangeSet::serialize_order(ser);
379  ser& changes;
380  ser& size;
381  ser& init;
382  ser& verify;
383  }
384 
385  ImplementSerializable(SST::Shared::SharedArray<T>::Data::ChangeSet);
386 
387  public:
388  // For serialization
389  ChangeSet() : SharedObjectChangeSet() {}
390  ChangeSet(const std::string& name) : SharedObjectChangeSet(name), size(0), verify(VERIFY_UNINITIALIZED) {}
391 
392  void addChange(int index, const T& value) { changes.emplace_back(index, value); }
393 
394  void setSize(size_t length, const T& init_data, verify_type v_type)
395  {
396  size = length;
397  init = init_data;
398  verify = v_type;
399  }
400  size_t getSize() { return size; }
401 
402  void applyChanges(SharedObjectDataManager* manager) override
403  {
404  auto data = manager->getSharedObjectData<Data>(getName());
405  data->setSize(size, init, verify);
406  for ( auto x : changes ) {
407  data->update_write(x.first, x.second);
408  }
409  }
410 
411  void clear() override { changes.clear(); }
412  };
413  };
414 };
415 
416 /**
417  SharedArray class. The class is templated to allow for an array
418  of any non-pointer type. The type must be serializable.
419  */
420 template <>
421 class SharedArray<bool> : public SharedObject
422 {
423  // Forward declaration. Defined below
424  class Data;
425 
426 public:
427  /**
428  Default constructor for SharedArray.
429  */
430  SharedArray() : SharedObject(), published(false), data(nullptr) {}
431 
432  /**
433  Shared Array Destructor
434  */
436  {
437  // data does not need to be deleted since the
438  // SharedObjectManager owns the pointer
439  }
440 
441  /**
442  Initialize the SharedArray.
443 
444  @param obj_name Name of the object. This name is how the
445  object is uniquely identified across ranks.
446 
447  @param length Length of the array. The length can be 0 if no
448  data is going to be written by the calling element, otherwise,
449  it must be large enough to write the desired data. The final
450  length of the array will be the maximum of the requested
451  lengths. The length of the array can be queried using the
452  size() method.
453 
454  @param init_value value that entries should be initialized to.
455  By default, each array item will be initialized using the
456  default constructor for the class being stored.
457 
458  @param verify_mode Specifies how multiply written data should
459  be verified. FE_VERIFY uses a full/empty bit for each entry
460  and if a value has previously been written, it will make sure
461  the two values match. INIT_VERIFY will simply compare writes
462  against the current value and will error unless the values
463  aren't the same or the existing value is the init_value. When
464  NO_VERIFY is passed, no verification will occur. This is
465  mostly useful when you can guarantee that multiple elements
466  won't write the same value and you want to do in-place
467  modifications as you initialize. VERIFY_UNINITIALIZED is a
468  reserved value and should not be passed.
469 
470  @return returns the number of instances that have intialized
471  themselve before this instance on this MPI rank.
472  */
474  const std::string& obj_name, size_t length = 0, bool init_value = false, verify_type v_type = INIT_VERIFY)
475  {
476  if ( data ) {
477  Private::getSimulationOutput().fatal(
478  CALL_INFO, 1, "ERROR: called initialize() of SharedArray %s more than once\n", obj_name.c_str());
479  }
480 
481  if ( v_type == VERIFY_UNINITIALIZED ) {
482  Private::getSimulationOutput().fatal(
483  CALL_INFO, 1,
484  "ERROR: VERIFY_UNINITIALIZED passed into instance of SharedArray %s. "
485  "This is a reserved value and cannot be passed in here. \n",
486  obj_name.c_str());
487  }
488  data = manager.getSharedObjectData<Data>(obj_name);
489  int ret = incShareCount(data);
490  if ( length != 0 ) { data->setSize(length, init_value, v_type); }
491 
492  return ret;
493  }
494 
495  /*** Typedefs and functions to mimic parts of the vector API ***/
496 
497  typedef typename std::vector<bool>::const_iterator const_iterator;
498  typedef typename std::vector<bool>::const_reverse_iterator const_reverse_iterator;
499 
500  /**
501  Get the length of the array.
502 
503  @return length of the array
504  */
505  inline size_t size() const { return data->getSize(); }
506 
507  /**
508  Tests if array is empty.
509 
510  @return true if array is empty (size = 0), false otherwise
511  */
512  inline bool empty() const { return data->array.empty(); }
513 
514  /**
515  Get const_iterator to beginning of underlying map
516  */
517  const_iterator begin() const { return data->array.cbegin(); }
518 
519  /**
520  Get const_iterator to end of underlying map
521  */
522  const_iterator end() const { return data->array.cend(); }
523 
524  /**
525  Get const_reverse_iterator to beginning of underlying map
526  */
527  const_reverse_iterator rbegin() const { return data->array.crbegin(); }
528 
529  /**
530  Get const_reverse_iterator to end of underlying map
531  */
532  const_reverse_iterator rend() const { return data->array.crend(); }
533 
534  /**
535  Indicate that the calling element has written all the data it
536  plans to write. Writing to the array through this instance
537  after publish() is called will create an error.
538  */
539  void publish()
540  {
541  if ( published ) return;
542  published = true;
543  incPublishCount(data);
544  }
545 
546  /**
547  Check whether all instances of this SharedArray have called
548  publish(). NOTE: Is is possible that this could return true
549  one round, but false the next if a new instance of the
550  SharedArray was initialized but not published after the last
551  call.
552  */
553  bool isFullyPublished() { return data->isFullyPublished(); }
554 
555  /**
556  Write data to the array. This function is thread-safe, as a
557  mutex is used to ensure only one write at a time.
558 
559  @param index index of the write
560 
561  @param value value to be written
562  */
563  inline void write(int index, bool value)
564  {
565  if ( published ) {
566  Private::getSimulationOutput().fatal(
567  CALL_INFO, 1, "ERROR: write to SharedArray %s after publish() was called\n", data->getName().c_str());
568  }
569  return data->write(index, value);
570  }
571 
572  /**
573  Read data from the array. This returns a const reference, so
574  is read only.
575 
576  NOTE: This function does not use a mutex, so it is possible to
577  get invalid results if another thread caused a resize of the
578  underlying data structure at the same time as the read.
579  However, after the init() phase of simulation is complete (in
580  setup() and beyond), this is always a safe operation. If
581  reading during init() and you can't guarantee that all elements
582  have already written all data to the SharedArray, use
583  mutex_read() to guarantee thread safety.
584 
585  @param index index to read
586 
587  @return const reference to data at index
588  */
589  inline bool operator[](int index) const { return data->read(index); }
590 
591  /**
592  Read data from the array. This returns a const reference, so
593  is read only. This version of read is always thread safe (@see
594  operator[]).
595 
596  @param index index to read
597 
598  @return const reference to data at index
599  */
600  inline bool mutex_read(int index) const { return data->mutex_read(index); }
601 
602  void serialize_order(SST::Core::Serialization::serializer& ser) override
603  {
604  SST::Shared::SharedObject::serialize_order(ser);
605  ser& published;
606  switch ( ser.mode() ) {
607  case SST::Core::Serialization::serializer::SIZER:
608  case SST::Core::Serialization::serializer::PACK:
609  {
610  std::string name = data->getName();
611  ser& name;
612  break;
613  }
614  case SST::Core::Serialization::serializer::UNPACK:
615  {
616  std::string name;
617  ser& name;
618  data = manager.getSharedObjectData<Data>(name);
619  break;
620  }
621  };
622  }
623  ImplementSerializable(SST::Shared::SharedArray<bool>)
624 
625 private:
626  bool published;
627  Data* data;
628 
629  class Data : public SharedObjectData
630  {
631 
632  // Forward declaration. Defined below
633  class ChangeSet;
634 
635  public:
636  std::vector<bool> array;
637  std::vector<bool> written;
638  ChangeSet* change_set;
639  bool init;
640  verify_type verify;
641 
642  Data() : SharedObjectData(), change_set(nullptr), verify(VERIFY_UNINITIALIZED) {} // For serialization ONLY
643  Data(const std::string& name) : SharedObjectData(name), change_set(nullptr), verify(VERIFY_UNINITIALIZED)
644  {
645  if ( Private::getNumRanks().rank > 1 ) { change_set = new ChangeSet(name); }
646  }
647 
648  ~Data()
649  {
650  if ( change_set ) delete change_set;
651  }
652 
653  /**
654  Set the size of the array. An element can only write up to the
655  current size (reading or writing beyond the size will create
656  undefined behavior). However, an element can put in the size
657  it needs for its writes and it will end up being the largest
658  size requested. We use a vector underneatch the covers to
659  manage the memory/copying of data.
660  */
661  void setSize(size_t size, bool init_data, verify_type v_type)
662  {
663  // If the data is uninitialized, then there is nothing to do
664  if ( v_type == VERIFY_UNINITIALIZED ) return;
665  std::lock_guard<std::mutex> lock(mtx);
666  if ( size > array.size() ) {
667  // Need to resize the vector
668  array.resize(size, init_data);
669  if ( v_type == FE_VERIFY ) { written.resize(size); }
670  if ( change_set ) change_set->setSize(size, init_data, v_type);
671  }
672  // init and verify must match across all intances. We can
673  // tell that they have been when verify is not
674  // VERIFY_UNINITIALIZED.
675  if ( verify != VERIFY_UNINITIALIZED ) {
676  if ( init != init_data ) {
677  Private::getSimulationOutput().fatal(
678  CALL_INFO, 1, "ERROR: Two different init_data values passed into SharedArray %s\n",
679  name.c_str());
680  }
681 
682  if ( verify != v_type ) {
683  Private::getSimulationOutput().fatal(
684  CALL_INFO, 1, "ERROR: Two different verify types passed into SharedArray %s\n", name.c_str());
685  }
686  }
687  init = init_data;
688  verify = v_type;
689  }
690 
691  size_t getSize()
692  {
693  std::lock_guard<std::mutex> lock(mtx);
694  return array.size();
695  }
696 
697  void update_write(int index, bool data)
698  {
699  // Don't need to mutex because this is only ever called
700  // from one thread at a time, with barrier before and
701  // after, or from write(), which does mutex.
702  bool check = false;
703  switch ( verify ) {
704  case FE_VERIFY:
705  check = written[index];
706  break;
707  case INIT_VERIFY:
708  check = array[index] != init;
709  break;
710  default:
711  break;
712  }
713  if ( check && (array[index] != data) ) {
714  Private::getSimulationOutput().fatal(
715  CALL_INFO, 1, "ERROR: wrote two different values to index %d of SharedArray %s\n", index,
716  name.c_str());
717  }
718  array[index] = data;
719  if ( verify == FE_VERIFY ) written[index] = true;
720  }
721 
722  void write(int index, bool data)
723  {
724  std::lock_guard<std::mutex> lock(mtx);
725  check_lock_for_write("SharedArray");
726  update_write(index, data);
727  if ( verify == FE_VERIFY ) written[index] = true;
728  if ( change_set ) change_set->addChange(index, data);
729  }
730 
731  // Inline the read since it may be called often during run().
732  // This read is not protected from data races in the case where
733  // the array may be resized by another thread. If there is a
734  // danger of the array being resized during init, use the
735  // mutex_read function until after the init phase.
736  inline bool read(int index) const { return array[index]; }
737 
738  // Mutexed read for use if you are resizing the array as you go
739  inline bool mutex_read(int index) const
740  {
741  std::lock_guard<std::mutex> lock(mtx);
742  return array[index];
743  }
744 
745  // Functions inherited from SharedObjectData
746  virtual SharedObjectChangeSet* getChangeSet() override { return change_set; }
747  virtual void resetChangeSet() override { change_set->clear(); }
748 
749  void serialize_order(SST::Core::Serialization::serializer& ser) override
750  {
751  SharedObjectData::serialize_order(ser);
752  ser& array;
753  // All other members are not needed past init()
754  }
755 
756  ImplementSerializable(SST::Shared::SharedArray<bool>::Data);
757 
758  private:
759  class ChangeSet : public SharedObjectChangeSet
760  {
761 
762  std::vector<std::pair<int, bool>> changes;
763  size_t size;
764  bool init;
765  verify_type verify;
766 
767  void serialize_order(SST::Core::Serialization::serializer& ser) override
768  {
769  SharedObjectChangeSet::serialize_order(ser);
770  ser& changes;
771  ser& size;
772  ser& init;
773  ser& verify;
774  }
775 
777 
778  public:
779  // For serialization
780  ChangeSet() : SharedObjectChangeSet() {}
781  ChangeSet(const std::string& name) : SharedObjectChangeSet(name), size(0), verify(VERIFY_UNINITIALIZED) {}
782 
783  void addChange(int index, bool value) { changes.emplace_back(index, value); }
784 
785  void setSize(size_t length, bool init_data, verify_type v_type)
786  {
787  size = length;
788  init = init_data;
789  verify = v_type;
790  }
791  size_t getSize() { return size; }
792 
793  void applyChanges(SharedObjectDataManager* manager) override
794  {
795  auto data = manager->getSharedObjectData<Data>(getName());
796  data->setSize(size, init, verify);
797  for ( auto x : changes ) {
798  data->update_write(x.first, x.second);
799  }
800  }
801 
802  void clear() override { changes.clear(); }
803  };
804  };
805 };
806 } // namespace Shared
807 } // namespace SST
808 
809 #endif // SST_CORE_SHARED_SHAREDARRAY_H
size_t size() const
Get the length of the array.
Definition: sharedArray.h:505
virtual SharedObjectChangeSet * getChangeSet() override
Gets the changeset for this data on this rank.
Definition: sharedArray.h:356
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
virtual SharedObjectChangeSet * getChangeSet() override
Gets the changeset for this data on this rank.
Definition: sharedArray.h:746
Definition: sharedObject.h:269
const_reverse_iterator rbegin() const
Get const_reverse_iterator to beginning of underlying map.
Definition: sharedArray.h:136
const T & operator[](int index) const
Read data from the array.
Definition: sharedArray.h:198
const_iterator begin() const
Get const_iterator to beginning of underlying map.
Definition: sharedArray.h:517
virtual void resetChangeSet() override
Resets the changeset for this data on this rank.
Definition: sharedArray.h:747
void lock()
Called by the core when writing to shared regions is no longer allowed.
Definition: sharedObject.h:186
bool isFullyPublished()
Checks to see if all instances of this SharedObject have called publish().
Definition: sharedObject.h:109
void publish()
Indicate that the calling element has written all the data it plans to write.
Definition: sharedArray.h:148
size_t size() const
Get the length of the array.
Definition: sharedArray.h:114
SharedArray()
Default constructor for SharedArray.
Definition: sharedArray.h:430
Definition: action.cc:18
const_reverse_iterator rend() const
Get const_reverse_iterator to end of underlying map.
Definition: sharedArray.h:141
bool empty() const
Tests if array is empty.
Definition: sharedArray.h:512
verify_type
Enum of verify types.
Definition: sharedObject.h:276
bool empty() const
Tests if array is empty.
Definition: sharedArray.h:121
SharedArray class.
Definition: sharedArray.h:421
void write(int index, const T &value)
Write data to the array.
Definition: sharedArray.h:172
int initialize(const std::string &obj_name, size_t length=0, bool init_value=false, verify_type v_type=INIT_VERIFY)
Initialize the SharedArray.
Definition: sharedArray.h:473
const_iterator begin() const
Get const_iterator to beginning of underlying map.
Definition: sharedArray.h:126
void write(int index, bool value)
Write data to the array.
Definition: sharedArray.h:563
bool isFullyPublished()
Check whether all instances of this SharedArray have called publish().
Definition: sharedArray.h:162
void setSize(size_t size, bool init_data, verify_type v_type)
Set the size of the array.
Definition: sharedArray.h:661
virtual void resetChangeSet() override
Resets the changeset for this data on this rank.
Definition: sharedArray.h:357
const_reverse_iterator rend() const
Get const_reverse_iterator to end of underlying map.
Definition: sharedArray.h:532
bool mutex_read(int index) const
Read data from the array.
Definition: sharedArray.h:600
SharedArray()
Default constructor for SharedArray.
Definition: sharedArray.h:40
const_reverse_iterator rbegin() const
Get const_reverse_iterator to beginning of underlying map.
Definition: sharedArray.h:527
void publish()
Indicate that the calling element has written all the data it plans to write.
Definition: sharedArray.h:539
const_iterator end() const
Get const_iterator to end of underlying map.
Definition: sharedArray.h:522
SharedArray class.
Definition: sharedArray.h:29
Definition: sharedArray.h:238
~SharedArray()
Shared Array Destructor.
Definition: sharedArray.h:435
~SharedArray()
Shared Array Destructor.
Definition: sharedArray.h:45
int initialize(const std::string &obj_name, size_t length=0, T init_value=T(), verify_type v_type=INIT_VERIFY)
Initialize the SharedArray.
Definition: sharedArray.h:83
const std::string & getName()
Get the name of the SharedObject for this data.
Definition: sharedObject.h:99
virtual void applyChanges(SharedObjectDataManager *UNUSED(manager))=0
Apply the changes to the name shared data.
This is the base class for holding data on changes made to the shared data on each rank...
Definition: sharedObject.h:44
const T & mutex_read(int index) const
Read data from the array.
Definition: sharedArray.h:209
const_iterator end() const
Get const_iterator to end of underlying map.
Definition: sharedArray.h:131
Base class for holding SharedObject data.
Definition: sharedObject.h:87
bool isFullyPublished()
Check whether all instances of this SharedArray have called publish().
Definition: sharedArray.h:553
bool operator[](int index) const
Read data from the array.
Definition: sharedArray.h:589
void setSize(size_t size, const T &init_data, verify_type v_type)
Set the size of the array.
Definition: sharedArray.h:270