source: src/comm/mpi/key.hpp@ 32ff22

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

Parallel performance update.

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

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[2112b1]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
[894a5f]17#include <iostream>
18#include <list>
19
20#include "grid/grid.hpp"
[2112b1]21
22namespace VMG
23{
24
25class Grid;
26class Index;
27
28namespace MPI
29{
30
[894a5f]31class KeyStorage
32{
33public:
34 KeyStorage(const Grid& grid) :
35 begin(grid.Global().BeginLocal()),
36 end(grid.Global().EndLocal()),
37 size_local(grid.Local().SizeTotal()),
38 size_global(grid.Global().SizeGlobal())
39 {}
40
41 KeyStorage(const Index& begin, const Index& end, const Index& size_local, const Index& size_global) :
42 begin(begin),
43 end(end),
44 size_local(size_local),
45 size_global(size_global)
46 {}
47
48 KeyStorage(const KeyStorage& other) :
49 begin(other.begin),
50 end(other.end),
51 size_local(other.size_local),
52 size_global(other.size_global)
53 {}
54
55 ~KeyStorage() {}
56
57 bool operator==(const KeyStorage& other) const
58 {
59 return this->begin == other.begin &&
60 this->end == other.end &&
61 this->size_local == other.size_local &&
62 this->size_global == other.size_global;
63 }
64
65 bool operator!=(const KeyStorage& other) const
66 {
67 return !(*this==other);
68 }
69
70 bool operator<(const KeyStorage& other) const
71 {
72 if (this->begin < other.begin) return true;
73 else if (this->begin != other.begin) return false;
74 else if (this->end < other.end) return true;
75 else if (this->end != other.end) return false;
76 else if (this->size_local < other.size_local) return true;
77 else if (this->size_local != other.size_local) return false;
78 else if (this->size_global < other.size_global) return true;
79 else return false;
80 }
81
82private:
83 const Index begin, end, size_local, size_global;
84 const void* ptr;
85};
86
87class KeySorted {
88public:
89 KeySorted(const KeySorted& other)
90 {
91 std::list<KeyStorage>::const_iterator i;
92 this->keys.clear();
93 for (i=other.keys.begin(); i!=other.keys.end(); ++i)
94 this->keys.push_back(*i);
95 }
96
97 KeySorted(const Grid& grid)
98 {
99 keys.push_back(KeyStorage(grid));
100 }
101
102 KeySorted(const Grid& grid_1, const Grid& grid_2)
103 {
104 keys.push_back(KeyStorage(grid_1));
105 keys.push_back(KeyStorage(grid_2));
106 keys.sort();
107 }
108
109 KeySorted(const Index& begin, const Index& end, const Index& size_local, const Index& size_global)
110 {
111 keys.push_back(KeyStorage(begin, end, size_local, size_global));
112 }
113
114 ~KeySorted() {}
115
116 bool operator<(const KeySorted& other) const
117 {
118 if (this->keys.size() < other.keys.size()) return true;
119 if (this->keys.size() > other.keys.size()) return false;
120
121 std::list<KeyStorage>::const_iterator i1, i2;
122 for (i1=this->keys.begin(), i2=other.keys.begin();
123 i1!=this->keys.end(), i2!=other.keys.end();
124 ++i1, ++i2) {
125 if (*i1 < *i2) return true;
126 if (*i1 != *i2) return false;
127 }
128
129 return false;
130 }
131
132private:
133 std::list<KeyStorage> keys;
134};
135
136class KeyUnsorted {
[2112b1]137public:
[894a5f]138 KeyUnsorted(const KeyUnsorted& other)
139 {
140 std::list<KeyStorage>::const_iterator i;
141 this->keys.clear();
142 for (i=other.keys.begin(); i!=other.keys.end(); ++i)
143 this->keys.push_back(*i);
144 }
145
146 KeyUnsorted(const Grid& grid)
147 {
148 keys.push_back(KeyStorage(grid));
149 }
150
151 KeyUnsorted(const Grid& grid_1, const Grid& grid_2)
152 {
153 keys.push_back(KeyStorage(grid_1));
154 keys.push_back(KeyStorage(grid_2));
155 }
156
157 KeyUnsorted(const Index& begin, const Index& end, const Index& size_local, const Index& size_global)
158 {
159 keys.push_back(KeyStorage(begin, end, size_local, size_global));
160 }
161
162 ~KeyUnsorted() {}
163
164 bool operator<(const KeyUnsorted& other) const
165 {
166 if (this->keys.size() < other.keys.size()) return true;
167 if (this->keys.size() > other.keys.size()) return false;
[2112b1]168
[894a5f]169 std::list<KeyStorage>::const_iterator i1, i2;
170 for (i1=this->keys.begin(), i2=other.keys.begin();
171 i1!=this->keys.end(), i2!=other.keys.end();
172 ++i1, ++i2) {
173 if (*i1 < *i2) return true;
174 if (*i1 != *i2) return false;
175 }
[2112b1]176
[894a5f]177 return false;
178 }
[2112b1]179
180private:
[894a5f]181 std::list<KeyStorage> keys;
[2112b1]182};
183
184}
185
186}
187
188#endif /* KEY_HPP_ */
Note: See TracBrowser for help on using the repository browser.