DIY 3.0 data-parallel out-of-core C++ library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List

All Classes Namespaces Functions Typedefs Groups Pages
types.hpp
1 #ifndef DIY_TYPES_HPP
2 #define DIY_TYPES_HPP
3
4 #include <iostream>
5 #include "constants.h"
6 #include "point.hpp"
7
8 namespace diy
9 {
10 struct BlockID
11 {
12 int gid, proc;
13 };
14
15 template<class Coordinate_>
16 struct Bounds
17 {
18 using Coordinate = Coordinate_;
19
20 Point<Coordinate, DIY_MAX_DIM> min, max;
21 };
22 using DiscreteBounds = Bounds<int>;
23 using ContinuousBounds = Bounds<float>;
24
26 inline
27 diy::DiscreteBounds
28 interval(int from, int to) { DiscreteBounds domain; domain.min[0] = from; domain.max[0] = to; return domain; }
29
30 struct Direction: public Point<int,DIY_MAX_DIM>
31 {
32 Direction() { for (size_t i = 0; i < DIY_MAX_DIM; ++i) (*this)[i] = 0; }
33 Direction(int dir)
34 {
35 for (size_t i = 0; i < DIY_MAX_DIM; ++i) (*this)[i] = 0;
36 if (dir & DIY_X0) (*this)[0] -= 1;
37 if (dir & DIY_X1) (*this)[0] += 1;
38 if (dir & DIY_Y0) (*this)[1] -= 1;
39 if (dir & DIY_Y1) (*this)[1] += 1;
40 if (dir & DIY_Z0) (*this)[2] -= 1;
41 if (dir & DIY_Z1) (*this)[2] += 1;
42 if (dir & DIY_T0) (*this)[3] -= 1;
43 if (dir & DIY_T1) (*this)[3] += 1;
44 }
45
46 bool
47 operator==(const diy::Direction& y) const
48 {
49 for (size_t i = 0; i < DIY_MAX_DIM; ++i)
50 if ((*this)[i] != y[i]) return false;
51 return true;
52 }
53
54 // lexicographic comparison
55 bool
56 operator<(const diy::Direction& y) const
57 {
58 for (size_t i = 0; i < DIY_MAX_DIM; ++i)
59 {
60 if ((*this)[i] < y[i]) return true;
61 if ((*this)[i] > y[i]) return false;
62 }
63 return false;
64 }
65 };
66
67 // Selector of bounds value type
68 template<class Bounds_>
69 struct BoundsValue
70 {
71 using type = typename Bounds_::Coordinate;
72 };
73
74 inline
75 bool
76 operator<(const diy::BlockID& x, const diy::BlockID& y)
77 { return x.gid < y.gid; }
78
79 inline
80 bool
81 operator==(const diy::BlockID& x, const diy::BlockID& y)
82 { return x.gid == y.gid; }
83 }
84
85 #endif
diy::BlockID
Definition: types.hpp:10
diy::BoundsValue
Definition: types.hpp:69
diy::Point< Coordinate, DIY_MAX_DIM >
diy::Bounds
Definition: types.hpp:16
diy::interval
diy::DiscreteBounds interval(int from, int to)
Helper to create a 1-dimensional discrete domain with the specified extents.
Definition: types.hpp:28
diy::Direction
Definition: types.hpp:30