source: src/comm/mpi/datatype.hpp@ 7dd744

Last change on this file since 7dd744 was 716da7, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Fix energy calculation.

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

  • Property mode set to 100644
File size: 3.2 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 _tag_send(0),
24 _tag_recv(0),
25 _type(MPI_DATATYPE_NULL),
26 _alloc_buffer(false)
27 {}
28
29 Datatype(Index sizes, Index subsizes, Index starts, const int& rank,
30 const int& tag_send, const int& tag_receive,
31 const bool& alloc_buffer) :
32 _sizes(sizes),
33 _subsizes(subsizes),
34 _starts(starts),
35 _rank(rank),
36 _tag_send(tag_send),
37 _tag_recv(tag_receive),
38 _alloc_buffer(alloc_buffer)
39 {
40 InitDatatype();
41 }
42
43 Datatype(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
44 const int& tag_send, const int& tag_receive,
45 const bool& alloc_buffer) :
46 _sizes(grid.Local().SizeTotal()),
47 _subsizes(bounds.Begin().GetEnd() - bounds.Begin().GetBegin()),
48 _starts(bounds.Begin().GetBegin()),
49 _rank(rank),
50 _tag_send(tag_send),
51 _tag_recv(tag_receive),
52 _alloc_buffer(alloc_buffer)
53 {
54 InitDatatype();
55 }
56
57 Datatype(const Datatype& other) :
58 _sizes(other._sizes),
59 _subsizes(other._subsizes),
60 _starts(other._starts),
61 _rank(other._rank),
62 _tag_send(other._tag_send),
63 _tag_recv(other._tag_recv),
64 _alloc_buffer(other._alloc_buffer)
65 {
66 InitDatatype();
67 }
68
69 ~Datatype()
70 {
71 if (_type != MPI_DATATYPE_NULL)
72 MPI_Type_free(&_type);
73 }
74
75 void Set(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
76 const int& tag_send, const int& tag_receive);
77
78 void Set(const Index& sizes, const Index& subsizes, const Index& starts, const int& rank,
79 const int& tag_send, const int& tag_receive);
80
81 const Index& Sizes() const {return _sizes;}
82 const Index& Subsizes() const {return _subsizes;}
83 const Index& Starts() const {return _starts;}
84
85 const int& Rank() const {return _rank;}
86 const int& TagSend() const {return _tag_send;}
87 const int& TagReceive() const {return _tag_recv;}
88
89 const MPI_Datatype& Type() const {return _type;}
90
91 std::vector<vmg_float>& Buffer() {return _buffer;}
92 const std::vector<vmg_float>& Buffer() const {return _buffer;}
93
94 void Send(Grid& grid, const int& tag, const MPI_Comm& comm) const;
95 void Isend(Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request) const;
96 void Recv(Grid& grid, const int& tag, const MPI_Comm& comm) const;
97 void Irecv(Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request) const;
98
99 void SendBuffered(const Grid& grid, const int& tag, const MPI_Comm& comm);
100 void IsendBuffered(const Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request);
101 void RecvBuffered(const int& tag, const MPI_Comm& comm);
102 void IrecvBuffered(const int& tag, const MPI_Comm& comm, MPI_Request& request);
103
104 void GridReplace(Grid& grid) const;
105 void GridSum(Grid& grid) const;
106
107 bool Feasible() const
108 {
109 return _sizes.Product() > 0 && _subsizes.Product() > 0;
110 }
111
112private:
113 void InitDatatype();
114
115 Index _sizes, _subsizes, _starts;
116 int _rank, _tag_send, _tag_recv;
117 MPI_Datatype _type;
118 std::vector<vmg_float> _buffer;
119 bool _alloc_buffer;
120};
121
122}
123
124}
125
126#endif /* DATATYPE_HPP_ */
Note: See TracBrowser for help on using the repository browser.