SST  13.1.0
Structural Simulation Toolkit
SST::Shared::SharedMap< keyT, valT > Class Template Reference

SharedMap class. More...

#include <sharedMap.h>

Inheritance diagram for SST::Shared::SharedMap< keyT, valT >:
SST::Shared::SharedObject

Public Types

typedef std::map< keyT, valT >::const_iterator const_iterator
 
typedef std::map< keyT, valT >::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

int initialize (const std::string &obj_name, verify_type v_type=FE_VERIFY)
 Initialize the SharedMap. More...
 
size_t size () const
 Get the size of the map. More...
 
bool empty () const
 Tests if the map is empty. More...
 
size_t count (const keyT &k) const
 Counts elements with a specific key. More...
 
const_iterator find (const keyT &key) const
 Searches the container for an element with a key equivalent to k and returns an iterator to it if found, otherwise it returns an iterator to SharedMap::end(). 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.
 
const_iterator lower_bound (const keyT &key) const
 Returns an iterator pointing to the first element in the container whose key is not considered to go before k (i.e., either it is equivalent or goes after). More...
 
const_iterator upper_bound (const keyT &key) const
 Returns an iterator pointing to the first element in the container whose key is considered to go after k. More...
 
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 SharedMap have called publish(). More...
 
void write (const keyT &key, const valT &value)
 Write data to the map. More...
 
const valT & operator[] (const keyT &key) const
 Read data from the map. More...
 
const valT & mutex_read (const keyT &key) const
 Read data from the map. 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 keyT, typename valT>
class SST::Shared::SharedMap< keyT, valT >

SharedMap class.

The class is templated to allow for Map of any non-pointer type as value. The type must be serializable.

Member Function Documentation

◆ count()

template<typename keyT , typename valT >
size_t SST::Shared::SharedMap< keyT, valT >::count ( const keyT &  k) const
inline

Counts elements with a specific key.

Becuase this is not a multimap, it will either return 1 or 0.

Returns
Count of elements with specified key

◆ empty()

template<typename keyT , typename valT >
bool SST::Shared::SharedMap< keyT, valT >::empty ( ) const
inline

Tests if the map is empty.

Returns
true if map is empty, false otherwise

◆ find()

template<typename keyT , typename valT >
const_iterator SST::Shared::SharedMap< keyT, valT >::find ( const keyT &  key) const
inline

Searches the container for an element with a key equivalent to k and returns an iterator to it if found, otherwise it returns an iterator to SharedMap::end().

Parameters
keykey to search for

◆ initialize()

template<typename keyT , typename valT >
int SST::Shared::SharedMap< keyT, valT >::initialize ( const std::string &  obj_name,
verify_type  v_type = FE_VERIFY 
)
inline

Initialize the SharedMap.

Parameters
obj_nameName of the object. This name is how the object is uniquely identified across ranks.
verify_modeSpecifies how multiply written data should be verified. Since the underlying map knows if the data has already been written, FE_VERIFY and INIT_VERIFY simply use this built-in mechanism to know when an item has previously been written. When these modes are enabled, multiply written data must match what was written before. 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 keyT , typename valT >
bool SST::Shared::SharedMap< keyT, valT >::isFullyPublished ( )
inline

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

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

◆ lower_bound()

template<typename keyT , typename valT >
const_iterator SST::Shared::SharedMap< keyT, valT >::lower_bound ( const keyT &  key) const
inline

Returns an iterator pointing to the first element in the container whose key is not considered to go before k (i.e., either it is equivalent or goes after).

Parameters
keykey to compare to

◆ mutex_read()

template<typename keyT , typename valT >
const valT& SST::Shared::SharedMap< keyT, valT >::mutex_read ( const keyT &  key) const
inline

Read data from the map.

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

See also
operator[]). If the key is not in the map, an out_of_range exception will be thrown.
Parameters
keykey to read
Returns
const reference to data at index
Exceptions
std::out_of_rangekey is not found in map

◆ operator[]()

template<typename keyT , typename valT >
const valT& SST::Shared::SharedMap< keyT, valT >::operator[] ( const keyT &  key) const
inline

Read data from the map.

This returns a const reference, so is read only. If the key is not in the map, an out_of_range exception will be thrown.

NOTE: This function does not use a mutex, so it is possible to get invalid results if another thread is simulateously writing to the map. 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 elements to the SharedMap, use mutex_read() to guarantee thread safety.

Parameters
keykey to read
Returns
const reference to data referenced by key
Exceptions
std::out_of_rangekey is not found in map

◆ publish()

template<typename keyT , typename valT >
void SST::Shared::SharedMap< keyT, valT >::publish ( )
inline

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

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

◆ size()

template<typename keyT , typename valT >
size_t SST::Shared::SharedMap< keyT, valT >::size ( ) const
inline

Get the size of the map.

Returns
size of the map

◆ upper_bound()

template<typename keyT , typename valT >
const_iterator SST::Shared::SharedMap< keyT, valT >::upper_bound ( const keyT &  key) const
inline

Returns an iterator pointing to the first element in the container whose key is considered to go after k.

Parameters
keykey to compare to

◆ write()

template<typename keyT , typename valT >
void SST::Shared::SharedMap< keyT, valT >::write ( const keyT &  key,
const valT &  value 
)
inline

Write data to the map.

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

Parameters
keykey of the write
valuevalue to be written

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