DASH  0.3.0
dash::Coevent Class Reference

A fortran style coevent. More...

#include <Coevent.h>

Public Types

using iterator = coarray::CoEventIter
 
using const_iterator = coarray::CoEventIter
 
using reference = coarray::CoEventRef
 
using size_type = int
 

Public Member Functions

 Coevent (Team &team=dash::Team::All())
 Constructor to setup and initialize an Coevent. More...
 
iterator begin () DASH_NOEXCEPT
 
const_iterator begin () const DASH_NOEXCEPT
 
iterator end ()
 
const_iterator end () const
 
size_type size () const
 
void wait (int count=1)
 wait for a given number of incoming events. More...
 
int test ()
 
void initialize (Team &team=dash::Team::All())
 initializes the Coevent. More...
 
Teamteam ()
 
reference operator() (const int &unit)
 Operator to select event at given unit. More...
 
reference operator() (const team_unit_t &unit)
 Operator to select event at given unit. More...
 

Detailed Description

A fortran style coevent.

Coevent can be used for point-to-point synchronization. Events can be posted to any image. Waiting on non-local events is not supported.

Note
Coevents might deadlock if multiple units are pinned to the same cpu-core. This is due to progress problems in MPI.

Example:

Coevent events;
events(2).post();
if(this_image() == 2){
events.wait();
}

Definition at line 45 of file Coevent.h.

Constructor & Destructor Documentation

◆ Coevent()

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

Constructor to setup and initialize an Coevent.

Definition at line 66 of file Coevent.h.

References dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::begin(), dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::end(), initialize(), dash::is_initialized(), and dash::Team::size().

67  : _team(&team) {
69  initialize(team);
70  }
71  }
bool is_initialized()
Check whether DASH has been initialized already.
void initialize(Team &team=dash::Team::All())
initializes the Coevent.
Definition: Coevent.h:138

Member Function Documentation

◆ initialize()

void dash::Coevent::initialize ( Team team = dash::Team::All())
inline

initializes the Coevent.

If it was already initialized in the Ctor, the second initialization is skipped.

Definition at line 138 of file Coevent.h.

References dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::allocate(), dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::barrier(), dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::begin(), dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::end(), dash::fill(), and dash::Team::size().

Referenced by Coevent().

138  {
139  if(!_is_initialized){
140  _team = &team;
141  _event_counts.allocate(_team->size());
142  dash::fill(_event_counts.begin(), _event_counts.end(), 0);
143  _event_counts.barrier();
144  _is_initialized = true;
145  }
146  }
iterator end() noexcept
Global pointer to the end of the array.
Definition: Array.h:1057
void fill(GlobIterType first, GlobIterType last, const typename GlobIterType::value_type &value)
Assigns the given value to the elements in the range [first, last)
Definition: Fill.h:35
size_t size() const
The number of units in this team.
Definition: Team.h:498
void barrier() const
Establish a barrier for all units operating on the array, publishing all changes to all units...
Definition: Array.h:1254
iterator begin() noexcept
Global pointer to the beginning of the array.
Definition: Array.h:1040
bool allocate(size_type nelem, dash::DistributionSpec< 1 > distribution, dash::Team &team=dash::Team::All())
Delayed allocation of global memory using a one-dimensional distribution spec.
Definition: Array.h:1319

◆ operator()() [1/2]

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

Operator to select event at given unit.

Definition at line 155 of file Coevent.h.

155  {
156  DASH_ASSERT_MSG(dash::is_initialized(), "DASH is not initialized");
157  auto ptr = static_cast<pointer>(_event_counts.begin() + unit);
158  return reference(ptr);
159  }
bool is_initialized()
Check whether DASH has been initialized already.
iterator begin() noexcept
Global pointer to the beginning of the array.
Definition: Array.h:1040

◆ operator()() [2/2]

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

Operator to select event at given unit.

Definition at line 164 of file Coevent.h.

164  {
165  return this->operator()(static_cast<int>(unit));
166  }
reference operator()(const int &unit)
Operator to select event at given unit.
Definition: Coevent.h:155

◆ wait()

void dash::Coevent::wait ( int  count = 1)
inline

wait for a given number of incoming events.

This function is thread-safe

Definition at line 112 of file Coevent.h.

References dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::at(), and dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::begin().

112  {
113  auto gref = _event_counts.at(_team->myid().id);
114  int current;
115  do {
116 #ifdef DASH_DEBUG
117  // avoid spamming the logs while busy waiting
118  DASH_LOG_DEBUG("waiting for event at gptr",
119  static_cast<pointer>(_event_counts.begin()
120  +_team->myid().id));
121  std::this_thread::sleep_for(std::chrono::milliseconds(100));
122 #endif
123  current = gref.get();
124  } while (current < count);
125  // decrement the counter
126  gref.sub(count);
127  }
reference at(size_type global_pos)
Random access assignment operator, range-checked.
Definition: Array.h:1132
iterator begin() noexcept
Global pointer to the beginning of the array.
Definition: Array.h:1040

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