SST 12.1.0
Structural Simulation Toolkit
SST::Shared::SharedArray< T > Class Template Reference

SharedArray class. More...

#include <sharedArray.h>

Inheritance diagram for SST::Shared::SharedArray< T >:
SST::Shared::SharedObject

Public Types

typedef std::vector< T >::const_iterator const_iterator
 
typedef std::vector< T >::const_reverse_iterator const_reverse_iterator
 
- Public Types inherited from SST::Shared::SharedObject
enum  verify_type { VERIFY_UNINITIALIZED , FE_VERIFY , INIT_VERIFY , NO_VERIFY }
 Enum of verify types.
 

Public Member Functions

 SharedArray ()
 Default constructor for SharedArray.
 
 ~SharedArray ()
 Shared Array Destructor.
 
int initialize (const std::string &obj_name, size_t length=0, T init_value=T(), verify_type v_type=INIT_VERIFY)
 Initialize the SharedArray. More...
 
size_t size () const
 Get the length of the array. More...
 
bool empty () const
 Tests if array is empty. More...
 
const_iterator begin () const
 Get const_iterator to beginning of underlying map.
 
const_iterator end () const
 Get const_iterator to end of underlying map.
 
const_reverse_iterator rbegin () const
 Get const_reverse_iterator to beginning of underlying map.
 
const_reverse_iterator rend () const
 Get const_reverse_iterator to end of underlying map.
 
void publish ()
 Indicate that the calling element has written all the data it plans to write. More...
 
bool isFullyPublished ()
 Check whether all instances of this SharedArray have called publish(). More...
 
void write (int index, const T &value)
 Write data to the array. More...
 
const T & operator[] (int index) const
 Read data from the array. More...
 
const T & mutex_read (int index) const
 Read data from the array. More...
 

Additional Inherited Members

- Protected Member Functions inherited from SST::Shared::SharedObject
void incPublishCount (SharedObjectData *data)
 
int incShareCount (SharedObjectData *data)
 
- Static Protected Attributes inherited from SST::Shared::SharedObject
static SharedObjectDataManager manager
 

Detailed Description

template<typename T>
class SST::Shared::SharedArray< T >

SharedArray class.

The class is templated to allow for an array of any non-pointer type. The type must be serializable.

Member Function Documentation

◆ empty()

template<typename T >
bool SST::Shared::SharedArray< T >::empty ( ) const
inline

Tests if array is empty.

Returns
true if array is empty (size = 0), false otherwise

◆ initialize()

template<typename T >
int SST::Shared::SharedArray< T >::initialize ( const std::string &  obj_name,
size_t  length = 0,
init_value = T(),
verify_type  v_type = INIT_VERIFY 
)
inline

Initialize the SharedArray.

Parameters
obj_nameName of the object. This name is how the object is uniquely identified across ranks.
lengthLength of the array. The length can be 0 if no data is going to be written by the calling element, otherwise, it must be large enough to write the desired data. The final length of the array will be the maximum of the requested lengths. The length of the array can be queried using the size() method.
init_valuevalue that entries should be initialized to. By default, each array item will be initialized using the default constructor for the class being stored.
verify_modeSpecifies how multiply written data should be verified. FE_VERIFY uses a full/empty bit for each entry and if a value has previously been written, it will make sure the two values match. INIT_VERIFY will simply compare writes against the current value and will error unless the values aren't the same or the existing value is the init_value. When NO_VERIFY is passed, no verification will occur. This is mostly useful when you can guarantee that multiple elements won't write the same value and you want to do in-place modifications as you initialize. VERIFY_UNINITIALIZED is a reserved value and should not be passed.
Returns
returns the number of instances that have intialized themselve before this instance on this MPI rank.

◆ isFullyPublished()

template<typename T >
bool SST::Shared::SharedArray< T >::isFullyPublished ( )
inline

Check whether all instances of this SharedArray have called publish().

NOTE: Is is possible that this could return true one round, but false the next if a new instance of the SharedArray was initialized but not published after the last call.

◆ mutex_read()

template<typename T >
const T & SST::Shared::SharedArray< T >::mutex_read ( int  index) const
inline

Read data from the array.

This returns a const reference, so is read only. This version of read is always thread safe (

See also
operator[]).
Parameters
indexindex to read
Returns
const reference to data at index

◆ operator[]()

template<typename T >
const T & SST::Shared::SharedArray< T >::operator[] ( int  index) const
inline

Read data from the array.

This returns a const reference, so is read only.

NOTE: This function does not use a mutex, so it is possible to get invalid results if another thread caused a resize of the underlying data structure at the same time as the read. However, after the init() phase of simulation is complete (in setup() and beyond), this is always a safe operation. If reading during init() and you can't guarantee that all elements have already written all data to the SharedArray, use mutex_read() to guarantee thread safety.

Parameters
indexindex to read
Returns
const reference to data at index

◆ publish()

template<typename T >
void SST::Shared::SharedArray< T >::publish ( )
inline

Indicate that the calling element has written all the data it plans to write.

Writing to the array through this instance after publish() is called will create an error.

◆ size()

template<typename T >
size_t SST::Shared::SharedArray< T >::size ( ) const
inline

Get the length of the array.

Returns
length of the array

◆ write()

template<typename T >
void SST::Shared::SharedArray< T >::write ( int  index,
const T &  value 
)
inline

Write data to the array.

This function is thread-safe, as a mutex is used to ensure only one write at a time.

Parameters
indexindex of the write
valuevalue to be written

The documentation for this class was generated from the following file: