1 #ifndef DASH__ALGORITHM__FIND_H__ 2 #define DASH__ALGORITHM__FIND_H__ 4 #include <dash/Array.h> 5 #include <dash/algorithm/LocalRange.h> 6 #include <dash/algorithm/Operation.h> 8 #include <dash/iterator/GlobIter.h> 28 const ElementType & value)
34 using p_index_t =
typename iterator_traits::index_type;
41 auto & pattern = first.pattern();
42 auto & team = pattern.team();
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();
50 auto g_begin_index = pattern.global(l_begin_index);
54 static_cast<typename GlobIter::pointer>(first), team.myid());
56 const auto l_range_begin = lbegin + l_begin_index;
57 const auto l_range_end = lbegin + l_end_index;
59 DASH_LOG_DEBUG(
"local index range", l_begin_index, l_end_index);
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();
66 auto l_hit_index = l_result - lbegin;
67 g_index = pattern.global(l_hit_index);
85 if (g_hit_idx == std::numeric_limits<p_index_t>::max()) {
86 DASH_LOG_DEBUG(
"element not found");
88 return first + g_hit_idx;
103 template <
typename GlobIter,
typename UnaryPredicate>
110 UnaryPredicate predicate)
114 using index_t =
typename iterator_traits::index_type;
116 auto& team = first.pattern().team();
117 auto myid = team.myid();
120 auto l_first = index_range.begin;
121 auto l_last = index_range.end;
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);
128 l_results.
local[0] = l_offset;
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();
159 class UnaryPredicate>
166 UnaryPredicate predicate)
168 return find_if(first, last, std::not1(predicate));
173 #endif // DASH__ALGORITHM__FIND_H__ 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.
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
This class is a simple memory pool which holds allocates elements of size ValueType.
RandomAccessIt::difference_type distance(const RandomAccessIt &first, const RandomAccessIt &last)
Resolve the number of elements between two iterators.
LocalRange< const typename GlobIterType::value_type > local_range(const GlobIterType &first, const GlobIterType &last)
Resolves the local address range between global iterators.
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...
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...
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.
Iterator on Partitioned Global Address Space.
DASH_CONSTEXPR index_type pos() const DASH_NOEXCEPT
Position of the iterator in global index space.
Type trait for mapping to DART data types.
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...
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.
local_type local
Local proxy object, allows use in range-based for loops.