source: src/comm/mpi/key.hpp@ 06e153

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