DASH  0.3.0
LocalMatrixRef.h
1 #ifndef DASH__MATRIX__LOCAL_MATRIX_REF_H__
2 #define DASH__MATRIX__LOCAL_MATRIX_REF_H__
3 
4 #include <dash/dart/if/dart.h>
5 
6 #include <dash/Team.h>
7 #include <dash/Pattern.h>
8 #include <dash/GlobRef.h>
9 #include <dash/HView.h>
10 
11 #include <dash/iterator/GlobIter.h>
12 #include <dash/iterator/GlobViewIter.h>
13 
14 #include <dash/Matrix.h>
15 
16 
17 namespace dash {
18 
20 template <
21  typename T,
22  dim_t NumDimensions,
23  typename IndexT,
24  class PatternT,
25  typename LocalMemT>
26 class Matrix;
28 template <
29  typename T,
30  dim_t NumDimensions,
31  dim_t CUR,
32  class PatternT,
33  typename LocalMemT>
34 class MatrixRef;
36 template <
37  typename T,
38  dim_t NumDimensions,
39  dim_t CUR,
40  class PatternT,
41  typename LocalMemT>
43 
51 template <
52  typename T,
53  dim_t NumDimensions,
54  dim_t CUR,
55  class PatternT,
56  class LocalMemT>
57 class LocalMatrixRef
58 {
59 private:
61 
64  typedef std::array<typename PatternT::size_type, NumDimensions>
65  Extents_t;
66  typedef std::array<typename PatternT::index_type, NumDimensions>
67  Offsets_t;
69  ViewSpec_t;
70  template <dim_t NumViewDim>
71  using LocalMatrixRef_t =
73 
74  typedef Matrix<
75  T,
76  NumDimensions,
77  typename PatternT::index_type,
78  PatternT,
79  LocalMemT>
80  matrix_t;
81 
82  typedef typename matrix_t::GlobMem_t GlobMem_t;
83 
84 public:
85  template<
86  typename T_,
87  dim_t NumDimensions_,
88  typename IndexT_,
89  class PatternT_,
90  typename MSpaceC_>
91  friend class Matrix;
92  template<
93  typename T_,
94  dim_t NumDimensions1,
95  dim_t NumDimensions2,
96  class PatternT_,
97  typename MSpaceC_>
98  friend class LocalMatrixRef;
99 
100 public:
101  typedef T value_type;
102  typedef PatternT pattern_type;
103  typedef typename PatternT::index_type index_type;
104 
105  typedef typename PatternT::size_type size_type;
106  typedef typename PatternT::index_type difference_type;
107 
110 
111  typedef std::reverse_iterator<iterator> reverse_iterator;
112  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
113 
116 
119 
120  typedef T * local_pointer;
121  typedef const T * const_local_pointer;
122 
123  typedef self_t local_type;
124 
125  template <dim_t NumViewDim>
126  using ViewT =
128 
129 public:
130  typedef std::integral_constant<dim_t, CUR>
131  rank;
132 
133  static constexpr dim_t ndim() {
134  return CUR;
135  }
136 
137 protected:
139  MatrixRefView_t && refview)
140  : _refview(std::move(refview))
141  {
142  DASH_LOG_TRACE_VAR("LocalMatrixRef<T,D,C>()", NumDimensions);
143  DASH_LOG_TRACE_VAR("LocalMatrixRef<T,D,C>()", CUR);
144  }
145 
147  const MatrixRefView_t & refview)
148  : _refview(refview)
149  {
150  DASH_LOG_TRACE_VAR("LocalMatrixRef<T,D,C>()", NumDimensions);
151  DASH_LOG_TRACE_VAR("LocalMatrixRef<T,D,C>()", CUR);
152  }
153 
154 public:
159  {
160  DASH_LOG_TRACE_VAR("LocalMatrixRef<T,D,C>()", NumDimensions);
161  DASH_LOG_TRACE_VAR("LocalMatrixRef<T,D,C>()", CUR);
162  }
163 
164  template <class T_>
167  size_type coord);
168 
172  template <class T_>
175  );
176 
181  const std::array<index_type, NumDimensions> & block_lcoords
182  );
183 
188  index_type block_lindex
189  );
190 
191  inline operator LocalMatrixRef<T, NumDimensions, CUR-1, PatternT, LocalMemT> && () &&;
192 
193  // SHOULD avoid cast from MatrixRef to LocalMatrixRef.
194  // Different operation semantics.
196 
201  inline T & local_at(size_type pos);
202  inline const T & local_at(size_type pos) const;
203 
204  constexpr Team & team() const noexcept;
205 
206  constexpr size_type size() const noexcept;
207  constexpr size_type local_size() const noexcept;
208  constexpr size_type local_capacity() const noexcept;
209  inline size_type extent(dim_t dim) const noexcept;
210  constexpr Extents_t extents() const noexcept;
211  inline index_type offset(dim_t dim) const noexcept;
212  constexpr Offsets_t offsets() const noexcept;
213  constexpr bool empty() const noexcept;
214 
223  constexpr const PatternT & pattern() const;
224 
225  inline iterator begin() noexcept;
226  constexpr const_iterator begin() const noexcept;
227  inline iterator end() noexcept;
228  constexpr const_iterator end() const noexcept;
229 
230  inline local_pointer lbegin() noexcept;
231  constexpr const_local_pointer lbegin() const noexcept;
232  inline local_pointer lend() noexcept;
233  constexpr const_local_pointer lend() const noexcept;
234 
243  template<typename ... Args>
244  inline T & at(
246  Args... args);
247 
257  template<typename... Args>
258  inline T & operator()(
260  Args... args);
261 
266  template<dim_t __NumViewDim = CUR-1>
267  typename std::enable_if<(__NumViewDim > 0),
269  operator[](size_type n);
270 
271  template<dim_t __NumViewDim = CUR-1>
272  typename std::enable_if<(__NumViewDim == 0), T&>::type
273  operator[](size_type n);
274 
279  template<dim_t __NumViewDim = CUR-1>
280  typename std::enable_if<(__NumViewDim > 0),
282  constexpr operator[](size_type n) const;
283 
284  template<dim_t __NumViewDim = CUR-1>
285  typename std::enable_if<(__NumViewDim == 0), const T&>::type
286  operator[](size_type n) const;
287 
288  LocalMatrixRef<T, NumDimensions, NumDimensions-1, PatternT, LocalMemT>
289  col(size_type n);
290  constexpr LocalMatrixRef<const T, NumDimensions, NumDimensions-1, PatternT, LocalMemT>
291  col(size_type n) const;
292 
293  LocalMatrixRef<T, NumDimensions, NumDimensions-1, PatternT, LocalMemT>
294  row(size_type n);
295  constexpr LocalMatrixRef<const T, NumDimensions, NumDimensions-1, PatternT, LocalMemT>
296  row(size_type n) const;
297 
298  template<dim_t NumSubDimensions>
299  LocalMatrixRef<T, NumDimensions, NumDimensions-1, PatternT, LocalMemT>
300  sub(size_type n);
301 
302  template<dim_t NumSubDimensions>
303  LocalMatrixRef<const T, NumDimensions, NumDimensions-1, PatternT, LocalMemT>
304  sub(size_type n) const;
305 
306  template<dim_t SubDimension>
308  sub(size_type n,
309  size_type range);
310 
311  template<dim_t SubDimension>
313  sub(size_type n,
314  size_type range) const;
315 
326  rows(
328  size_type offset,
330  size_type range);
331 
333  rows(
335  size_type offset,
337  size_type range) const;
338 
349  cols(
351  size_type offset,
353  size_type extent);
354 
356  cols(
358  size_type offset,
360  size_type extent) const;
361 
362 private:
363 
364  MatrixRefView_t _refview;
365 };
366 
367 } // namespace dash
368 
369 #include <dash/matrix/internal/LocalMatrixRef-inl.h>
370 
371 #endif
constexpr dim_t rank(const DimensionalType &d)
Definition: Dimensional.h:64
T & operator()(Args... args)
Fortran-style subscript operator, alias for at().
Forward-declaration.
size_t size()
Return the number of units in the global team.
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
Global iterator on an index set specified by a view modifier.
Definition: GlobViewIter.h:40
Specifies view parameters for implementing submat, rows and cols.
Definition: Dimensional.h:430
std::enable_if<(__NumViewDim > 0), LocalMatrixRef< T, NumDimensions, __NumViewDim, PatternT, LocalMemT > >::type operator[](size_type n)
Subscript assignment operator, access element at given offset in global element range.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
Definition: Range.h:89
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
LocalMatrixRef< T, NumDimensions, CUR, PatternT, LocalMemT > block(const std::array< index_type, NumDimensions > &block_lcoords)
View at local block at given local block coordinates.
LocalMatrixRef< T, NumDimensions, NumDimensions, PatternT, LocalMemT > rows(size_type offset, size_type range)
Create a view representing the matrix slice within a row range.
Stores information needed by subscripting and subdim selection.
Definition: MatrixRefView.h:57
A Team instance specifies a subset of all available units.
Definition: Team.h:41
constexpr dim_t ndim(const DimensionalType &d)
Definition: Dimensional.h:56
constexpr const PatternT & pattern() const
The pattern used to distribute matrix elements to units in its associated team.
T & at(Args... args)
Fortran-style subscript operator.
T & local_at(size_type pos)
Returns a reference to the element at local index pos.
constexpr DimensionalType::extent_type extent(const DimensionalType &d)
Definition: Dimensional.h:73
Forward-declaration.
constexpr ViewSubMod< ViewOrigin< NViewDim >, SubDim > sub(OffsetFirstT begin, OffsetFinalT end)
Sub-section, view dimensions maintain domain dimensions.
Definition: Sub.h:27
Forward-declaration.
LocalMatrixRef< T, NumDimensions, NumDimensions, PatternT, LocalMemT > cols(size_type offset, size_type extent)
Create a view representing the matrix slice within a column range.