1 #ifndef DASH__ALGORITHM__FOR_EACH_H__ 2 #define DASH__ALGORITHM__FOR_EACH_H__ 4 #include <dash/algorithm/LocalRange.h> 5 #include <dash/iterator/GlobIter.h> 31 template <
typename GlobInputIt,
class UnaryFunction>
34 const GlobInputIt&
first,
36 const GlobInputIt& last,
42 iterator_traits::is_global_iterator::value,
43 "must be a global iterator");
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) {
51 auto & pattern = first.pattern();
53 auto lrange_begin = (first + pattern.global(lbegin_index)).
local();
54 auto lrange_end = lrange_begin + lend_index;
79 template <
typename GlobInputIt,
class UnaryFunctionWithIndex>
82 const GlobInputIt&
first,
84 const GlobInputIt& last,
86 UnaryFunctionWithIndex func)
90 iterator_traits::is_global_iterator::value,
91 "must be a global iterator");
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) {
100 auto & pattern = first.pattern();
101 auto first_offset = first.pos();
103 for (
auto lindex = lbegin_index;
104 lindex != lend_index;
106 auto gindex = pattern.global(lindex);
107 auto element_it = first + (gindex - first_offset);
108 func(*(element_it.local()), gindex);
116 #endif // DASH__ALGORITHM__FOR_EACH_H__ 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
This class is a simple memory pool which holds allocates elements of size ValueType.
void 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.
void for_each(const GlobInputIt &first, const GlobInputIt &last, UnaryFunction func)
Invoke a function on every element in a range distributed by a pattern.
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.