DASH  0.3.0
HView.h
1 #ifndef DASH__HVIEW_H_INCLUDED
2 #define DASH__HVIEW_H_INCLUDED
3 
4 #include <dash/Team.h>
5 #include <dash/pattern/BlockPattern.h>
6 
7 #include <iostream>
8 
9 
10 namespace dash {
11 
12 template<class ContainerType, int LEVEL>
13 class HIter : public ContainerType::iterator
14 {
15 private:
16  BlockPattern<1> & m_pattern;
17  Team & m_subteam;
18 
19 public:
20  HIter<ContainerType,LEVEL>& advance() {
21  auto idx = ContainerType::iterator::m_idx;
22  for(; idx < m_pattern.capacity(); idx++) {
23  auto unit = m_pattern.unit_at(idx);
24  if (m_subteam.is_member(unit)) {
25  break;
26  }
27  }
28  ContainerType::iterator::m_idx = idx;
29  return *this;
30  }
31 
32 public:
33  HIter(
34  typename ContainerType::iterator it,
35  BlockPattern<1> & pattern,
36  Team & subteam)
37  : ContainerType::iterator(it),
38  m_pattern(pattern),
39  m_subteam(subteam) {
40  }
41 
42  HIter<ContainerType,LEVEL>& operator++() {
43  ContainerType::iterator::m_idx++;
44  return advance();
45  }
46 };
47 
48 template<class ContainerType, int LEVEL>
49 class HView
50 {
51 public:
52  typedef typename ContainerType::iterator iterator;
53  typedef typename ContainerType::value_type value_type;
54 
55 private:
56  ContainerType & m_container;
57  Team & m_subteam;
58  BlockPattern<1> & m_pat;
59 
62 
63  HIter<ContainerType,LEVEL> find_begin()
64  {
66  m_container.begin(),
67  m_pat,
68  m_subteam
69  };
70  it.advance();
71  return it;
72  }
73 
75  {
76  return {
77  m_container.end(),
78  m_pat,
79  m_subteam
80  };
81  }
82 
83 public:
84  HView(ContainerType& cont)
85  : m_container(cont),
86  m_subteam(cont.team().sub(LEVEL)),
87  m_pat(cont.pattern()),
88  m_begin(find_begin()),
89  m_end(find_end())
90  { }
91 
93  return m_begin;
94  }
95 
97  return m_end;
98  }
99 };
100 
101 template<class ContainerType>
102 class HView<ContainerType, -1> {
103 public:
104  typedef typename ContainerType::iterator iterator;
105  typedef typename ContainerType::value_type value_type;
106 
107 private:
108  Team & m_subteam;
109  ContainerType & m_container;
110  BlockPattern<1> & m_pat;
111 
112 public:
113  HView(ContainerType& cont)
114  : m_container(cont),
115  m_subteam(cont.team()),
116  m_pat(cont.pattern()) {
117  };
118 
119  value_type* begin() {
120  return m_container.lbegin();
121  }
122 
123  value_type* end() {
124  return m_container.lend();
125  }
126 };
127 
128 } // namespace dash
129 
130 #endif /* HVIEW_H_INCLUDED */
constexpr IndexType capacity() const noexcept
The maximum number of elements arranged in this pattern.
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
Definition: Range.h:98
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
Definition: Range.h:89
A Team instance specifies a subset of all available units.
Definition: Team.h:41
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords, const ViewSpec_t &viewspec) const
unit_at
Definition: BlockPattern.h:430
bool is_member(global_unit_t global_unit_id) const
Whether the group associated with this Team instance contains the unit specified by global id...
Definition: Team.h:437