source: src/comm/mpi/datatype.hpp@ a40eea

Last change on this file since a40eea was ac6d04, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1666 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 3.0 KB
Line 
1#ifndef DATATYPE_HPP_
2#define DATATYPE_HPP_
3
4#include <vector>
5
6#include "base/index.hpp"
7#include "grid/grid.hpp"
8
9namespace VMG
10{
11
12namespace MPI
13{
14
15class Datatype
16{
17public:
18 Datatype() :
19 _sizes(0),
20 _subsizes(0),
21 _starts(0),
22 _rank(-1),
23 _type(MPI_DATATYPE_NULL)
24 {}
25
26 Datatype(Index sizes, Index subsizes, Index starts, const int& rank,
27 const int& tag_send, const int& tag_receive) :
28 _sizes(sizes),
29 _subsizes(subsizes),
30 _starts(starts),
31 _rank(rank),
32 _tag_send(tag_send),
33 _tag_recv(tag_receive),
34 _buffer(subsizes.Product())
35 {
36 InitDatatype();
37 }
38
39 Datatype(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
40 const int& tag_send, const int& tag_receive) :
41 _sizes(grid.Local().SizeTotal()),
42 _subsizes(bounds.Begin().GetEnd() - bounds.Begin().GetBegin()),
43 _starts(bounds.Begin().GetBegin()),
44 _rank(rank),
45 _tag_send(tag_send),
46 _tag_recv(tag_receive),
47 _buffer(_subsizes.Product())
48 {
49 InitDatatype();
50 }
51
52 Datatype(const Datatype& other) :
53 _sizes(other._sizes),
54 _subsizes(other._subsizes),
55 _starts(other._starts),
56 _rank(other._rank),
57 _tag_send(other._tag_send),
58 _tag_recv(other._tag_recv),
59 _buffer(_subsizes.Product())
60 {
61 InitDatatype();
62 }
63
64 ~Datatype()
65 {
66 if (_type != MPI_DATATYPE_NULL)
67 MPI_Type_free(&_type);
68 }
69
70 void Set(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
71 const int& tag_send, const int& tag_receive);
72
73 void Set(const Index& sizes, const Index& subsizes, const Index& starts, const int& rank,
74 const int& tag_send, const int& tag_receive);
75
76 const Index& Sizes() const {return _sizes;}
77 const Index& Subsizes() const {return _subsizes;}
78 const Index& Starts() const {return _starts;}
79
80 const int& Rank() const {return _rank;}
81 const int& TagSend() const {return _tag_send;}
82 const int& TagReceive() const {return _tag_recv;}
83
84 const MPI_Datatype& Type() const {return _type;}
85
86 const std::vector<vmg_float>& Buffer() const {return _buffer;}
87
88 void Send(Grid& grid, const int& tag, const MPI_Comm& comm) const;
89 void Isend(Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request) const;
90 void Recv(Grid& grid, const int& tag, const MPI_Comm& comm) const;
91 void Irecv(Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request) const;
92
93 void SendBuffered(const Grid& grid, const int& tag, const MPI_Comm& comm);
94 void IsendBuffered(const Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request);
95 void RecvBuffered(const int& tag, const MPI_Comm& comm);
96 void IrecvBuffered(const int& tag, const MPI_Comm& comm, MPI_Request& request);
97
98 void GridReplace(Grid& grid) const;
99 void GridSum(Grid& grid) const;
100
101 bool Feasible() const
102 {
103 return _sizes.Product() > 0 && _subsizes.Product() > 0;
104 }
105
106private:
107 void InitDatatype();
108
109 Index _sizes, _subsizes, _starts;
110 int _rank, _tag_send, _tag_recv;
111 MPI_Datatype _type;
112 std::vector<vmg_float> _buffer;
113};
114
115}
116
117}
118
119#endif /* DATATYPE_HPP_ */
Note: See TracBrowser for help on using the repository browser.