source: src/comm/mpi/datatype.hpp@ 8180d8

Last change on this file since 8180d8 was a72216, checked in by Olaf Lenz <olenz@…>, 13 years ago

Fixed permissions.

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

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef DATATYPE_HPP_
20#define DATATYPE_HPP_
21
22#include <vector>
23
24#include "base/index.hpp"
25#include "grid/grid.hpp"
26
27namespace VMG
28{
29
30namespace MPI
31{
32
33class Datatype
34{
35public:
36 Datatype() :
37 _sizes(0),
38 _subsizes(0),
39 _starts(0),
40 _rank(-1),
41 _tag_send(0),
42 _tag_recv(0),
43 _type(MPI_DATATYPE_NULL),
44 _alloc_buffer(false)
45 {}
46
47 Datatype(Index sizes, Index subsizes, Index starts, const int& rank,
48 const int& tag_send, const int& tag_receive,
49 const bool& alloc_buffer) :
50 _sizes(sizes),
51 _subsizes(subsizes),
52 _starts(starts),
53 _rank(rank),
54 _tag_send(tag_send),
55 _tag_recv(tag_receive),
56 _alloc_buffer(alloc_buffer)
57 {
58 InitDatatype();
59 }
60
61 Datatype(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
62 const int& tag_send, const int& tag_receive,
63 const bool& alloc_buffer) :
64 _sizes(grid.Local().SizeTotal()),
65 _subsizes(bounds.Begin().GetEnd() - bounds.Begin().GetBegin()),
66 _starts(bounds.Begin().GetBegin()),
67 _rank(rank),
68 _tag_send(tag_send),
69 _tag_recv(tag_receive),
70 _alloc_buffer(alloc_buffer)
71 {
72 InitDatatype();
73 }
74
75 Datatype(const Datatype& other) :
76 _sizes(other._sizes),
77 _subsizes(other._subsizes),
78 _starts(other._starts),
79 _rank(other._rank),
80 _tag_send(other._tag_send),
81 _tag_recv(other._tag_recv),
82 _alloc_buffer(other._alloc_buffer)
83 {
84 InitDatatype();
85 }
86
87 ~Datatype()
88 {
89 if (_type != MPI_DATATYPE_NULL)
90 MPI_Type_free(&_type);
91 }
92
93 void Set(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
94 const int& tag_send, const int& tag_receive);
95
96 void Set(const Index& sizes, const Index& subsizes, const Index& starts, const int& rank,
97 const int& tag_send, const int& tag_receive);
98
99 const Index& Sizes() const {return _sizes;}
100 const Index& Subsizes() const {return _subsizes;}
101 const Index& Starts() const {return _starts;}
102
103 const int& Rank() const {return _rank;}
104 const int& TagSend() const {return _tag_send;}
105 const int& TagReceive() const {return _tag_recv;}
106
107 const MPI_Datatype& Type() const {return _type;}
108
109 std::vector<vmg_float>& Buffer() {return _buffer;}
110 const std::vector<vmg_float>& Buffer() const {return _buffer;}
111
112 void Send(Grid& grid, const int& tag, const MPI_Comm& comm) const;
113 void Isend(Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request) const;
114 void Recv(Grid& grid, const int& tag, const MPI_Comm& comm) const;
115 void Irecv(Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request) const;
116
117 void SendBuffered(const Grid& grid, const int& tag, const MPI_Comm& comm);
118 void IsendBuffered(const Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request);
119 void RecvBuffered(const int& tag, const MPI_Comm& comm);
120 void IrecvBuffered(const int& tag, const MPI_Comm& comm, MPI_Request& request);
121
122 void GridReplace(Grid& grid) const;
123 void GridSum(Grid& grid) const;
124
125 bool Feasible() const
126 {
127 return _sizes.Product() > 0 && _subsizes.Product() > 0;
128 }
129
130private:
131 void InitDatatype();
132
133 Index _sizes, _subsizes, _starts;
134 int _rank, _tag_send, _tag_recv;
135 MPI_Datatype _type;
136 std::vector<vmg_float> _buffer;
137 bool _alloc_buffer;
138};
139
140}
141
142}
143
144#endif /* DATATYPE_HPP_ */
Note: See TracBrowser for help on using the repository browser.