DASH  0.3.0
Coarray Runtime Interface

Functions of the dash::coarray extension to provide an interface similar to CAF 2008. More...

Collaboration diagram for Coarray Runtime Interface:

Functions

dash::global_unit_t dash::coarray::this_image ()
 Shortcut to query the global unit ID of the calling unit. More...
 
ssize_t dash::coarray::num_images ()
 Return the number of units in the global team. More...
 
void dash::coarray::sync_all ()
 blocks until all units reach this statement. More...
 
template<typename Container >
void dash::coarray::sync_images (const Container &image_ids)
 Blocks until all selected units reach this statement. More...
 
template<typename T >
void dash::coarray::cobroadcast (Coarray< T > &coarr, const team_unit_t &master)
 Broadcasts the value on master to all other members of this co_array. More...
 
template<typename T , typename BinaryOp >
void dash::coarray::coreduce (Coarray< T > &coarr, const BinaryOp &op, team_unit_t master=team_unit_t{-1})
 Performes a broadside reduction of the Coarray images. More...
 

Detailed Description

Functions of the dash::coarray extension to provide an interface similar to CAF 2008.

Function Documentation

◆ cobroadcast()

template<typename T >
void dash::coarray::cobroadcast ( Coarray< T > &  coarr,
const team_unit_t master 
)

#include </tmp/tmporruphar/dash/include/dash/coarray/Utils.h>

Broadcasts the value on master to all other members of this co_array.

Note
fortran defines this function only for scalar Coarray. This implementation allows you to broadcast arrays as well
Parameters
coarrcoarray which should be broadcasted
masterthe value of this unit will be broadcastet

Definition at line 142 of file Utils.h.

References dart_bcast(), and DART_OK.

Referenced by dash::broadcast().

142  {
143  using value_type = typename Coarray<T>::value_type;
144  const dash::dart_storage<value_type> ds(coarr.local_size());
145  DASH_ASSERT_RETURNS(
146  dart_bcast(coarr.lbegin(),
147  ds.nelem,
148  ds.dtype,
149  master,
150  coarr.team().dart_id()),
151  DART_OK);
152 }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_bcast(void *buf, size_t nelem, dart_datatype_t dtype, dart_team_unit_t root, dart_team_t team)
DART Equivalent to MPI broadcast.
Convencience wrapper to determine the DART type and number of elements required for the given templat...
Definition: Types.h:295

◆ coreduce()

template<typename T , typename BinaryOp >
void dash::coarray::coreduce ( Coarray< T > &  coarr,
const BinaryOp &  op,
team_unit_t  master = team_unit_t{-1} 
)

#include </tmp/tmporruphar/dash/include/dash/coarray/Utils.h>

Performes a broadside reduction of the Coarray images.

Parameters
coarrperform the reduction on this array
opone of the DASH Reduce Operations
masterunit which recieves the result. -1 to broadcast to all units

Definition at line 163 of file Utils.h.

165  {-1})
166 {
167  using value_type = typename Coarray<T>::value_type;
168  using index_type = typename Coarray<T>::index_type;
169 
170  static_assert(dash::dart_datatype<value_type>::value != DART_TYPE_UNDEFINED,
171  "Cannot reduce unknown type!");
172 
173  constexpr auto ndim = Coarray<T>::ndim();
174  const auto team_dart_id = coarr.team().dart_id();
175  bool broadcast_result = (master < 0);
176  if(master < 0){master = team_unit_t{0};}
177 
178  // position of first element on master
179  const auto & global_coords = coarr.pattern().global(master,
180  std::array<index_type,ndim> {});
181  const auto & global_idx = coarr.pattern().at(global_coords);
182 
183  const auto dart_gptr = (coarr.begin() + global_idx).dart_gptr();
184  const dash::dart_storage<value_type> ds(coarr.local_size());
185 
186  // as source and destination location is equal, master must not contribute
187  // in accumulation as otherwise it's value is counted twice
188  if(coarr.team().myid() != master){
189  DASH_ASSERT_RETURNS(
191  dart_gptr,
192  coarr.lbegin(),
193  ds.nelem,
194  ds.dtype,
195  op.dart_operation()
196  ),
197  DART_OK);
198  }
199  if(broadcast_result){
200  dart_flush(dart_gptr);
201  dart_barrier(team_dart_id);
202  DASH_ASSERT_RETURNS(
203  dart_bcast(coarr.lbegin(),
204  ds.nelem,
205  ds.dtype,
206  master,
207  team_dart_id),
208  DART_OK);
209  }
210 }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_bcast(void *buf, size_t nelem, dart_datatype_t dtype, dart_team_unit_t root, dart_team_t team)
DART Equivalent to MPI broadcast.
dart_ret_t dart_accumulate(dart_gptr_t gptr, const void *values, size_t nelem, dart_datatype_t dtype, dart_operation_t op)
Perform an element-wise atomic update on the values pointed to by gptr by applying the operation op w...
constexpr dim_t ndim(const DimensionalType &d)
Definition: Dimensional.h:56
dart_ret_t dart_barrier(dart_team_t team)
DART Equivalent to MPI_Barrier.
Type trait for mapping to DART data types.
Definition: Types.h:96
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
Definition: Types.h:319
void op(const dash::GlobRef< dash::Atomic< T >> &ref, const BinaryOp binary_op, const T &value)
Atomically executes specified operation on the referenced shared value.
Definition: Operation.h:80
Convencience wrapper to determine the DART type and number of elements required for the given templat...
Definition: Types.h:295
dart_ret_t dart_flush(dart_gptr_t gptr)
Guarantee completion of all outstanding operations involving a segment on a certain unit...

◆ num_images()

ssize_t dash::coarray::num_images ( )
inline

#include </tmp/tmporruphar/dash/include/dash/coarray/Utils.h>

Return the number of units in the global team.

Returns
The number of units available. -1 if DASH is not initialized (anymore).
See also
dash::size()

Definition at line 43 of file Utils.h.

References dash::size().

43  {
44  return dash::size();
45 }
size_t size()
Return the number of units in the global team.

◆ sync_all()

void dash::coarray::sync_all ( )
inline

#include </tmp/tmporruphar/dash/include/dash/coarray/Utils.h>

blocks until all units reach this statement.

This statement does not imply a flush. If a flush is required, use the corresponding dash::Coarray::sync_all() method of Coarray.

See also
dash::coarray::sync_images()

Definition at line 56 of file Utils.h.

References dash::barrier().

56  {
57  dash::barrier();
58 }
void barrier()
A global barrier involving all units.

◆ sync_images()

template<typename Container >
void dash::coarray::sync_images ( const Container &  image_ids)
inline

#include </tmp/tmporruphar/dash/include/dash/coarray/Utils.h>

Blocks until all selected units reach this statement.

This statement does not imply a flush. If a flush is required, use the sync_all() method of the Coarray

Note
If possible use sync_all() or Coevent for performance reasons. sync_images() is implemented using two-sided operations based on a implementation of MPI_Barrier(). For dispatching the messages we use tag DART_TAG_SYNC_IMAGES
See also
dash::coarray::sync_all()

Definition at line 75 of file Utils.h.

References dart_recv(), dart_send(), DART_TYPE_BYTE, dash::find(), dash::for_each(), dash::myid(), and dash::coarray::this_image().

Referenced by dash::Coarray< T, IndexType, Arrangement, LocalMemSpaceT >::sync_images().

75  {
76  using element = typename Container::value_type;
77 
78  auto myid = this_image();
79 
80  if(std::find(image_ids.begin(),
81  image_ids.end(),
82  static_cast<element>(myid)) == image_ids.end())
83  {
84  // I do not participate
85  return;
86  }
87 
88  auto root = global_unit_t{
89  *(std::min(image_ids.begin(), image_ids.end()))};
90  auto tag = DART_TAG_SYNC_IMAGES;
91  // DART does not specify if nullptr is allowed as target
92  char buffer = 0;
93 
94  if(myid == root){
95  // I am root, recv messages from leaves
96  std::for_each(image_ids.begin(), image_ids.end(), [&](const element & el){
97  if(el != root){
98  dart_recv(&buffer, 1, dart_datatype<char>::value,
99  tag,
100  global_unit_t{el}
101  );
102  }
103  });
104  } else {
105  // I am a leave, send message to root
106  dart_send(&buffer, 1, DART_TYPE_BYTE,
107  tag,
108  global_unit_t{root});
109  }
110 
111  // Second phase: recieve message from root
112  DASH_LOG_DEBUG("Begin second phase of sync_images");
113  if(myid == root){
114  std::for_each(image_ids.begin(), image_ids.end(), [&](const element & el)
115  {
116  if(el != root){
117  dart_send(&buffer, 1, dart_datatype<char>::value,
118  tag,
119  global_unit_t{el}
120  );
121  }
122  });
123  } else {
124  dart_recv(&buffer, 1, dart_datatype<char>::value,
125  tag,
126  global_unit_t{root}
127  );
128  }
129 }
dart_ret_t dart_send(const void *sendbuf, size_t nelem, dart_datatype_t dtype, int tag, dart_global_unit_t unit)
DART Equivalent to MPI send.
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
struct dash::unit_id< dash::global_unit, dart_global_unit_t > global_unit_t
Unit ID to use for global IDs.
Definition: Types.h:332
dash::global_unit_t this_image()
Shortcut to query the global unit ID of the calling unit.
Definition: Utils.h:29
#define DART_TYPE_BYTE
integral data types
Definition: dart_types.h:125
dart_ret_t dart_recv(void *recvbuf, size_t nelem, dart_datatype_t dtype, int tag, dart_global_unit_t unit)
DART Equivalent to MPI recv.
GlobIter find(GlobIter first, GlobIter last, const ElementType &value)
Returns an iterator to the first element in the range [first,last) that compares equal to val...
Definition: Find.h:22
void for_each(const GlobInputIt &first, const GlobInputIt &last, UnaryFunction func)
Invoke a function on every element in a range distributed by a pattern.
Definition: ForEach.h:32

◆ this_image()

dash::global_unit_t dash::coarray::this_image ( )
inline

#include </tmp/tmporruphar/dash/include/dash/coarray/Utils.h>

Shortcut to query the global unit ID of the calling unit.

Returns
The unit ID of the calling unit relative to dash::Team::All
See also
dash::myid()

Definition at line 29 of file Utils.h.

References dash::myid().

Referenced by dash::coarray::sync_images().

29  {
30  return dash::myid();
31 }
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.