DASH  0.3.0
Domain.h
1 #ifndef DASH__DOMAIN_H__INCLUDED
2 #define DASH__DOMAIN_H__INCLUDED
3 
4 #include <array>
5 #include <algorithm>
6 #include <iostream>
7 
8 #include <dash/Types.h>
9 #include <dash/internal/Logging.h>
10 
11 
12 namespace dash {
13 
14 template<
15  dim_t NumDim,
16  typename IndexType = dash::default_index_t >
17 class Domain
18 {
19 
20 private:
21 
23 
24 public:
25 
33  Domain(const std::initializer_list<std::array<IndexType, 2>> & ranges) {
34  DASH_ASSERT_EQ(
35  NumDim, ranges.size(),
36  "wrong number of dimensions in domain ranges");
37  dim_t d = 0;
38  for (auto & range : ranges) {
39  _extents[d] = range[1] - range[0];
40  _offsets[d] = range[0];
41  d++;
42  }
43  }
44 
45  self_t & translate(
46  const std::array<IndexType, NumDim> & offs) {
47  std::transform(_offsets.begin(), _offsets.end(),
48  offs.begin(),
49  _offsets.begin(),
50  std::plus<IndexType>());
51  return *this;
52  }
53 
54  self_t & resize(
55  const std::array<IndexType, NumDim> & extents) {
56  _extents = extents;
57  }
58 
59  self_t & expand(
60  const std::array<IndexType, NumDim> & ext) {
61  std::transform(_extents.begin(), _extents.end(),
62  ext.begin(),
63  _extents.begin(),
64  std::plus<IndexType>());
65  return *this;
66  }
67 
68  IndexType offset(dim_t d) const {
69  return _offsets[d];
70  }
71 
72  std::array<IndexType, NumDim> offsets() const {
73  return _offsets;
74  }
75 
76  IndexType extent(dim_t d) const {
77  return _extents[d];
78  }
79 
80  std::array<IndexType, NumDim> extents() const {
81  return _extents;
82  }
83 
84 private:
85 
86  std::array<IndexType, NumDim> _offsets;
87  std::array<IndexType, NumDim> _extents;
88 
89 };
90 
91 template<dim_t D, typename I>
92 std::ostream & operator<<(
93  std::ostream & os,
94  const dash::Domain<D,I> & dom) {
95  os << "dash::Domain { ";
96  os << "extents(" << dom.extents() << "), ";
97  os << "offsets(" << dom.offsets() << ")";
98  os << " }";
99  return os;
100 }
101 
102 } // namespace dash
103 
104 #endif // DASH__DOMAIN_H__INCLUDED
Domain(const std::initializer_list< std::array< IndexType, 2 >> &ranges)
Example:
Definition: Domain.h:33
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
Definition: Types.h:59
OutputIt transform(InputIt in_first, InputIt in_last, OutputIt out_first, UnaryOperation unary_op)
Apply a given function to elements in a range and store the result in another range, beginning at out_first.