source: ThirdParty/vmg/src/comm/mpi/datatype.hpp

Candidate_v1.6.1
Last change on this file was 7faa5c, checked in by Frederik Heber <heber@…>, 9 years ago

Merge commit 'de061d9d851257a04e924d4472df4523d33bb08b' as 'ThirdParty/vmg'

  • Property mode set to 100644
File size: 4.2 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/**
20 * @file datatype.hpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Tue Apr 09 12:19:58 2013
23 *
24 * @brief Helper class to handle MPI datatypes.
25 *
26 */
27
28#ifndef DATATYPE_HPP_
29#define DATATYPE_HPP_
30
31#include <string>
32#include <vector>
33
34#include "base/index.hpp"
35#include "grid/grid.hpp"
36
37namespace VMG
38{
39
40namespace MPI
41{
42
43class Datatype
44{
45public:
46 Datatype() :
47 _sizes(0),
48 _subsizes(0),
49 _starts(0),
50 _rank(-1),
51 _tag_send(0),
52 _tag_recv(0),
53 _type(MPI_DATATYPE_NULL),
54 _alloc_buffer(false)
55 {}
56
57 Datatype(Index sizes, Index subsizes, Index starts, const int& rank,
58 const int& tag_send, const int& tag_receive,
59 const bool& alloc_buffer) :
60 _sizes(sizes),
61 _subsizes(subsizes),
62 _starts(starts),
63 _rank(rank),
64 _tag_send(tag_send),
65 _tag_recv(tag_receive),
66 _alloc_buffer(alloc_buffer)
67 {
68 InitDatatype();
69 }
70
71 Datatype(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
72 const int& tag_send, const int& tag_receive,
73 const bool& alloc_buffer) :
74 _sizes(grid.Local().SizeTotal()),
75 _subsizes(bounds.Begin().GetEnd() - bounds.Begin().GetBegin()),
76 _starts(bounds.Begin().GetBegin()),
77 _rank(rank),
78 _tag_send(tag_send),
79 _tag_recv(tag_receive),
80 _alloc_buffer(alloc_buffer)
81 {
82 InitDatatype();
83 }
84
85 Datatype(const Datatype& other) :
86 _sizes(other._sizes),
87 _subsizes(other._subsizes),
88 _starts(other._starts),
89 _rank(other._rank),
90 _tag_send(other._tag_send),
91 _tag_recv(other._tag_recv),
92 _alloc_buffer(other._alloc_buffer)
93 {
94 InitDatatype();
95 }
96
97 ~Datatype()
98 {
99 if (_type != MPI_DATATYPE_NULL)
100 MPI_Type_free(&_type);
101 }
102
103 void Set(const GridIteratorSet& bounds, const Grid& grid, const int& rank,
104 const int& tag_send, const int& tag_receive);
105
106 void Set(const Index& sizes, const Index& subsizes, const Index& starts, const int& rank,
107 const int& tag_send, const int& tag_receive);
108
109 const Index& Sizes() const {return _sizes;}
110 const Index& Subsizes() const {return _subsizes;}
111 const Index& Starts() const {return _starts;}
112
113 const int& Rank() const {return _rank;}
114 const int& TagSend() const {return _tag_send;}
115 const int& TagReceive() const {return _tag_recv;}
116
117 const MPI_Datatype& Type() const {return _type;}
118
119 std::vector<vmg_float>& Buffer() {return _buffer;}
120 const std::vector<vmg_float>& Buffer() const {return _buffer;}
121
122 void Send(Grid& grid, const int& tag, const MPI_Comm& comm) const;
123 void Isend(Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request) const;
124 void Recv(Grid& grid, const int& tag, const MPI_Comm& comm) const;
125 void Irecv(Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request) const;
126
127 void SendBuffered(const Grid& grid, const int& tag, const MPI_Comm& comm);
128 void IsendBuffered(const Grid& grid, const int& tag, const MPI_Comm& comm, MPI_Request& request);
129 void RecvBuffered(const int& tag, const MPI_Comm& comm);
130 void IrecvBuffered(const int& tag, const MPI_Comm& comm, MPI_Request& request);
131
132 void GridReplace(Grid& grid) const;
133 void GridSum(Grid& grid) const;
134
135 bool Feasible() const
136 {
137 return _sizes.Product() > 0 && _subsizes.Product() > 0;
138 }
139
140 std::string ToString() const;
141
142private:
143 void InitDatatype();
144
145 Index _sizes, _subsizes, _starts;
146 int _rank, _tag_send, _tag_recv;
147 MPI_Datatype _type;
148 std::vector<vmg_float> _buffer;
149 bool _alloc_buffer;
150};
151
152}
153
154}
155
156#endif /* DATATYPE_HPP_ */
Note: See TracBrowser for help on using the repository browser.