DASH  0.3.0
Algorithms operating on DASH containers

Functions

template<typename GlobIter , typename UnaryPredicate >
bool dash::all_of (GlobIter first, GlobIter last, UnaryPredicate p)
 Check whether all element in the range satisfy predicate p. More...
 
template<typename GlobIter , typename UnaryPredicate >
bool dash::any_of (GlobIter first, GlobIter last, UnaryPredicate p)
 Check whether any element in the range satisfies predicate p. More...
 
template<class LocalInputIter , typename = typename std::enable_if< !dash::detail::is_global_iterator<LocalInputIter>::value >::type>
void dash::broadcast (LocalInputIter in_first, LocalInputIter in_last, dash::team_unit_t root, dash::Team &team=dash::Team::All())
 Broadcast the local range of elements [in_first, in_last) from unit root to all other units in team. More...
 
template<class ValueType >
ValueType dash::broadcast (dash::Shared< ValueType > &shared)
 Broadcast the value stored in dash::Shared from the unit owning the value to all other units with access to the shared object. More...
 
template<typename T >
void dash::broadcast (Coarray< T > &coarr, const team_unit_t &root)
 Broadcasts the value on root to all other members of this co_array. More...
 
template<typename ValueType , class InputIt , class OutputIt >
OutputIt dash::copy (InputIt in_first, InputIt in_last, OutputIt out_first)
 Copies the elements in the range, defined by [in_first, in_last), to another range beginning at out_first. More...
 
template<typename ValueType , class GlobInputIt >
dash::Future< ValueType * > dash::copy_async (InputIt in_first, InputIt in_last, OutputIt out_first)
 Asynchronous variant of dash::copy. More...
 
template<typename GlobIter >
bool dash::equal (GlobIter first_1, GlobIter last_1, GlobIter first_2)
 Returns true if the range [first1, last1) is equal to the range [first2, first2 + (last1 - first1)), and false otherwise. More...
 
template<typename GlobIter , class BinaryPredicate >
bool dash::equal (GlobIter first_1, GlobIter last_1, GlobIter first_2, BinaryPredicate)
 Returns true if the range [first1, last1) is equal to the range [first2, first2 + (last1 - first1)) with respect to a specified predicate, and false otherwise. More...
 
template<typename GlobIterType >
void dash::fill (GlobIterType first, GlobIterType last, const typename GlobIterType::value_type &value)
 Assigns the given value to the elements in the range [first, last) More...
 
template<typename GlobIter , typename ElementType >
GlobIter dash::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. More...
 
template<typename GlobIter , typename UnaryPredicate >
GlobIter dash::find_if (GlobIter first, GlobIter last, UnaryPredicate predicate)
 Returns an iterator to the first element in the range [first,last) that satisfies the predicate p. More...
 
template<typename GlobIter , class UnaryPredicate >
GlobIter dash::find_if_not (GlobIter first, GlobIter last, UnaryPredicate predicate)
 Returns an iterator to the first element in the range [first,last) that does not satisfy the predicate p. More...
 
template<typename GlobInputIt , class UnaryFunction >
void dash::for_each (const GlobInputIt &first, const GlobInputIt &last, UnaryFunction func)
 Invoke a function on every element in a range distributed by a pattern. More...
 
template<typename GlobInputIt , class UnaryFunctionWithIndex >
void dash::for_each_with_index (const GlobInputIt &first, const GlobInputIt &last, UnaryFunctionWithIndex func)
 Invoke a function on every element in a range distributed by a pattern. More...
 
template<typename GlobInputIt , class UnaryFunction >
void dash::generate (GlobInputIt first, GlobInputIt last, UnaryFunction gen)
 Assigns each element in range [first, last) a value generated by the given function object g. More...
 
template<typename GlobInputIt , class UnaryFunction >
void dash::generate_with_index (GlobInputIt first, GlobInputIt last, UnaryFunction gen)
 Assigns each element in range [first, last) a value generated by the given function object g. More...
 
template<class GlobInputIter >
std::enable_if< !GlobInputIter::has_view::value, LocalIndexRange< typename GlobInputIter::pattern_type::index_type >>::type dash::local_index_range (const GlobInputIter &first, const GlobInputIter &last)
 Resolves the local index range between global iterators. More...
 
template<class GlobIterType >
LocalRange< const typename GlobIterType::value_type > dash::local_range (const GlobIterType &first, const GlobIterType &last)
 Resolves the local address range between global iterators. More...
 
template<class ElementType , class Compare = std::less<const ElementType &>>
const ElementType * dash::min_element (const ElementType *l_range_begin, const ElementType *l_range_end, Compare compare=std::less< const ElementType &>())
 Finds an iterator pointing to the element with the smallest value in the range [first,last). More...
 
template<typename GlobInputIt , class Compare = std::less< const typename dash::iterator_traits<GlobInputIt>::value_type &>>
GlobInputIt dash::min_element (const typename std::enable_if< dash::iterator_traits< GlobInputIt >::is_global_iterator::value, GlobInputIt >::type &first, const GlobInputIt &last, Compare compare=Compare())
 Finds an iterator pointing to the element with the smallest value in the range [first,last). More...
 
template<class GlobIter , class Compare = std::greater<const typename GlobIter::value_type &>>
GlobIter dash::max_element (const GlobIter &first, const GlobIter &last, Compare compare=Compare())
 Finds an iterator pointing to the element with the greatest value in the range [first,last). More...
 
template<class ElementType , class Compare = std::greater<ElementType &>>
const ElementType * dash::max_element (const ElementType *first, const ElementType *last, Compare compare=Compare())
 Finds an iterator pointing to the element with the greatest value in the range [first,last). More...
 
template<class LocalInputIter , class InitType , class BinaryOperation = dash::plus<typename std::iterator_traits<LocalInputIter>::value_type>, typename = typename std::enable_if< !dash::detail::is_global_iterator<LocalInputIter>::value >::type>
std::iterator_traits< LocalInputIter >::value_type dash::reduce (LocalInputIter in_first, LocalInputIter in_last, InitType init, BinaryOperation binary_op=BinaryOperation(), bool non_empty=true, dash::Team &team=dash::Team::All())
 Accumulate values in each process' range [in_first, in_last) using the provided binary reduce function binary_op, which must be commutative and associative. More...
 
template<class LocalInputIter , class InitType = typename std::iterator_traits<LocalInputIter>::value_type, typename = typename std::enable_if< !dash::detail::is_global_iterator<LocalInputIter>::value >::type>
std::iterator_traits< LocalInputIter >::value_type dash::reduce (LocalInputIter in_first, LocalInputIter in_last, InitType init, bool non_empty, dash::Team &team=dash::Team::All())
 Accumulate values across the local ranges [in_first,in_last) of each process as the sum of all values in the range. More...
 
template<class GlobInputIt , class InitType = typename dash::iterator_traits<GlobInputIt>::value_type, class BinaryOperation = dash::plus<typename dash::iterator_traits<GlobInputIt>::value_type>, typename = typename std::enable_if< dash::detail::is_global_iterator<GlobInputIt>::value >::type>
dash::iterator_traits< GlobInputIt >::value_type dash::reduce (GlobInputIt in_first, GlobInputIt in_last, InitType init, BinaryOperation binary_op=BinaryOperation())
 Accumulate values in the global range [in_first, in_last) using the provided binary reduce function binary_op, which must be commutative and linear. More...
 
template<class GlobRandomIt >
void dash::sort (GlobRandomIt begin, GlobRandomIt end)
 Sorts the elements in the range, defined by [begin, end) in ascending order. More...
 
template<class GlobRandomIt , class SortableHash >
void dash::sort (GlobRandomIt begin, GlobRandomIt end, SortableHash hash)
 Sorts the elements in the range, defined by [begin, end) in ascending order. More...
 
template<typename ValueType , class InputIt , class OutputIt , class UnaryOperation >
OutputIt dash::transform (InputIt in_first, InputIt in_last, OutputIt out_first, UnaryOperation unary_op)
 Apply a given function to elements in a range and store the result in another range, beginning at out_first. More...
 
template<class InputIt1 , class GlobInputIt , class GlobOutputIt , class BinaryOperation >
GlobOutputIt dash::transform (InputIt1 in_a_first, InputIt1 in_a_last, GlobInputIt in_b_first, GlobOutputIt out_first, BinaryOperation binary_op)
 Apply a given function to pairs of elements from two ranges and store the result in another range, beginning at out_first. More...
 

Detailed Description

Description

DASH algorithms library defines functions for a variety of purposes (e.g. searching, sorting, counting, manipulating) that operate on DASH containers.

Function Documentation

◆ all_of()

template<typename GlobIter , typename UnaryPredicate >
bool dash::all_of ( GlobIter  first,
GlobIter  last,
UnaryPredicate  p 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/AllOf.h>

Check whether all element in the range satisfy predicate p.

Returns
true if all elements satisfy p, false otherwise.
See also
dash::find_if
dash::find_if_not
dash::any_of
Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
pPredicate applied to the elements in range [first, last)
Examples:
ex.06.std-algo/main.cpp.

Definition at line 24 of file AllOf.h.

References dash::find_if_not().

31 {
32  return find_if_not(first, last, p) == last;
33 }
GlobIter find_if_not(GlobIter first, GlobIter last, UnaryPredicate predicate)
Returns an iterator to the first element in the range [first,last) that does not satisfy the predicat...
Definition: Find.h:160

◆ any_of()

template<typename GlobIter , typename UnaryPredicate >
bool dash::any_of ( GlobIter  first,
GlobIter  last,
UnaryPredicate  p 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/AnyOf.h>

Check whether any element in the range satisfies predicate p.

Returns
true if at least one element satisfies p, false otherwise.
See also
dash::find_if
dash::find_if_not
dash::all_of
Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
pPredicate applied to the elements in range [first, last)

Definition at line 23 of file AnyOf.h.

References dash::find_if().

30 {
31  return find_if(first, last, p) != last;
32 }
GlobIter find_if(GlobIter first, GlobIter last, UnaryPredicate predicate)
Returns an iterator to the first element in the range [first,last) that satisfies the predicate p...
Definition: Find.h:104

◆ broadcast() [1/3]

template<class LocalInputIter , typename = typename std::enable_if< !dash::detail::is_global_iterator<LocalInputIter>::value >::type>
void dash::broadcast ( LocalInputIter  in_first,
LocalInputIter  in_last,
dash::team_unit_t  root,
dash::Team team = dash::Team::All() 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Bcast.h>

Broadcast the local range of elements [in_first, in_last) from unit root to all other units in team.

If the range is not contiguous, a local copy of the data is created, broadcast, and copied into the range on all unit except for root.

The range has to have the same size on all units.

This operation overwrites the values in the range on all units except for root.

Collective operation.

Parameters
in_firstLocal iterator describing the beginning of the range to broadcast.
in_lastLocal iterator describing the end of the range to broadcast.
rootThe unit (member of team) to broadcast the data from.
teamThe team to use for the collective operation.

Definition at line 95 of file Bcast.h.

References dash::broadcast().

Referenced by dash::broadcast().

100 {
102  in_first, in_last, root, team,
103  typename std::iterator_traits<LocalInputIter>::iterator_category());
104 }
void broadcast(Coarray< T > &coarr, const team_unit_t &root)
Broadcasts the value on root to all other members of this co_array.
Definition: Bcast.h:152

◆ broadcast() [2/3]

template<class ValueType >
ValueType dash::broadcast ( dash::Shared< ValueType > &  shared)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Bcast.h>

Broadcast the value stored in dash::Shared from the unit owning the value to all other units with access to the shared object.

Collective operation.

Note
A broadcast can be more efficient than having all units access the value stored in the dash::Shared instance individually.
Parameters
sharedInstance of dash::Shared from which the value is broadcast to all units in the team that created the shared object.
Returns
The value broadcasted.

Definition at line 124 of file Bcast.h.

References dash::broadcast(), dash::Shared< ElementType >::local(), dash::Shared< ElementType >::owner(), dash::Shared< ElementType >::team(), and dash::ValueType.

125 {
126  ValueType res{};
127  auto& team = shared.team();
128  auto owner = shared.owner();
129  ValueType *ptr = (team.myid() == owner) ? shared.local() : std::addressof(res);
130  dash::broadcast(ptr,
131  std::next(ptr),
132  owner,
133  shared.team());
134 
135  return *ptr;
136 }
dash::Team & team() const noexcept
The dash::Team that created this shared object.
Definition: Shared.h:289
void broadcast(LocalInputIter in_first, LocalInputIter in_last, dash::team_unit_t root, dash::Team &team=dash::Team::All())
Broadcast the local range of elements [in_first, in_last) from unit root to all other units in team...
Definition: Bcast.h:95
dash::team_unit_t owner() const noexcept
The unit owning the memory in the global address space.
Definition: Shared.h:281
struct dash::dart_operation ValueType
Reduce operands to their minimum value.
constexpr value_type const * local() const noexcept
Native pointer to the starting address of the local memory of the unit that initialized this dash::Sh...
Definition: Shared.h:264

◆ broadcast() [3/3]

template<typename T >
void dash::broadcast ( Coarray< T > &  coarr,
const team_unit_t root 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Bcast.h>

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

This is a wrapper for dash::coarray::cobroadcast.

Collective operation.

See also
dash::coarray::cobroadcast
Parameters
coarrcoarray which should be broadcasted
masterthe value of this unit will be broadcastet

Definition at line 152 of file Bcast.h.

References dash::coarray::cobroadcast().

Referenced by dash::broadcast().

152  {
153  dash::coarray::cobroadcast(coarr, root);
154 }
void cobroadcast(Coarray< T > &coarr, const team_unit_t &master)
Broadcasts the value on master to all other members of this co_array.
Definition: Utils.h:142

◆ copy()

template<typename ValueType , class InputIt , class OutputIt >
OutputIt dash::copy ( InputIt  in_first,
InputIt  in_last,
OutputIt  out_first 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Copy.h>

Copies the elements in the range, defined by [in_first, in_last), to another range beginning at out_first.

In terms of data distribution, source and destination ranges passed to dash::copy can be local (*ValueType) or global (GlobIter<ValueType>).

For a non-blocking variant of dash::copy, see dash::copy_async.

Example:

// Start blocking copy
auto copy_last =
dash::copy(array_a.lbegin(),
array_a.lend(),
array_b.begin() + 200);
auto ncopied = dash::distance(array_b.begin() + 200, copy_last);
Returns
The output range end iterator that is created on completion of the copy operation.
Examples:
ex.06.std-algo/main.cpp, ex.10.radixsort/main.cpp, and ex.11.halo-stencil/main.cpp.

Referenced by dash::summa().

◆ copy_async()

template<typename ValueType , class GlobInputIt >
dash::Future<ValueType *> dash::copy_async ( InputIt  in_first,
InputIt  in_last,
OutputIt  out_first 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Copy.h>

Asynchronous variant of dash::copy.

Copies the elements in the range, defined by [in_first, in_last), to another range beginning at out_first.

In terms of data distribution, source and destination ranges passed to dash::copy can be local (*ValueType) or global (GlobIter<ValueType>).

For a blocking variant of dash::copy_async, see dash::copy.

Example:

// Start asynchronous copying
dash::Future<T*> fut_dest_end =
dash::copy_async(array_a.block(0).begin(),
array_a.block(0).end(),
local_array);
// Overlapping computation here
// ...
// Wait for completion of asynchronous copying:
T * copy_dest_end = fut_dest_end.get();
Returns
An instance of dash::Future providing the output range end iterator that is created on completion of the asynchronous copy operation.

Referenced by dash::summa().

◆ equal() [1/2]

template<typename GlobIter >
bool dash::equal ( GlobIter  first_1,
GlobIter  last_1,
GlobIter  first_2 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Equal.h>

Returns true if the range [first1, last1) is equal to the range [first2, first2 + (last1 - first1)), and false otherwise.

Parameters
first_1Iterator to the initial position in the sequence
last_1Iterator to the final position in the sequence

Definition at line 51 of file Equal.h.

References dart_allreduce(), DART_OK, DART_OP_BAND, DART_TYPE_BYTE, dash::distance(), dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::local(), dash::local_range(), and dash::myid().

57  {
58  static_assert(
60  "invalid iterator: Need to be a global iterator");
61 
62  auto& team = first_1.team();
63  auto myid = team.myid();
64  // Global iterators to local range:
65  auto index_range_in = dash::local_range(first_1, last_1);
66  auto l_first_1 = index_range_in.begin;
67  auto l_last_1 = index_range_in.end;
68  auto dist = std::distance(l_first_1, l_last_1);
69  auto index_range_out = dash::local_range(first_2, first_2 + dist);
70  auto common_dist = std::min(
71  std::distance(index_range_out.begin, index_range_out.end), dist);
72  char l_result = 1;
73 
74  // check if local ranges are corresponding
75  if (common_dist == dist) {
76  l_result = ::dash::internal::equal_loc_impl(
77  l_first_1, l_last_1, first_2.local());
78  } else if(common_dist > 0) {
79  l_result = ::dash::internal::equal_overlapping_impl(
80  first_1, last_1, first_2);
81  }
82 
83  char r_result = 0;
84 
85  DASH_ASSERT_RETURNS(
86  dart_allreduce(&l_result, &r_result, 1,
87  DART_TYPE_BYTE, DART_OP_BAND, team.dart_id()),
88  DART_OK);
89  return r_result;
90 }
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
Signals success.
Definition: dart_types.h:33
RandomAccessIt::difference_type distance(const RandomAccessIt &first, const RandomAccessIt &last)
Resolve the number of elements between two iterators.
Definition: Iterator.h:90
LocalRange< const typename GlobIterType::value_type > local_range(const GlobIterType &first, const GlobIterType &last)
Resolves the local address range between global iterators.
Definition: LocalRange.h:295
dart_ret_t dart_allreduce(const void *sendbuf, void *recvbuf, size_t nelem, dart_datatype_t dtype, dart_operation_t op, dart_team_t team)
DART Equivalent to MPI allreduce.
#define DART_TYPE_BYTE
integral data types
Definition: dart_types.h:125
Binary AND.
Definition: dart_types.h:83

◆ equal() [2/2]

template<typename GlobIter , class BinaryPredicate >
bool dash::equal ( GlobIter  first_1,
GlobIter  last_1,
GlobIter  first_2,
BinaryPredicate   
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Equal.h>

Returns true if the range [first1, last1) is equal to the range [first2, first2 + (last1 - first1)) with respect to a specified predicate, and false otherwise.

Parameters
first_1Iterator to the initial position in the sequence
last_1Iterator to the final position in the sequence

Definition at line 100 of file Equal.h.

References dart_allreduce(), DART_OK, DART_OP_BAND, DART_TYPE_BYTE, dash::distance(), dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::local(), dash::local_range(), and dash::myid().

107 {
108  static_assert(
110  "invalid iterator: Need to be a global iterator");
111 
112  auto & team = first_1.team();
113  auto myid = team.myid();
114  // Global iterators to local range:
115  auto index_range_in = dash::local_range(first_1, last_1);
116  auto l_first_1 = index_range_in.begin;
117  auto l_last_1 = index_range_in.end;
118  auto dist = std::distance(l_first_1, l_last_1);
119  auto index_range_out = dash::local_range(first_2, first_2 + dist);
120  auto common_dist = std::min(std::distance(index_range_out.begin, index_range_out.end),dist);
121  char l_result = 1;
122 
123  // check if local ranges are corresponding
124  if(std::distance(index_range_out.begin, index_range_out.end) == dist){
125  l_result = ::dash::internal::equal_loc_impl(l_first_1, l_last_1, first_2.local());
126  } else if(common_dist > 0) {
127  l_result = ::dash::internal::equal_overlapping_impl(
128  first_1, last_1, first_2);
129  }
130 
131  char r_result = 0;
132 
133  DASH_ASSERT_RETURNS(
134  dart_allreduce(&l_result, &r_result, 1,
135  DART_TYPE_BYTE, DART_OP_BAND, team.dart_id()),
136  DART_OK);
137  return r_result;
138 }
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
Signals success.
Definition: dart_types.h:33
RandomAccessIt::difference_type distance(const RandomAccessIt &first, const RandomAccessIt &last)
Resolve the number of elements between two iterators.
Definition: Iterator.h:90
LocalRange< const typename GlobIterType::value_type > local_range(const GlobIterType &first, const GlobIterType &last)
Resolves the local address range between global iterators.
Definition: LocalRange.h:295
dart_ret_t dart_allreduce(const void *sendbuf, void *recvbuf, size_t nelem, dart_datatype_t dtype, dart_operation_t op, dart_team_t team)
DART Equivalent to MPI allreduce.
#define DART_TYPE_BYTE
integral data types
Definition: dart_types.h:125
Binary AND.
Definition: dart_types.h:83

◆ fill()

template<typename GlobIterType >
void dash::fill ( GlobIterType  first,
GlobIterType  last,
const typename GlobIterType::value_type &  value 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Fill.h>

Assigns the given value to the elements in the range [first, last)

Being a collaborative operation, each unit will assign the value to its local elements only.

Template Parameters
ElementTypeType of the elements in the sequence
Time complexity
O(d) + O(nl), with d dimensions in the global iterators' pattern and nl local elements within the global range
Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
valueValue which will be assigned to the elements in range [first, last)
Examples:
ex.08.io-hdf5/main.cpp, ex.11.halo-stencil/main.cpp, and ex.11.simple-stencil/main.cpp.

Definition at line 35 of file Fill.h.

References dash::local_range(), and dash::util::UnitLocality::num_domain_threads().

Referenced by dash::halo::HaloMemory< HaloBlock_t >::HaloMemory(), and dash::Coevent::initialize().

42 {
43  typedef typename GlobIterType::index_type index_t;
44  typedef typename GlobIterType::value_type value_t;
45 
46  // Global iterators to local range:
47  auto index_range = dash::local_range(first, last);
48  value_t * lfirst = index_range.begin;
49  value_t * llast = index_range.end;
50 
51 #ifdef DASH_ENABLE_OPENMP
53  auto n_threads = uloc.num_domain_threads();
54  auto nlocal = llast - lfirst;
55  DASH_LOG_DEBUG("dash::fill", "thread capacity:", n_threads);
56  #pragma omp parallel for num_threads(n_threads)
57  for (index_t lt = 0; lt < nlocal; ++lt) {
58  lfirst[lt] = value;
59  }
60 
61 #else
62  std::fill(lfirst, llast, value);
63 #endif
64 }
LocalRange< const typename GlobIterType::value_type > local_range(const GlobIterType &first, const GlobIterType &last)
Resolves the local address range between global iterators.
Definition: LocalRange.h:295
int num_domain_threads()
Number of threads currently available to the active unit.
Definition: UnitLocality.h:306
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
Wrapper of a single dart_unit_locality_t object.
Definition: UnitLocality.h:30

◆ find()

template<typename GlobIter , typename ElementType >
GlobIter dash::find ( GlobIter  first,
GlobIter  last,
const ElementType &  value 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Find.h>

Returns an iterator to the first element in the range [first,last) that compares equal to val.

If no such element is found, the function returns last.

Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
valueValue which is searched for using operator==

Definition at line 22 of file Find.h.

References dart_allreduce(), DART_OK, DART_OP_MIN, dash::local_begin(), dash::local_index_range(), and dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::pos().

Referenced by dash::util::LocalityDomain::leader_unit(), and dash::coarray::sync_images().

29 {
30 
31  //use iterator traits
32  using iterator_traits = dash::iterator_traits<GlobIter>;
33 
34  using p_index_t = typename iterator_traits::index_type;
35 
36  if(first >= last) {
37  return last;
38  }
39 
40  p_index_t g_index;
41  auto & pattern = first.pattern();
42  auto & team = pattern.team();
43  auto index_range = dash::local_index_range(first, last);
44  auto l_begin_index = index_range.begin;
45  auto l_end_index = index_range.end;
46  auto first_offset = first.pos();
47  if(l_begin_index == l_end_index){
48  g_index = std::numeric_limits<p_index_t>::max();
49  } else {
50  auto g_begin_index = pattern.global(l_begin_index);
51 
52  // Pointer to first element in local memory:
53  auto const* lbegin = dash::local_begin(
54  static_cast<typename GlobIter::pointer>(first), team.myid());
55  // Pointers to first / final element in local range:
56  const auto l_range_begin = lbegin + l_begin_index;
57  const auto l_range_end = lbegin + l_end_index;
58 
59  DASH_LOG_DEBUG("local index range", l_begin_index, l_end_index);
60 
61  auto l_result = std::find(l_range_begin, l_range_end, value);
62  if (l_result == l_range_end) {
63  DASH_LOG_DEBUG("Not found in local range");
64  g_index = std::numeric_limits<p_index_t>::max();
65  } else {
66  auto l_hit_index = l_result - lbegin;
67  g_index = pattern.global(l_hit_index);
68  }
69  }
70  team.barrier();
71 
72  // receive buffer for global maximal index
73  p_index_t g_hit_idx;
74 
75  DASH_ASSERT_RETURNS(
77  &g_index,
78  &g_hit_idx,
79  1,
80  dart_datatype<p_index_t>::value,
82  team.dart_id()),
83  DART_OK);
84 
85  if (g_hit_idx == std::numeric_limits<p_index_t>::max()) {
86  DASH_LOG_DEBUG("element not found");
87  } else {
88  return first + g_hit_idx;
89  }
90  return last;
91 }
DASH_CONSTEXPR std::enable_if< std::is_same< typename dash::memory_space_traits< MemSpaceT >::memory_space_layout_tag, memory_space_contiguous >::value, T >::type * local_begin(GlobPtr< T, MemSpaceT > global_begin, dash::team_unit_t unit)
Returns the begin of the local memory portion within a global memory segment.
Definition: GlobPtr.h:593
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_allreduce(const void *sendbuf, void *recvbuf, size_t nelem, dart_datatype_t dtype, dart_operation_t op, dart_team_t team)
DART Equivalent to MPI allreduce.
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
std::enable_if< !GlobInputIter::has_view::value, LocalIndexRange< typename GlobInputIter::pattern_type::index_type >>::type local_index_range(const GlobInputIter &first, const GlobInputIter &last)
Resolves the local index range between global iterators.
Definition: LocalRange.h:101
Minimum.
Definition: dart_types.h:73

◆ find_if()

template<typename GlobIter , typename UnaryPredicate >
GlobIter dash::find_if ( GlobIter  first,
GlobIter  last,
UnaryPredicate  predicate 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Find.h>

Returns an iterator to the first element in the range [first,last) that satisfies the predicate p.

If no such element is found, the function returns last.

See also
dash::find
dash::find_if_not

Global iterators to local range:

Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
predicatePredicate which will be applied to the elements in range [first, last)

Definition at line 104 of file Find.h.

References dash::distance(), dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::local, dash::local_range(), dash::myid(), and dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::pos().

Referenced by dash::any_of(), dash::EpochSynchronizedAllocator< ElementType, LMemSpace, AllocationPolicy, LocalAlloc >::deallocate(), dash::find_if_not(), dash::GlobLocalMemoryPool< dash::HostSpace >::flush_local(), and dash::EpochSynchronizedAllocator< ElementType, LMemSpace, AllocationPolicy, LocalAlloc >::get_local_allocator().

111 {
112  using iterator_traits = dash::iterator_traits<GlobIter>;
113 
114  using index_t = typename iterator_traits::index_type;
115 
116  auto& team = first.pattern().team();
117  auto myid = team.myid();
119  auto index_range = dash::local_range(first, last);
120  auto l_first = index_range.begin;
121  auto l_last = index_range.end;
122 
123  auto l_result = std::find_if(l_first, l_last, predicate);
124  auto l_offset = l_result == l_last ? -1 : std::distance(l_first, l_result);
125 
126  dash::Array<index_t> l_results(team.size(), team);
127 
128  l_results.local[0] = l_offset;
129 
130  team.barrier();
131 
132  // All local offsets stored in l_results
133  auto result = last;
134 
135  for (auto u = 0; u < team.size(); u++) {
136  if (l_results[u] >= 0) {
137  auto g_offset = first.pattern().global_index(u, {l_results[u]});
138  result = first + g_offset - first.pos();
139  break;
140  }
141  }
142 
143  team.barrier();
144  return result;
145 }
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
RandomAccessIt::difference_type distance(const RandomAccessIt &first, const RandomAccessIt &last)
Resolve the number of elements between two iterators.
Definition: Iterator.h:90
LocalRange< const typename GlobIterType::value_type > local_range(const GlobIterType &first, const GlobIterType &last)
Resolves the local address range between global iterators.
Definition: LocalRange.h:295
GlobIter find_if(GlobIter first, GlobIter last, UnaryPredicate predicate)
Returns an iterator to the first element in the range [first,last) that satisfies the predicate p...
Definition: Find.h:104
A distributed array.
Definition: Array.h:89
constexpr const PatternType & pattern() const noexcept
The pattern used to distribute array elements to units.
Definition: Array.h:249
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732

◆ find_if_not()

template<typename GlobIter , class UnaryPredicate >
GlobIter dash::find_if_not ( GlobIter  first,
GlobIter  last,
UnaryPredicate  predicate 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Find.h>

Returns an iterator to the first element in the range [first,last) that does not satisfy the predicate p.

If no such element is found, the function returns last.

See also
dash::find
dash::find_if_not
Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
predicatePredicate which will be applied to the elements in range [first, last)

Definition at line 160 of file Find.h.

References dash::find_if().

Referenced by dash::all_of().

167 {
168  return find_if(first, last, std::not1(predicate));
169 }
GlobIter find_if(GlobIter first, GlobIter last, UnaryPredicate predicate)
Returns an iterator to the first element in the range [first,last) that satisfies the predicate p...
Definition: Find.h:104

◆ for_each()

template<typename GlobInputIt , class UnaryFunction >
void dash::for_each ( const GlobInputIt &  first,
const GlobInputIt &  last,
UnaryFunction  func 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/ForEach.h>

Invoke a function on every element in a range distributed by a pattern.

This function has the same signature as std::for_each but Being a collaborative operation, each unit will invoke the given function on its local elements only. To support compiler optimization, this const version is provided

Template Parameters
GlobIterGlobal Iterator to iterate the sequence
UnaryFunctionFunction to invoke for each element in the specified range with signature (void (const ElementType &)). Signature does not need to have (const &) but must be compatible to std::for_each.
Time complexity
O(d) + O(nl), with d dimensions in the global iterators' pattern and nl local elements within the global range

Global iterators to local index range:

Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
funcFunction to invoke on every index in the range

Definition at line 32 of file ForEach.h.

References dash::local(), and dash::local_index_range().

Referenced by dash::coarray::sync_images(), and dash::io::hdf5::StoreHDF::write().

39 {
40  using iterator_traits = dash::iterator_traits<GlobInputIt>;
41  static_assert(
42  iterator_traits::is_global_iterator::value,
43  "must be a global iterator");
45  auto index_range = dash::local_index_range(first, last);
46  auto lbegin_index = index_range.begin;
47  auto lend_index = index_range.end;
48  auto & team = first.pattern().team();
49  if (lbegin_index != lend_index) {
50  // Pattern from global begin iterator:
51  auto & pattern = first.pattern();
52  // Local range to native pointers:
53  auto lrange_begin = (first + pattern.global(lbegin_index)).local();
54  auto lrange_end = lrange_begin + lend_index;
55  std::for_each(lrange_begin, lrange_end, func);
56  }
57  team.barrier();
58 }
constexpr auto local(ViewType &v) -> typename std::enable_if<(std::is_pointer< typename ViewType::iterator >::value||(dash::view_traits< ViewValueT >::is_local::value)), ViewType &>::type
Definition: Local.h:28
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
std::enable_if< !GlobInputIter::has_view::value, LocalIndexRange< typename GlobInputIter::pattern_type::index_type >>::type local_index_range(const GlobInputIter &first, const GlobInputIter &last)
Resolves the local index range between global iterators.
Definition: LocalRange.h:101

◆ for_each_with_index()

template<typename GlobInputIt , class UnaryFunctionWithIndex >
void dash::for_each_with_index ( const GlobInputIt &  first,
const GlobInputIt &  last,
UnaryFunctionWithIndex  func 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/ForEach.h>

Invoke a function on every element in a range distributed by a pattern.

Being a collaborative operation, each unit will invoke the given function on its local elements only. The index passed to the function is a global index.

Template Parameters
GlobIterGlobal Iterator to iterate the sequence
UnaryFunctionWithIndexFunction to invoke for each element in the specified range with signature void (const ElementType &, index_t) Signature does not need to have (const &) but must be compatible to std::for_each.
Time complexity
O(d) + O(nl), with d dimensions in the global iterators' pattern and nl local elements within the global range

Global iterators to local index range:

Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
funcFunction to invoke on every index in the range

Definition at line 80 of file ForEach.h.

References dash::local_index_range().

87 {
88  using iterator_traits = dash::iterator_traits<GlobInputIt>;
89  static_assert(
90  iterator_traits::is_global_iterator::value,
91  "must be a global iterator");
92 
94  auto index_range = dash::local_index_range(first, last);
95  auto lbegin_index = index_range.begin;
96  auto lend_index = index_range.end;
97  auto & team = first.pattern().team();
98  if (lbegin_index != lend_index) {
99  // Pattern from global begin iterator:
100  auto & pattern = first.pattern();
101  auto first_offset = first.pos();
102  // Iterate local index range:
103  for (auto lindex = lbegin_index;
104  lindex != lend_index;
105  ++lindex) {
106  auto gindex = pattern.global(lindex);
107  auto element_it = first + (gindex - first_offset);
108  func(*(element_it.local()), gindex);
109  }
110  }
111  team.barrier();
112 }
std::enable_if< !GlobInputIter::has_view::value, LocalIndexRange< typename GlobInputIter::pattern_type::index_type >>::type local_index_range(const GlobInputIter &first, const GlobInputIter &last)
Resolves the local index range between global iterators.
Definition: LocalRange.h:101

◆ generate()

template<typename GlobInputIt , class UnaryFunction >
void dash::generate ( GlobInputIt  first,
GlobInputIt  last,
UnaryFunction  gen 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Generate.h>

Assigns each element in range [first, last) a value generated by the given function object g.

Being a collaborative operation, each unit will invoke the given function on its local elements only.

Template Parameters
ElementTypeType of the elements in the sequence invoke, deduced from parameter gen
UnaryFunctionUnary function with signature ElementType(void)
Time complexity
O(d) + O(nl), with d dimensions in the global iterators' pattern and nl local elements within the global range

Global iterators to local range:

Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
genGenerator function

Definition at line 32 of file Generate.h.

References dash::local_range().

39 {
40  using iterator_traits = dash::iterator_traits<GlobInputIt>;
41  static_assert(
42  iterator_traits::is_global_iterator::value,
43  "must be a global iterator");
45  auto lrange = dash::local_range(first, last);
46  auto lfirst = lrange.begin;
47  auto llast = lrange.end;
48 
49  std::generate(lfirst, llast, gen);
50 }
LocalRange< const typename GlobIterType::value_type > local_range(const GlobIterType &first, const GlobIterType &last)
Resolves the local address range between global iterators.
Definition: LocalRange.h:295
void generate(GlobInputIt first, GlobInputIt last, UnaryFunction gen)
Assigns each element in range [first, last) a value generated by the given function object g...
Definition: Generate.h:32

◆ generate_with_index()

template<typename GlobInputIt , class UnaryFunction >
void dash::generate_with_index ( GlobInputIt  first,
GlobInputIt  last,
UnaryFunction  gen 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Generate.h>

Assigns each element in range [first, last) a value generated by the given function object g.

The index passed to the function is a global index.

Being a collaborative operation, each unit will invoke the given function on its local elements only.

Template Parameters
ElementTypeType of the elements in the sequence invoke, deduced from parameter gen
UnaryFunctionUnary function with signature ElementType(index_t)
Time complexity
O(d) + O(nl), with d dimensions in the global iterators' pattern and nl local elements within the global range

Global iterators to local index range:

Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
genGenerator function

Definition at line 71 of file Generate.h.

References dash::local_index_range().

78 {
79  using iterator_traits = dash::iterator_traits<GlobInputIt>;
80  static_assert(
81  iterator_traits::is_global_iterator::value,
82  "must be a global iterator");
84  auto index_range = dash::local_index_range(first, last);
85  auto lbegin_index = index_range.begin;
86  auto lend_index = index_range.end;
87 
88  if (lbegin_index != lend_index) {
89  // Pattern from global begin iterator:
90  auto& pattern = first.pattern();
91  auto first_offset = first.pos();
92  // Iterate local index range:
93  for (auto lindex = lbegin_index; lindex != lend_index; ++lindex) {
94  auto gindex = pattern.global(lindex);
95  auto element_it = first + (gindex - first_offset);
96  *element_it = gen(gindex);
97  }
98  }
99 }
std::enable_if< !GlobInputIter::has_view::value, LocalIndexRange< typename GlobInputIter::pattern_type::index_type >>::type local_index_range(const GlobInputIter &first, const GlobInputIter &last)
Resolves the local index range between global iterators.
Definition: LocalRange.h:101

◆ local_index_range()

template<class GlobInputIter >
std::enable_if< !GlobInputIter::has_view::value, LocalIndexRange<typename GlobInputIter::pattern_type::index_type>>::type dash::local_index_range ( const GlobInputIter &  first,
const GlobInputIter &  last 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/LocalRange.h>

Resolves the local index range between global iterators.

Example:

Total range 0 1 2 3 4 5 6 7 8 9
Global iterators first = 4; last = 7;
  0 1 2 3 [4 5 6 7] 8 9]
Local elements (local index:value) 0:2 1:3 2:6 3:7
Result (local indices) 2 3
Returns
A local index range consisting of offsets of the first and last element in local memory within the sequence limited by the given global iterators.
Template Parameters
ElementTypeType of the elements in the sequence
PatternTypeType of the global iterators' pattern implementation
Time complexity
O(d), with d dimensions in the global iterators' pattern
Parameters
firstIterator to the initial position in the global sequence
lastIterator to the final position in the global sequence

Definition at line 101 of file LocalRange.h.

Referenced by dash::find(), dash::for_each(), dash::for_each_with_index(), dash::generate_with_index(), dash::local_range(), and dash::min_element().

106 {
107  typedef typename GlobInputIter::pattern_type::index_type idx_t;
108 
109  typedef typename GlobInputIter::pattern_type pattern_t;
110  typedef typename pattern_t::index_type idx_t;
111  // Get offsets of iterators within global memory, O(1):
112  auto begin_gindex = static_cast<idx_t>(first.pos());
113  auto end_gindex = static_cast<idx_t>(last.pos());
114  DASH_LOG_TRACE("local_index_range(GlobIt,GlobIt)",
115  begin_gindex, end_gindex);
116  // Get pattern from global iterators, O(1):
117  const auto& pattern = first.pattern();
118  DASH_LOG_TRACE_VAR("local_index_range", pattern.local_size());
119  if (pattern.local_size() == 0) {
120  // Local index range is empty
121  DASH_LOG_TRACE("local_index_range (lsize:0) ->", 0, 0);
122  return LocalIndexRange<idx_t> { 0, 0 };
123  }
124  // Global index of first element in pattern, O(1):
125  idx_t lbegin_gindex = pattern.lbegin();
126  // Global index of last element in pattern, O(1):
127  idx_t lend_gindex = pattern.lend();
128  DASH_LOG_TRACE_VAR("local_index_range", lbegin_gindex);
129  DASH_LOG_TRACE_VAR("local_index_range", lend_gindex);
130  if (lend_gindex <= begin_gindex || // local end before global begin
131  lbegin_gindex >= end_gindex) { // local begin after global end
132  // No overlap, intersection is empty
133  DASH_LOG_TRACE("local_index_range (intersect:0) >", 0, 0);
134  return LocalIndexRange<idx_t> { 0, 0 };
135  }
136  // Intersect local range and global range, in global index domain:
137  auto goffset_lbegin = std::max<idx_t>(lbegin_gindex, begin_gindex);
138  auto goffset_lend = std::min<idx_t>(lend_gindex, end_gindex);
139  // Global positions of local range to global coordinates, O(d):
140  auto lbegin_gcoords = pattern.coords(goffset_lbegin);
141  // Subtract 1 from global end offset as it points one coordinate
142  // past the last index which is out of the valid coordinates range:
143  auto lend_gcoords = pattern.coords(goffset_lend-1);
144  // Global coordinates of local range to local indices, O(d):
145  auto lbegin_index = pattern.at(lbegin_gcoords);
146  // Add 1 to local end index to it points one coordinate past the
147  // last index:
148  auto lend_index = pattern.at(lend_gcoords);
149  if (lend_index
150  == std::numeric_limits<typename pattern_t::index_type>::max()) {
151  DASH_LOG_ERROR("local_index_range !",
152  "index type too small for for local index range");
153  }
154  lend_index += 1;
155  // Return local index range
156  DASH_LOG_TRACE("local_index_range >", lbegin_index, lend_index);
157  return LocalIndexRange<idx_t> { lbegin_index, lend_index };
158 }

◆ local_range()

template<class GlobIterType >
LocalRange<const typename GlobIterType::value_type> dash::local_range ( const GlobIterType &  first,
const GlobIterType &  last 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/LocalRange.h>

Resolves the local address range between global iterators.

Example:
Total range a b c d e f g h i j
Global iterators first = b; last = i;

| a b [c d e f g h] i j] Local elements | a b d e Result | d e

Returns
A local range consisting of native pointers to the first and last local element within the sequence limited by the given global iterators.
Time complexity
O(d), with d dimensions in the global iterators' pattern
Parameters
firstIterator to the initial position in the global sequence
lastIterator to the final position in the global sequence

Definition at line 295 of file LocalRange.h.

References dash::local_begin(), and dash::local_index_range().

Referenced by dash::equal(), dash::fill(), dash::find_if(), dash::generate(), and dash::reduce().

300 {
301  typedef typename GlobIterType::pattern_type pattern_t;
302  typedef typename GlobIterType::value_type value_t;
303  typedef typename pattern_t::index_type idx_t;
304  DASH_LOG_TRACE("local_range()",
305  "gfirst.pos:", first.pos(),
306  "glast.pos:", last.pos());
307  // Global iterators to local index range, O(d):
308  auto index_range = dash::local_index_range(first, last);
309  idx_t lbegin_index = index_range.begin;
310  idx_t lend_index = index_range.end;
311  if (lbegin_index == lend_index) {
312  // Local range is empty
313  DASH_LOG_TRACE("local_range >", "empty local range",
314  lbegin_index, lend_index);
315  return LocalRange<const value_t> { nullptr, nullptr };
316  }
317  // Local start address from global memory:
318  const auto& pattern = first.pattern();
319 
320  auto* lbegin = dash::local_begin(
321  static_cast<typename GlobIterType::pointer>(first.globmem().begin()),
322  first.team().myid());
323  // Add local offsets to local start address:
324  if (lbegin == nullptr) {
325  DASH_LOG_TRACE("local_range >", "lbegin null");
326  return LocalRange<const value_t> { nullptr, nullptr };
327  }
328  DASH_LOG_TRACE("local_range >",
329  "lbegin:", lbegin,
330  "l_idx_range:", lbegin_index, "-", lend_index);
331  return LocalRange<const value_t> {
332  lbegin + lbegin_index,
333  lbegin + lend_index };
334 }
DASH_CONSTEXPR std::enable_if< std::is_same< typename dash::memory_space_traits< MemSpaceT >::memory_space_layout_tag, memory_space_contiguous >::value, T >::type * local_begin(GlobPtr< T, MemSpaceT > global_begin, dash::team_unit_t unit)
Returns the begin of the local memory portion within a global memory segment.
Definition: GlobPtr.h:593
std::enable_if< !GlobInputIter::has_view::value, LocalIndexRange< typename GlobInputIter::pattern_type::index_type >>::type local_index_range(const GlobInputIter &first, const GlobInputIter &last)
Resolves the local index range between global iterators.
Definition: LocalRange.h:101

◆ max_element() [1/2]

template<class GlobIter , class Compare = std::greater<const typename GlobIter::value_type &>>
GlobIter dash::max_element ( const GlobIter first,
const GlobIter last,
Compare  compare = Compare() 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/MinMax.h>

Finds an iterator pointing to the element with the greatest value in the range [first,last).

Returns
An iterator to the first occurrence of the greatest value in the range, or last if the range is empty.
Template Parameters
ElementTypeType of the elements in the sequence
CompareBinary comparison function with signature bool (const TypeA &a, const TypeB &b)
Time complexity
O(d) + O(nl), with d dimensions in the global iterators' pattern and nl local elements within the global range
Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
compareElement comparison function, defaults to std::less

Definition at line 332 of file MinMax.h.

References dash::min_element().

Referenced by dash::LoadBalancePattern< 1, CompBasedMeasure, MemBasedMeasure, Arrangement, IndexType >::ndim(), dash::CSRPattern< 1, Arrangement, IndexType >::ndim(), and dash::DynamicPattern< 1, Arrangement, IndexType >::ndim().

339 {
340  // Same as min_element with different compare function
341  return dash::min_element(first, last, compare);
342 }
const ElementType * min_element(const ElementType *l_range_begin, const ElementType *l_range_end, Compare compare=std::less< const ElementType &>())
Finds an iterator pointing to the element with the smallest value in the range [first,last).
Definition: MinMax.h:47

◆ max_element() [2/2]

template<class ElementType , class Compare = std::greater<ElementType &>>
const ElementType* dash::max_element ( const ElementType *  first,
const ElementType *  last,
Compare  compare = Compare() 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/MinMax.h>

Finds an iterator pointing to the element with the greatest value in the range [first,last).

Specialization for local range, delegates to std::min_element.

Returns
An iterator to the first occurrence of the greatest value in the range, or last if the range is empty.
Template Parameters
ElementTypeType of the elements in the sequence
CompareBinary comparison function with signature bool (const TypeA &a, const TypeB &b)
Time complexity
O(d) + O(nl), with d dimensions in the global iterators' pattern and nl local elements within the global range
Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
compareElement comparison function, defaults to std::less

Definition at line 362 of file MinMax.h.

References dash::min_element().

369 {
370  // Same as min_element with different compare function
371  return dash::min_element(first, last, compare);
372 }
const ElementType * min_element(const ElementType *l_range_begin, const ElementType *l_range_end, Compare compare=std::less< const ElementType &>())
Finds an iterator pointing to the element with the smallest value in the range [first,last).
Definition: MinMax.h:47

◆ min_element() [1/2]

template<class ElementType , class Compare = std::less<const ElementType &>>
const ElementType* dash::min_element ( const ElementType *  l_range_begin,
const ElementType *  l_range_end,
Compare  compare = std::less<const ElementType &>() 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/MinMax.h>

Finds an iterator pointing to the element with the smallest value in the range [first,last).

Specialization for local range, delegates to std::min_element.

Returns
An iterator to the first occurrence of the smallest value in the range, or last if the range is empty.
Template Parameters
ElementTypeType of the elements in the sequence
CompareBinary comparison function with signature bool (const TypeA &a, const TypeB &b)
Time complexity
O(d) + O(nl), with d dimensions in the global iterators' pattern and nl local elements within the global range
Parameters
l_range_beginIterator to the initial position in the sequence
l_range_endIterator to the final position in the sequence
compareElement comparison function, defaults to std::less
Examples:
ex.05.min_element/main.cpp.

Definition at line 47 of file MinMax.h.

References dash::min_element(), and dash::util::UnitLocality::num_domain_threads().

Referenced by dash::max_element(), and dash::min_element().

55 {
56 #ifdef DASH_ENABLE_OPENMP
57 #define ROUNDUP(T, A) ((T + A - 1) & ~(A - 1))
58 
59  typedef typename std::decay<ElementType>::type value_t;
61  //TODO: ask dyloc for available memory spaces
62  auto n_threads = uloc.num_domain_threads();
63  DASH_LOG_DEBUG("dash::min_element", "thread capacity:", n_threads);
64 
65  // TODO: Should also restrict on elements/units > ~10240.
66  // Find a model for the minimum work laod.
67  if (n_threads > 1) {
68  auto l_size = l_range_end - l_range_begin;
69  int min_idx_l = 0;
70  ElementType min_val_l = *l_range_begin;
71 
72  typedef struct min_pos_t { value_t val; size_t idx; } min_pos;
73 
74  DASH_LOG_TRACE("dash::min_element", "sizeof(min_pos):", sizeof(min_pos));
75 
76  dash::HostSpace hostSpace;
77 
78  int align_bytes = uloc.cache_line_size(0);
79  int single_element_sz = ROUNDUP(sizeof(min_pos), align_bytes);
80 
81  size_t min_vals_t_bytes = single_element_sz * n_threads;
82 
83  auto min_vals_t_raw = static_cast<uint8_t *>(
84  hostSpace.allocate(min_vals_t_bytes, align_bytes));
85 
86  DASH_LOG_TRACE("dash::min_element", "min * alloc:", min_vals_t_raw);
87  //DASH_LOG_TRACE("dash::min_element", "min * aligned:", min_vals_t);
88  DASH_LOG_TRACE("dash::min_element", "min * size:", min_vals_t_bytes);
89  DASH_ASSERT_GE(min_vals_t_bytes, n_threads * sizeof(min_pos),
90  "Aligned buffer of min_pos has insufficient size");
91  DASH_ASSERT_MSG(nullptr != min_vals_t_raw,
92  "Aligned allocation of min_pos returned nullptr");
93 
94  // Cannot use user-defined reduction (OpenMP 4.0) as the compare
95  // predicate cannot be used in `omp declare reduction`.
96  // Avoid omp for + omp critical section by using array of
97  // thread-local minimum values, aligned to prevent false sharing:
98  int t_id;
99  #pragma omp parallel num_threads(n_threads) private(t_id)
100  {
101  // Documentation of Intel MIC intrinsics, see:
102  // https://software.intel.com/de-de/node/523533
103  // https://software.intel.com/de-de/node/523387
104  t_id = omp_get_thread_num();
105  DASH_LOG_TRACE("dash::min_element", "starting thread", t_id);
106  auto & min_val_t = *(reinterpret_cast<min_pos *>(min_vals_t_raw + t_id * single_element_sz));
107  min_val_t.idx = min_idx_l;
108  min_val_t.val = min_val_l;
109  // Cannot use explicit private(min_val_t) as ElementType might
110  // not be default-constructible:
111  #pragma omp for schedule(static)
112  for (int i = 0; i < l_size; i++) {
113  const ElementType & val_t = *(l_range_begin + i);
114  if (compare(val_t, min_val_t.val)) {
115  min_val_t.val = val_t;
116  min_val_t.idx = i;
117  }
118  }
119  DASH_LOG_TRACE("dash::min_element", "local minimum at thread", t_id,
120  "idx:", min_val_t.idx,
121  "val:", min_val_t.val);
122  }
123 
124  min_pos min_pos_l = * (reinterpret_cast<min_pos *>(min_vals_t_raw));
125 
126  for (int t = 1; t < n_threads; t++) {
127  const min_pos & mpt = *(reinterpret_cast<min_pos *>(min_vals_t_raw + t * single_element_sz));
128  if (compare(mpt.val, min_pos_l.val)) {
129  min_pos_l = mpt;
130  }
131  }
132 
133  hostSpace.deallocate(min_vals_t_raw, min_vals_t_bytes, align_bytes);
134 
135  return (l_range_begin + min_pos_l.idx);
136  }
137 #endif // DASH_ENABLE_OPENMP
138  return ::std::min_element(l_range_begin, l_range_end, compare);
139 }
int num_domain_threads()
Number of threads currently available to the active unit.
Definition: UnitLocality.h:306
GlobInputIt min_element(const typename std::enable_if< dash::iterator_traits< GlobInputIt >::is_global_iterator::value, GlobInputIt >::type &first, const GlobInputIt &last, Compare compare=Compare())
Finds an iterator pointing to the element with the smallest value in the range [first,last).
Definition: MinMax.h:161
Wrapper of a single dart_unit_locality_t object.
Definition: UnitLocality.h:30

◆ min_element() [2/2]

template<typename GlobInputIt , class Compare = std::less< const typename dash::iterator_traits<GlobInputIt>::value_type &>>
GlobInputIt dash::min_element ( const typename std::enable_if< dash::iterator_traits< GlobInputIt >::is_global_iterator::value, GlobInputIt >::type &  first,
const GlobInputIt &  last,
Compare  compare = Compare() 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/MinMax.h>

Finds an iterator pointing to the element with the smallest value in the range [first,last).

Returns
An iterator to the first occurrence of the smallest value in the range, or last if the range is empty.
Template Parameters
ElementTypeType of the elements in the sequence
CompareBinary comparison function with signature bool (const TypeA &a, const TypeB &b)
Time complexity
O(d) + O(nl), with d dimensions in the global iterators' pattern and nl local elements within the global range
Parameters
firstIterator to the initial position in the sequence
lastIterator to the final position in the sequence
compareElement comparison function, defaults to std::less

Definition at line 161 of file MinMax.h.

References dart_allgather(), DART_OK, DART_TYPE_BYTE, dash::local_begin(), dash::local_index_range(), and dash::min_element().

Referenced by dash::min_element().

170 {
171  typedef typename GlobInputIt::pattern_type pattern_t;
172  typedef typename pattern_t::index_type index_t;
173  typedef typename std::decay<
174  typename dash::iterator_traits<GlobInputIt>::value_type>::type value_t;
175 
176  // return last for empty array
177  if (first == last) {
178  DASH_LOG_DEBUG("dash::min_element >",
179  "empty range, returning last", last);
180  return last;
181  }
182 
183  dash::util::Trace trace("min_element");
184 
185  auto & pattern = first.pattern();
186  auto & team = pattern.team();
187  DASH_LOG_DEBUG("dash::min_element()",
188  "allocate minarr, size", team.size());
189  // Global position of end element in range:
190  auto gi_last = last.gpos();
191  // Find the local min. element in parallel
192  // Get local address range between global iterators:
193  auto local_idx_range = dash::local_index_range(first, last);
194  // Pointer to local minimum element:
195  const value_t * lmin = nullptr;
196  // Local offset of local minimum element, or -1 if no element found:
197  index_t l_idx_lmin = -1;
198  if (local_idx_range.begin == local_idx_range.end) {
199  // local range is empty
200  DASH_LOG_DEBUG("dash::min_element", "local range empty");
201  } else {
202  trace.enter_state("local");
203 
204  // Pointer to first element in local memory:
205  auto *lbegin = dash::local_begin(
206  static_cast<typename GlobInputIt::const_pointer>(first), team.myid());
207 
208  // Pointers to first / final element in local range:
209  const auto * l_range_begin = lbegin + local_idx_range.begin;
210  const auto * l_range_end = lbegin + local_idx_range.end;
211 
212  lmin = dash::min_element(l_range_begin, l_range_end, compare);
213 
214  if (lmin != l_range_end) {
215  DASH_LOG_TRACE_VAR("dash::min_element", *lmin);
216  // Offset of local minimum in local memory:
217  l_idx_lmin = lmin - lbegin;
218  }
219 
220  trace.exit_state("local");
221  }
222  DASH_LOG_TRACE("dash::min_element",
223  "local index of local minimum:", l_idx_lmin);
224  DASH_LOG_TRACE("dash::min_element",
225  "waiting for local min of other units");
226 
227  trace.enter_state("barrier");
228  team.barrier();
229  trace.exit_state("barrier");
230 
231  typedef struct {
232  value_t value;
233  index_t g_index;
234  } local_min_t;
235 
236  std::vector<local_min_t> local_min_values(team.size());
237 
238  // Set global index of local minimum to -1 if no local minimum has been
239  // found:
240  local_min_t local_min;
241  local_min.value = l_idx_lmin < 0
242  ? value_t()
243  : *lmin;
244  local_min.g_index = l_idx_lmin < 0
245  ? -1
246  : pattern.global(l_idx_lmin);
247 
248  DASH_LOG_TRACE("dash::min_element", "sending local minimum: {",
249  "value:", local_min.value,
250  "g.index:", local_min.g_index, "}");
251 
252  DASH_LOG_TRACE("dash::min_element", "dart_allgather()");
253  trace.enter_state("allgather");
254  DASH_ASSERT_RETURNS(
256  &local_min,
257  local_min_values.data(),
258  sizeof(local_min_t),
260  team.dart_id()),
261  DART_OK);
262  trace.exit_state("allgather");
263 
264 #ifdef DASH_ENABLE_LOGGING
265  for (int lmin_u = 0; lmin_u < local_min_values.size(); lmin_u++) {
266  auto lmin_entry = local_min_values[lmin_u];
267  DASH_LOG_TRACE("dash::min_element", "dart_allgather >",
268  "unit:", lmin_u,
269  "value:", lmin_entry.value,
270  "g_index:", lmin_entry.g_index);
271  }
272 #endif
273 
274  auto gmin_elem_it = ::std::min_element(
275  local_min_values.begin(),
276  local_min_values.end(),
277  [&](const local_min_t & a,
278  const local_min_t & b) {
279  // Ignore elements with global index -1 (no
280  // element found):
281  return (b.g_index < 0 ||
282  (a.g_index > 0 &&
283  compare(a.value, b.value)));
284  });
285 
286  if (gmin_elem_it == local_min_values.end()) {
287  DASH_LOG_DEBUG_VAR("dash::min_element >", last);
288  return last;
289  }
290 
291  auto gi_minimum = gmin_elem_it->g_index;
292 
293  DASH_LOG_TRACE("dash::min_element",
294  "min. value:", gmin_elem_it->value,
295  "at unit:", (gmin_elem_it - local_min_values.begin()),
296  "global idx:", gi_minimum);
297 
298  DASH_LOG_TRACE_VAR("dash::min_element", gi_minimum);
299  if (gi_minimum < 0 || gi_minimum == gi_last) {
300  DASH_LOG_DEBUG_VAR("dash::min_element >", last);
301  return last;
302  }
303  // iterator 'first' is relative to start of input range, convert to start
304  // of its referenced container (= container.begin()), then apply global
305  // offset of minimum element:
306  auto minimum = (first - first.gpos()) + gi_minimum;
307  DASH_LOG_DEBUG("dash::min_element >", minimum,
308  "=", static_cast<value_t>(*minimum));
309 
310  return minimum;
311 }
DASH_CONSTEXPR std::enable_if< std::is_same< typename dash::memory_space_traits< MemSpaceT >::memory_space_layout_tag, memory_space_contiguous >::value, T >::type * local_begin(GlobPtr< T, MemSpaceT > global_begin, dash::team_unit_t unit)
Returns the begin of the local memory portion within a global memory segment.
Definition: GlobPtr.h:593
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_allgather(const void *sendbuf, void *recvbuf, size_t nelem, dart_datatype_t dtype, dart_team_t team)
DART Equivalent to MPI allgather.
GlobInputIt min_element(const typename std::enable_if< dash::iterator_traits< GlobInputIt >::is_global_iterator::value, GlobInputIt >::type &first, const GlobInputIt &last, Compare compare=Compare())
Finds an iterator pointing to the element with the smallest value in the range [first,last).
Definition: MinMax.h:161
const ElementType * min_element(const ElementType *l_range_begin, const ElementType *l_range_end, Compare compare=std::less< const ElementType &>())
Finds an iterator pointing to the element with the smallest value in the range [first,last).
Definition: MinMax.h:47
#define DART_TYPE_BYTE
integral data types
Definition: dart_types.h:125
std::enable_if< !GlobInputIter::has_view::value, LocalIndexRange< typename GlobInputIter::pattern_type::index_type >>::type local_index_range(const GlobInputIter &first, const GlobInputIter &last)
Resolves the local index range between global iterators.
Definition: LocalRange.h:101

◆ reduce() [1/3]

template<class LocalInputIter , class InitType , class BinaryOperation = dash::plus<typename std::iterator_traits<LocalInputIter>::value_type>, typename = typename std::enable_if< !dash::detail::is_global_iterator<LocalInputIter>::value >::type>
std::iterator_traits<LocalInputIter>::value_type dash::reduce ( LocalInputIter  in_first,
LocalInputIter  in_last,
InitType  init,
BinaryOperation  binary_op = BinaryOperation(),
bool  non_empty = true,
dash::Team team = dash::Team::All() 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Reduce.h>

Accumulate values in each process' range [in_first, in_last) using the provided binary reduce function binary_op, which must be commutative and associative.

The iteration order is not specified and the result is non-deterministic if binary_op is not commutative and associative.

The result type is determined by the type of the elements in the range and the value of init is cast to this type.

Collective operation.

Parameters
in_firstLocal iterator describing the beginning of the range to reduce.
in_lastLocal iterator describing the end of the range to accumualte
initThe initial element to use in the accumulation.
binary_opThe binary operation to apply to reduce two elements (default: using dash::plus)
non_emptyWhether all units are guaranteed to provide a non-empty local range (default false).
teamThe team to use for the collective operation.

Definition at line 79 of file Reduce.h.

References DART_OP_UNDEFINED, and dash::myid().

Referenced by dash::reduce().

86 {
87  using value_t = typename std::iterator_traits<LocalInputIter>::value_type;
88  using local_result_t = struct dash::internal::local_result<value_t>;
89  auto myid = team.myid();
90  auto l_first = in_first;
91  auto l_last = in_last;
92 
93  local_result_t l_result;
94  local_result_t g_result;
95  if (l_first != l_last) {
96  l_result.value = std::accumulate(std::next(l_first),
97  l_last, *l_first,
98  binary_op);
99  l_result.valid = true;
100  }
101  dart_operation_t dop =
102  dash::internal::dart_reduce_operation<BinaryOperation>::value;
104 
105  if (!non_empty || dop == DART_OP_UNDEFINED || dtype == DART_TYPE_UNDEFINED)
106  {
107  dart_type_create_custom(sizeof(local_result_t), &dtype);
108 
109  // we need a custom reduction operation because not every unit
110  // may have valid values
112  &dash::internal::reduce_custom_fn<value_t, BinaryOperation>,
113  &binary_op, true, dtype, true, &dop);
114  dart_allreduce(&l_result, &g_result, 1, dtype, dop, team.dart_id());
115  dart_op_destroy(&dop);
116  dart_type_destroy(&dtype);
117  } else {
118  // ideal case: we can use DART predefined reductions
119  dart_allreduce(&l_result.value, &g_result.value, 1, dtype, dop, team.dart_id());
120  g_result.valid = true;
121  }
122  if (!g_result.valid) {
123  DASH_LOG_ERROR("dash::reduce()", "Found invalid reduction value!");
124  }
125  auto result = g_result.value;
126 
127  result = binary_op(init, result);
128 
129  return result;
130 }
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
dart_ret_t dart_op_destroy(dart_operation_t *op)
Destroy a operation object created through dart_op_create and set op to DART_OP_UNDEFINED.
intptr_t dart_datatype_t
Raw data types supported by the DART interface.
Definition: dart_types.h:121
dart_ret_t dart_type_destroy(dart_datatype_t *dart_type)
Destroy a data type that was previously created using dart_type_create_strided or dart_type_create_in...
dart_ret_t dart_allreduce(const void *sendbuf, void *recvbuf, size_t nelem, dart_datatype_t dtype, dart_operation_t op, dart_team_t team)
DART Equivalent to MPI allreduce.
dart_ret_t dart_type_create_custom(size_t num_bytes, dart_datatype_t *newtype)
Create a custom data type of size num_bytes bytes.
Undefined, do not use.
Definition: dart_types.h:71
Convencience wrapper to determine the DART type and number of elements required for the given templat...
Definition: Types.h:295
void init(int *argc, char ***argv)
Initialize the DASH library and the underlying runtime system.
dart_ret_t dart_op_create(dart_operator_t op, void *userdata, bool commute, dart_datatype_t dtype, bool dtype_is_tmp, dart_operation_t *new_op)
Create a new operation new_op that can be used in collective reduction operations, i.e., dart_reduce, dart_allreduce.
dart_team_t dart_id() const
Index of this team relative to global team dash::Team::All().
Definition: Team.h:522

◆ reduce() [2/3]

template<class LocalInputIter , class InitType = typename std::iterator_traits<LocalInputIter>::value_type, typename = typename std::enable_if< !dash::detail::is_global_iterator<LocalInputIter>::value >::type>
std::iterator_traits<LocalInputIter>::value_type dash::reduce ( LocalInputIter  in_first,
LocalInputIter  in_last,
InitType  init,
bool  non_empty,
dash::Team team = dash::Team::All() 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Reduce.h>

Accumulate values across the local ranges [in_first,in_last) of each process as the sum of all values in the range.

The iteration order is not specified. The reduction is performed using dash::plus.

The result type is determined by the type of the elements in the range and the value of init is cast to this type.

Note
: For equivalent of semantics of MPI_Accumulate, see dash::transform.
Parameters
in_firstLocal pointer describing the beginning of the range to reduce.
in_lastLocal pointer describing the end of the range to accumualte
initThe initial element to use in the accumulation.
non_emptyWhether all units are guaranteed to provide a non-empty local range (default false).
teamThe team to use for the collective operation.

Definition at line 162 of file Reduce.h.

References dash::reduce().

168 {
169  using value_t = typename std::iterator_traits<LocalInputIter>::value_type;
170  return dash::reduce(
171  in_first,
172  in_last,
173  init,
175  non_empty,
176  team);
177 }
Reduce operands to their sum.
Definition: Operation.h:163
std::iterator_traits< LocalInputIter >::value_type reduce(LocalInputIter in_first, LocalInputIter in_last, InitType init, BinaryOperation binary_op=BinaryOperation(), bool non_empty=true, dash::Team &team=dash::Team::All())
Accumulate values in each process&#39; range [in_first, in_last) using the provided binary reduce functio...
Definition: Reduce.h:79
void init(int *argc, char ***argv)
Initialize the DASH library and the underlying runtime system.

◆ reduce() [3/3]

template<class GlobInputIt , class InitType = typename dash::iterator_traits<GlobInputIt>::value_type, class BinaryOperation = dash::plus<typename dash::iterator_traits<GlobInputIt>::value_type>, typename = typename std::enable_if< dash::detail::is_global_iterator<GlobInputIt>::value >::type>
dash::iterator_traits<GlobInputIt>::value_type dash::reduce ( GlobInputIt  in_first,
GlobInputIt  in_last,
InitType  init,
BinaryOperation  binary_op = BinaryOperation() 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Reduce.h>

Accumulate values in the global range [in_first, in_last) using the provided binary reduce function binary_op, which must be commutative and linear.

The iteration order is not specified and the result is non-deterministic if binary_op is not commutative and associative.

The result type is determined by the type of the elements in the range and the value of init is cast to this type.

Collective operation.

Parameters
in_firstGlobal iterator describing the beginning of the range to reduce.
in_lastGlobal iterator describing the end of the range to accumualte
initThe initial element to use in the accumulation.
binary_opThe associative, commutative binary operation to apply.
Note
: For equivalent of semantics of MPI_Accumulate, see dash::transform.

Definition at line 212 of file Reduce.h.

References dash::local_range(), and dash::reduce().

217 {
218  auto & team = in_first.team();
219  auto index_range = dash::local_range(in_first, in_last);
220  auto l_first = index_range.begin;
221  auto l_last = index_range.end;
222 
223  // TODO: can we figure out whether or not units are empty?
224  static constexpr bool units_non_empty = false;
225  return dash::reduce(l_first,
226  l_last,
227  init,
228  binary_op,
229  units_non_empty,
230  team);
231 }
std::iterator_traits< LocalInputIter >::value_type reduce(LocalInputIter in_first, LocalInputIter in_last, InitType init, BinaryOperation binary_op=BinaryOperation(), bool non_empty=true, dash::Team &team=dash::Team::All())
Accumulate values in each process&#39; range [in_first, in_last) using the provided binary reduce functio...
Definition: Reduce.h:79
LocalRange< const typename GlobIterType::value_type > local_range(const GlobIterType &first, const GlobIterType &last)
Resolves the local address range between global iterators.
Definition: LocalRange.h:295
void init(int *argc, char ***argv)
Initialize the DASH library and the underlying runtime system.

◆ sort() [1/2]

template<class GlobRandomIt >
void dash::sort ( GlobRandomIt  begin,
GlobRandomIt  end 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Sort.h>

Sorts the elements in the range, defined by [begin, end) in ascending order.

The order of equal elements is not guaranteed to be preserved.

Elements are sorted using operator<. Additionally, the elements must be arithmetic, i.e. std::is_arithmetic<T> must be satisfied.

In terms of data distribution, source and destination ranges passed to dash::sort must be global (GlobIter<ValueType>).

The operation is collective among the team of the owning dash container.

Example:

dash::generate(arr.begin(), arr.end());
dash::sort(array.begin(),
array.end();

◆ sort() [2/2]

template<class GlobRandomIt , class SortableHash >
void dash::sort ( GlobRandomIt  begin,
GlobRandomIt  end,
SortableHash  hash 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Sort.h>

Sorts the elements in the range, defined by [begin, end) in ascending order.

The order of equal elements is not guaranteed to be preserved.

Elements are sorted by using a user-defined hash function. Resulting values of the hash function are required to be sortable by operator<.

This variant may be appropriate if the underlying container does not hold arithmetic values (e.g. structs).

In terms of data distribution, source and destination ranges passed to dash::sort must be global (GlobIter<ValueType>).

The operation is collective among the team of the owning dash container.

Example:

struct pair { int x; int y; };
dash::generate(arr.begin(), arr.end(), random());
dash::sort(array.begin(),
array.end(),
[](pair const & p){return p.x % 13; }
);

◆ transform() [1/2]

template<typename ValueType , class InputIt , class OutputIt , class UnaryOperation >
OutputIt dash::transform ( InputIt  in_first,
InputIt  in_last,
OutputIt  out_first,
UnaryOperation  unary_op 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Transform.h>

Apply a given function to elements in a range and store the result in another range, beginning at out_first.

Corresponding to MPI_Accumulate, the unary operation is executed atomically on single elements.

Precondition: All elements in the input range are contained in a single block so that

g_out_last == g_out_first + (l_in_last - l_in_first)

Semantics:

unary_op(in_first[0]), unary_op(in_first[1]), ..., unary_op(in_first[n])

Returns
Output iterator to the element past the last element transformed.

Referenced by dash::LoadBalancePattern< 1, CompBasedMeasure, MemBasedMeasure, Arrangement, IndexType >::ndim(), and dash::UnitClockFreqMeasure::unit_weights().

◆ transform() [2/2]

template<class InputIt1 , class GlobInputIt , class GlobOutputIt , class BinaryOperation >
GlobOutputIt dash::transform ( InputIt1  in_a_first,
InputIt1  in_a_last,
GlobInputIt  in_b_first,
GlobOutputIt  out_first,
BinaryOperation  binary_op 
)

#include </tmp/tmporruphar/dash/include/dash/algorithm/Transform.h>

Apply a given function to pairs of elements from two ranges and store the result in another range, beginning at out_first.

Corresponding to MPI_Accumulate, the binary operation is executed atomically on single elements.

Precondition: All elements in the input range are contained in a single block so that

g_out_last == g_out_first + (l_in_last - l_in_first)

Semantics:

binary_op(in_a[0], in_b[0]), binary_op(in_a[1], in_b[1]), ..., binary_op(in_a[n], in_b[n])

Example:

gptr_diff_t num_transformed_elements =
dash::transform(in.begin(), in.end(), // A
out.begin(), // B
out.begin(), // C = op(A, B)
dash::plus<int>()), // op
out.end());
Returns
Output iterator to the element past the last element transformed.
See also
dash::reduce
DASH Reduce Operations
Template Parameters
InputItIterator on first (local) input range
GlobInputItIterator on second (global) input range
GlobOutputItIterator on global result range
BinaryOperationReduce operation type
Parameters
in_a_firstIterator on begin of first local range
in_a_lastIterator after last element of local range
in_b_firstIterator on begin of second local range
out_firstIterator on first element of global output range
binary_opReduce operation