1 #ifndef DASH__MAP__UNORDERED_MAP_GLOB_ITER_H__INCLUDED 2 #define DASH__MAP__UNORDERED_MAP_GLOB_ITER_H__INCLUDED 6 #include <dash/Types.h> 7 #include <dash/memory/GlobHeapPtr.h> 8 #include <dash/GlobSharedRef.h> 9 #include <dash/Allocator.h> 10 #include <dash/Team.h> 11 #include <dash/Onesided.h> 13 #include <dash/map/UnorderedMapLocalIter.h> 15 #include <dash/internal/Logging.h> 17 #include <type_traits> 42 :
public std::iterator<
43 std::random_access_iterator_tag,
44 std::pair<const Key, Mapped>,
45 dash::default_index_t,
46 GlobHeapPtr<std::pair<const Key, Mapped>, GlobMemType>,
47 GlobSharedRef<std::pair<const Key, Mapped>, GlobMemType>> {
48 template<
typename K_,
typename M_,
typename H_,
typename P_,
typename G_>
51 template<
typename K_,
typename M_,
typename H_,
typename P_,
typename G_>
52 friend std::ostream & dash::operator<<(
69 typedef typename map_t::value_type value_type;
79 typedef value_type* raw_pointer;
80 typedef const value_type* const_raw_pointer;
84 std::is_const<value_type>::value,
111 _myid(map->team().
myid()),
115 DASH_LOG_TRACE_VAR(
"UnorderedMapGlobIter(map,pos)", _idx);
117 DASH_LOG_TRACE(
"UnorderedMapGlobIter(map,pos) >");
130 _myid(map->team().
myid()),
132 _idx_local_idx(local_index)
134 DASH_LOG_TRACE(
"UnorderedMapGlobIter(map,unit,lidx)()");
135 DASH_LOG_TRACE_VAR(
"UnorderedMapGlobIter(map,unit,lidx)", unit);
136 DASH_LOG_TRACE_VAR(
"UnorderedMapGlobIter(map,unit,lidx)", local_index);
138 size_type unit_l_cumul_size_prev = 0;
140 unit_l_cumul_size_prev = _map->_local_cumul_sizes[unit-1];
142 _idx = unit_l_cumul_size_prev + _idx_local_idx;
143 DASH_LOG_TRACE_VAR(
"UnorderedMapGlobIter(map,unit,lidx)", _idx);
144 DASH_LOG_TRACE(
"UnorderedMapGlobIter(map,unit,lidx) >");
151 const self_t & other) =
default;
157 const self_t & other) =
default;
168 DASH_LOG_TRACE(
"UnorderedMapGlobIter(nullptr)");
180 constexpr
bool operator==(std::nullptr_t)
const noexcept
185 constexpr
bool operator!=(std::nullptr_t)
const noexcept
205 constexpr
operator pointer()
const 218 return _map->globmem().at(
233 auto l_map_it =
local();
234 DASH_ASSERT_MSG(l_map_it !=
nullptr,
235 "Converting global iterator at local position to " 236 "local iterator failed");
238 return reference(static_cast<raw_pointer>(l_map_it));
253 auto l_map_it =
local();
254 DASH_ASSERT_MSG(l_map_it !=
nullptr,
255 "Converting global iterator at local position to " 256 "local iterator failed");
258 return reference(static_cast<raw_pointer>(l_map_it));
268 pointer operator->()
const 270 return static_cast<pointer
>(*this);
280 return (_myid == _idx_unit_id);
288 if (_myid != _idx_unit_id) {
290 return local_iterator(
nullptr);
292 return (_map->lbegin() + _idx_local_idx);
300 if (_myid != _idx_unit_id) {
302 return local_iterator(
nullptr);
304 return (_map->lbegin() + _idx_local_idx);
313 local_pos.unit = _idx_unit_id;
314 local_pos.index = _idx_local_idx;
329 constexpr index_type
pos() const noexcept
337 constexpr index_type
gpos() const noexcept
380 template<
typename K_,
typename M_,
typename H_,
typename P_,
typename A_>
381 constexpr
bool operator==(
384 return (
this == std::addressof(other) || _idx == other._idx);
387 template<
typename K_,
typename M_,
typename H_,
typename P_,
typename A_>
388 constexpr
bool operator!=(
391 return !(*
this == other);
394 self_t & operator+=(index_type offset)
400 self_t & operator-=(index_type offset)
406 self_t operator+(index_type offset)
const 413 self_t operator-(index_type offset)
const 420 constexpr index_type operator+(
421 const self_t & other)
const noexcept
423 return _idx + other._idx;
426 constexpr index_type operator-(
427 const self_t & other)
const noexcept
429 return _idx - other._idx;
432 template<
typename K_,
typename M_,
typename H_,
typename P_,
typename A_>
436 return (_idx < other._idx);
439 template<
typename K_,
typename M_,
typename H_,
typename P_,
typename A_>
443 return (_idx <= other._idx);
446 template<
typename K_,
typename M_,
typename H_,
typename P_,
typename A_>
450 return (_idx > other._idx);
453 template<
typename K_,
typename M_,
typename H_,
typename P_,
typename A_>
457 return (_idx >= other._idx);
464 void increment(index_type offset)
466 DASH_LOG_TRACE(
"UnorderedMapGlobIter.increment()",
467 "gidx:", _idx,
"-> (",
468 "unit:", _idx_unit_id,
469 "lidx:", _idx_local_idx,
")",
491 _idx_local_idx = _idx;
492 auto & l_cumul_sizes = _map->_local_cumul_sizes;
494 while (_idx >= l_cumul_sizes[_idx_unit_id] &&
495 _idx_unit_id < l_cumul_sizes.size() - 1) {
496 DASH_LOG_TRACE(
"UnorderedMapGlobIter.increment",
497 "local cumulative size of unit", _idx_unit_id,
":",
498 l_cumul_sizes[_idx_unit_id]);
501 if (_idx_unit_id > 0) {
502 _idx_local_idx = _idx - l_cumul_sizes[_idx_unit_id-1];
505 DASH_LOG_TRACE(
"UnorderedMapGlobIter.increment >", *
this);
511 void decrement(index_type offset)
513 DASH_LOG_TRACE(
"UnorderedMapGlobIter.decrement()",
514 "gidx:", _idx,
"-> (",
515 "unit:", _idx_unit_id,
516 "lidx:", _idx_local_idx,
")",
520 }
else if (offset > 0) {
523 _idx_local_idx = _idx;
525 DASH_LOG_TRACE(
"UnorderedMapGlobIter.decrement >", *
this);
530 map_t * _map =
nullptr;
532 index_type _idx = -1;
538 index_type _idx_local_idx = -1;
540 bool _is_nullptr =
false;
549 typename GlobMemType >
550 std::ostream & operator<<(
553 Key, Mapped, Hash, Pred, GlobMemType> & it)
555 std::ostringstream ss;
556 ss <<
"dash::UnorderedMapGlobIter<" 557 <<
typeid(Key).name() <<
"," 558 <<
typeid(Mapped).name() <<
">" 560 <<
"idx:" << it._idx <<
", " 561 <<
"unit:" << it._idx_unit_id <<
", " 562 <<
"lidx:" << it._idx_local_idx
564 return operator<<(os, ss.str());
569 #endif // DASH__MAP__UNORDERED_MAP_GLOB_ITER_H__INCLUDED reference operator[](index_type offset)
Random access operator.
UnorderedMapGlobIter(map_t *map, index_type position)
Constructor, creates iterator at specified global position.
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
internal::default_unsigned_index default_size_t
Unsigned integer type used as default for size values.
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
This class is a simple memory pool which holds allocates elements of size ValueType.
self_t & operator=(const self_t &other)=default
Assignment operator.
constexpr index_type gpos() const noexcept
Position of the iterator in global index range.
self_t operator--(int)
Postfix decrement operator.
UnorderedMapGlobIter()
Default constructor.
constexpr dart_gptr_t dart_gptr() const
Explicit conversion to dart_gptr_t.
self_t operator++(int)
Postfix increment operator.
UnorderedMapGlobIter(map_t *map, team_unit_t unit, index_type local_index)
Constructor, creates iterator at local position relative to the specified unit's local iteration spac...
constexpr bool operator<=(const Pair< T1, T2 > &x, const Pair< T1, T2 > &y)
Less-than-or-equal operator implemented in terms of less-than operator.
self_t & operator++()
Prefix increment operator.
const_reference operator*() const
Dereference operator.
const_local_iterator local() const
Conversion to local bucket iterator.
constexpr bool operator>=(const Pair< T1, T2 > &x, const Pair< T1, T2 > &y)
Greater-than-or-equal operator implemented in terms of less-than operator.
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
local_index lpos() const noexcept
Unit and local offset at the iterator's position.
constexpr bool operator>(const Pair< T1, T2 > &x, const Pair< T1, T2 > &y)
Greater-than operator implemented in terms of less-than operator.
UnorderedMapGlobIter(std::nullptr_t)
Null-pointer constructor.
Iterator on global buckets.
DART Global pointer type.
self_t & operator--()
Prefix decrement operator.
constexpr index_type pos() const noexcept
Position of the iterator in global index space.
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
constexpr bool is_local() const noexcept
Checks whether the element referenced by this global iterator is in the calling unit's local memory...
self_t & operator=(std::nullptr_t) noexcept
Null-pointer assignment operator.
reference operator*()
Dereference operator.
constexpr self_t global() const noexcept
Map iterator to global index domain.
#define DART_UNDEFINED_UNIT_ID
Undefined unit ID.
constexpr bool operator<(const Pair< T1, T2 > &x, const Pair< T1, T2 > &y)
A pair is smaller than another pair if the first member is smaller or the first is equal and the seco...
local_iterator local()
Conversion to local bucket iterator.