source: src/comm/mpi/key.hpp@ fcf7f6

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

vmg: Added license files and headers (GPLv3).

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

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[fcf7f6]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
[2112b1]19/**
20 * @file key.hpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Nov 21 13:27:22 2011
23 *
24 * @brief Class to distinguish the different entities in maps.
25 *
26 */
27
28#ifndef KEY_HPP_
29#define KEY_HPP_
30
31#ifndef HAVE_MPI
32#error MPI is needed to compile this class
33#endif /* HAVE_MPI */
34
[894a5f]35#include <iostream>
36#include <list>
37
38#include "grid/grid.hpp"
[2112b1]39
40namespace VMG
41{
42
43class Grid;
44class Index;
45
46namespace MPI
47{
48
[894a5f]49class KeyStorage
50{
51public:
52 KeyStorage(const Grid& grid) :
[ac6d04]53 begin(grid.Global().LocalBegin()),
54 end(grid.Global().LocalEnd()),
[894a5f]55 size_local(grid.Local().SizeTotal()),
[ac6d04]56 size_global(grid.Global().GlobalSize()),
57 level(grid.Level())
[894a5f]58 {}
59
[ac6d04]60 KeyStorage(const Index& begin, const Index& end,
61 const Index& size_local, const Index& size_global,
62 const int& level) :
[894a5f]63 begin(begin),
64 end(end),
65 size_local(size_local),
[ac6d04]66 size_global(size_global),
67 level(level)
[894a5f]68 {}
69
70 KeyStorage(const KeyStorage& other) :
71 begin(other.begin),
72 end(other.end),
73 size_local(other.size_local),
[ac6d04]74 size_global(other.size_global),
75 level(other.level)
[894a5f]76 {}
77
78 ~KeyStorage() {}
79
80 bool operator==(const KeyStorage& other) const
81 {
82 return this->begin == other.begin &&
83 this->end == other.end &&
84 this->size_local == other.size_local &&
[ac6d04]85 this->size_global == other.size_global &&
86 this->level == other.level;
[894a5f]87 }
88
89 bool operator!=(const KeyStorage& other) const
90 {
91 return !(*this==other);
92 }
93
94 bool operator<(const KeyStorage& other) const
95 {
96 if (this->begin < other.begin) return true;
[ac6d04]97 if (this->begin != other.begin) return false;
98 if (this->end < other.end) return true;
99 if (this->end != other.end) return false;
100 if (this->size_local < other.size_local) return true;
101 if (this->size_local != other.size_local) return false;
102 if (this->size_global < other.size_global) return true;
103 if (this->size_global != other.size_global) return false;
104 if (this->level < other.level) return true;
105 return false;
[894a5f]106 }
107
108private:
109 const Index begin, end, size_local, size_global;
[ac6d04]110 const int level;
[894a5f]111};
112
113class KeySorted {
114public:
115 KeySorted(const KeySorted& other)
116 {
117 std::list<KeyStorage>::const_iterator i;
118 this->keys.clear();
119 for (i=other.keys.begin(); i!=other.keys.end(); ++i)
120 this->keys.push_back(*i);
121 }
122
123 KeySorted(const Grid& grid)
124 {
125 keys.push_back(KeyStorage(grid));
126 }
127
128 KeySorted(const Grid& grid_1, const Grid& grid_2)
129 {
130 keys.push_back(KeyStorage(grid_1));
131 keys.push_back(KeyStorage(grid_2));
132 keys.sort();
133 }
134
[ac6d04]135 KeySorted(const Index& begin, const Index& end,
136 const Index& size_local, const Index& size_global,
137 const int& level)
[894a5f]138 {
[ac6d04]139 keys.push_back(KeyStorage(begin, end, size_local, size_global, level));
[894a5f]140 }
141
142 ~KeySorted() {}
143
144 bool operator<(const KeySorted& other) const
145 {
146 if (this->keys.size() < other.keys.size()) return true;
147 if (this->keys.size() > other.keys.size()) return false;
148
149 std::list<KeyStorage>::const_iterator i1, i2;
150 for (i1=this->keys.begin(), i2=other.keys.begin();
151 i1!=this->keys.end(), i2!=other.keys.end();
152 ++i1, ++i2) {
153 if (*i1 < *i2) return true;
154 if (*i1 != *i2) return false;
155 }
156
157 return false;
158 }
159
160private:
161 std::list<KeyStorage> keys;
162};
163
[ac6d04]164
165 /*
166 * direction: 0 - from multigrid to temporary grid
167 * 1 - from temporary grid to multigrid
168 * for single grid datatypes always 0
169 */
[894a5f]170class KeyUnsorted {
[2112b1]171public:
[894a5f]172 KeyUnsorted(const KeyUnsorted& other)
173 {
174 std::list<KeyStorage>::const_iterator i;
175 this->keys.clear();
176 for (i=other.keys.begin(); i!=other.keys.end(); ++i)
177 this->keys.push_back(*i);
[ac6d04]178 this->direction = other.direction;
[894a5f]179 }
180
[ac6d04]181 KeyUnsorted(const Grid& grid, const int& direction)
[894a5f]182 {
183 keys.push_back(KeyStorage(grid));
[ac6d04]184 this->direction = direction;
[894a5f]185 }
186
[ac6d04]187 KeyUnsorted(const Grid& grid_1, const Grid& grid_2, const int& direction)
[894a5f]188 {
189 keys.push_back(KeyStorage(grid_1));
190 keys.push_back(KeyStorage(grid_2));
[ac6d04]191 this->direction = direction;
[894a5f]192 }
193
[ac6d04]194 KeyUnsorted(const Index& begin, const Index& end,
195 const Index& size_local, const Index& size_global,
196 const int& level, const int& direction)
[894a5f]197 {
[ac6d04]198 keys.push_back(KeyStorage(begin, end, size_local, size_global, level));
199 this->direction = direction;
[894a5f]200 }
201
202 ~KeyUnsorted() {}
203
204 bool operator<(const KeyUnsorted& other) const
205 {
206 if (this->keys.size() < other.keys.size()) return true;
207 if (this->keys.size() > other.keys.size()) return false;
[2112b1]208
[894a5f]209 std::list<KeyStorage>::const_iterator i1, i2;
210 for (i1=this->keys.begin(), i2=other.keys.begin();
211 i1!=this->keys.end(), i2!=other.keys.end();
212 ++i1, ++i2) {
213 if (*i1 < *i2) return true;
214 if (*i1 != *i2) return false;
215 }
[2112b1]216
[ac6d04]217 if (this->direction < other.direction) return true;
218
[894a5f]219 return false;
220 }
[2112b1]221
222private:
[894a5f]223 std::list<KeyStorage> keys;
[ac6d04]224 int direction;
[2112b1]225};
226
227}
228
229}
230
231#endif /* KEY_HPP_ */
Note: See TracBrowser for help on using the repository browser.