DASH  0.3.0
dash::Comutex Class Reference

A fortran style comutex. More...

#include <Comutex.h>

Public Types

using iterator = typename _storage_type::iterator
 
using const_iterator = typename _storage_type::const_iterator
 
using reference = typename _storage_type::reference
 
using size_type = typename _storage_type::size_type
 

Public Member Functions

 Comutex (Team &team=dash::Team::All())
 Constructor to setup and initialize an Comutex. More...
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
size_type size () const noexcept
 
void initialize (Team &team)
 initializeds the mutexes. More...
 
Teamteam ()
 
reference operator() (const int &unit)
 Operator to select mutex at given unit. More...
 
reference operator() (const team_unit_t &unit)
 Operator to select mutex at given unit. More...
 

Detailed Description

A fortran style comutex.

Comutex is used to ensure mutual exclusion on a certain image. The interface is similar to dash::Coarray but does not allow local accesses. Hence it does not fulfill the DASH Container Concept.

Note
In its current implementation the Comutex does not scale well as each unit stores internally one ::mutex per unit. Hence, use this only for small teams.

Example:

Coarray<int> arr;
Comutex comx;
{
// lock unit i
std::lock_guard<dash::Mutex> lg(comx(i));
// exclusively access data on unti i
arr(i) = 42;
}

: Use custom mutex to avoid storing the team multiple times (Each dash::Mutex) contains the team itself.

Definition at line 46 of file Comutex.h.

Constructor & Destructor Documentation

◆ Comutex()

dash::Comutex::Comutex ( Team team = dash::Team::All())
inlineexplicit

Constructor to setup and initialize an Comutex.

If dash is not initialized, use () after dash is initialized to initialize the Comutex

Definition at line 62 of file Comutex.h.

References initialize(), and dash::is_initialized().

62  {
64  initialize(team);
65  }
66  }
bool is_initialized()
Check whether DASH has been initialized already.
void initialize(Team &team)
initializeds the mutexes.
Definition: Comutex.h:92

Member Function Documentation

◆ initialize()

void dash::Comutex::initialize ( Team team)
inline

initializeds the mutexes.

If they were already initialized in the Ctor, the second initialization is skipped.

Definition at line 92 of file Comutex.h.

References dash::Team::size().

Referenced by Comutex().

92  {
93  if(!_is_initialized){
94  _team = &team;
95  _mutexes.reserve(team.size());
96  for(decltype(team.size()) i = 0; i<team.size(); ++i){
97  _mutexes.emplace_back(team);
98  }
99  } else {
100  DASH_ASSERT_MSG((team == *_team),
101  "Comutex was initialized with a different team");
102  }
103  _is_initialized = true;
104  }
size_t size() const
The number of units in this team.
Definition: Team.h:498

◆ operator()() [1/2]

reference dash::Comutex::operator() ( const int &  unit)
inline

Operator to select mutex at given unit.

Definition at line 113 of file Comutex.h.

113  {
114  DASH_ASSERT_MSG(_is_initialized, "Comutex is not initialized");
115  return _mutexes.at(unit);
116  }

◆ operator()() [2/2]

reference dash::Comutex::operator() ( const team_unit_t unit)
inline

Operator to select mutex at given unit.

Definition at line 121 of file Comutex.h.

121  {
122  return this->operator()(static_cast<int>(unit));
123  }
reference operator()(const int &unit)
Operator to select mutex at given unit.
Definition: Comutex.h:113

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