| 1 | #ifndef DATATYPE_HPP_
|
|---|
| 2 | #define DATATYPE_HPP_
|
|---|
| 3 |
|
|---|
| 4 | #include "base/index.hpp"
|
|---|
| 5 | #include "grid/grid.hpp"
|
|---|
| 6 |
|
|---|
| 7 | namespace VMG
|
|---|
| 8 | {
|
|---|
| 9 |
|
|---|
| 10 | namespace MPI
|
|---|
| 11 | {
|
|---|
| 12 |
|
|---|
| 13 | class Datatype
|
|---|
| 14 | {
|
|---|
| 15 | public:
|
|---|
| 16 | Datatype() :
|
|---|
| 17 | _sizes(0),
|
|---|
| 18 | _subsizes(0),
|
|---|
| 19 | _starts(0),
|
|---|
| 20 | _rank(-1),
|
|---|
| 21 | _type(MPI_DATATYPE_NULL)
|
|---|
| 22 | {}
|
|---|
| 23 |
|
|---|
| 24 | Datatype(Index sizes, Index subsizes, Index starts, const int& rank,
|
|---|
| 25 | const int& tag_send, const int& tag_receive) :
|
|---|
| 26 | _sizes(sizes),
|
|---|
| 27 | _subsizes(subsizes),
|
|---|
| 28 | _starts(starts),
|
|---|
| 29 | _rank(rank),
|
|---|
| 30 | _tag_send(tag_send),
|
|---|
| 31 | _tag_recv(tag_receive)
|
|---|
| 32 | {
|
|---|
| 33 | if (_sizes.Product() > 0 && _subsizes.Product() > 0) {
|
|---|
| 34 | MPI_Type_create_subarray(3, _sizes.vec(), _subsizes.vec(), _starts.vec(), MPI_ORDER_C, MPI_DOUBLE, &_type);
|
|---|
| 35 | MPI_Type_commit(&_type);
|
|---|
| 36 | }else {
|
|---|
| 37 | _type = MPI_DATATYPE_NULL;
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | Datatype(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
|
|---|
| 42 | const int& tag_send, const int& tag_receive) :
|
|---|
| 43 | _sizes(grid.Local().SizeTotal()),
|
|---|
| 44 | _subsizes(bounds.Begin().GetEnd() - bounds.Begin().GetBegin()),
|
|---|
| 45 | _starts(bounds.Begin().GetBegin()),
|
|---|
| 46 | _rank(rank),
|
|---|
| 47 | _tag_send(tag_send),
|
|---|
| 48 | _tag_recv(tag_receive)
|
|---|
| 49 | {
|
|---|
| 50 | if (_sizes.Product() > 0 && _subsizes.Product() > 0) {
|
|---|
| 51 | MPI_Type_create_subarray(3, _sizes.vec(), _subsizes.vec(), _starts.vec(), MPI_ORDER_C, MPI_DOUBLE, &_type);
|
|---|
| 52 | MPI_Type_commit(&_type);
|
|---|
| 53 | }else {
|
|---|
| 54 | _type = MPI_DATATYPE_NULL;
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | Datatype(const Datatype& other) :
|
|---|
| 59 | _sizes(other._sizes),
|
|---|
| 60 | _subsizes(other._subsizes),
|
|---|
| 61 | _starts(other._starts),
|
|---|
| 62 | _rank(other._rank),
|
|---|
| 63 | _tag_send(other._tag_send),
|
|---|
| 64 | _tag_recv(other._tag_recv)
|
|---|
| 65 | {
|
|---|
| 66 | if (_sizes.Product() > 0 && _subsizes.Product() > 0) {
|
|---|
| 67 | MPI_Type_create_subarray(3, _sizes.vec(), _subsizes.vec(), _starts.vec(), MPI_ORDER_C, MPI_DOUBLE, &_type);
|
|---|
| 68 | MPI_Type_commit(&_type);
|
|---|
| 69 | }else {
|
|---|
| 70 | _type = MPI_DATATYPE_NULL;
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | void Set(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
|
|---|
| 75 | const int& tag_send, const int& tag_receive)
|
|---|
| 76 | {
|
|---|
| 77 | _sizes = grid.Local().SizeTotal();
|
|---|
| 78 | _subsizes = bounds.Begin().GetEnd() - bounds.Begin().GetBegin();
|
|---|
| 79 | _starts = bounds.Begin().GetBegin();
|
|---|
| 80 | _rank = rank;
|
|---|
| 81 | _tag_send = tag_send;
|
|---|
| 82 | _tag_recv = tag_receive;
|
|---|
| 83 |
|
|---|
| 84 | if (_sizes.Product() > 0 && _subsizes.Product() > 0) {
|
|---|
| 85 | MPI_Type_create_subarray(3, _sizes.vec(), _subsizes.vec(), _starts.vec(), MPI_ORDER_C, MPI_DOUBLE, &_type);
|
|---|
| 86 | MPI_Type_commit(&_type);
|
|---|
| 87 | }else {
|
|---|
| 88 | _type = MPI_DATATYPE_NULL;
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | void Set(const Index& sizes, const Index& subsizes, const Index& starts, const int& rank,
|
|---|
| 93 | const int& tag_send, const int& tag_receive)
|
|---|
| 94 | {
|
|---|
| 95 | _sizes = sizes;
|
|---|
| 96 | _subsizes = subsizes;
|
|---|
| 97 | _starts = starts;
|
|---|
| 98 | _rank = rank;
|
|---|
| 99 | _tag_send = tag_send;
|
|---|
| 100 | _tag_recv = tag_receive;
|
|---|
| 101 |
|
|---|
| 102 | if (_sizes.Product() > 0 && _subsizes.Product() > 0) {
|
|---|
| 103 | MPI_Type_create_subarray(3, _sizes.vec(), _subsizes.vec(), _starts.vec(), MPI_ORDER_C, MPI_DOUBLE, &_type);
|
|---|
| 104 | MPI_Type_commit(&_type);
|
|---|
| 105 | }else {
|
|---|
| 106 | _type = MPI_DATATYPE_NULL;
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | ~Datatype()
|
|---|
| 111 | {
|
|---|
| 112 | if (_type != MPI_DATATYPE_NULL)
|
|---|
| 113 | MPI_Type_free(&_type);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | Index& Sizes() {return _sizes;}
|
|---|
| 117 | Index& Subsizes() {return _subsizes;}
|
|---|
| 118 | Index& Starts() {return _starts;}
|
|---|
| 119 | const int& Rank() const {return _rank;}
|
|---|
| 120 | const int& TagSend() const {return _tag_send;}
|
|---|
| 121 | const int& TagReceive() const {return _tag_recv;}
|
|---|
| 122 | MPI_Datatype Type() const {return _type;}
|
|---|
| 123 |
|
|---|
| 124 | bool Feasible() const
|
|---|
| 125 | {
|
|---|
| 126 | return _sizes.Product() > 0 && _subsizes.Product() > 0;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | int Size() const
|
|---|
| 130 | {
|
|---|
| 131 | return _subsizes.Product();
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | private:
|
|---|
| 135 | Index _sizes, _subsizes, _starts;
|
|---|
| 136 | int _rank, _tag_send, _tag_recv;
|
|---|
| 137 | MPI_Datatype _type;
|
|---|
| 138 | };
|
|---|
| 139 |
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | #endif /* DATATYPE_HPP_ */
|
|---|