source: ThirdParty/vmg/src/comm/mpi/key.hpp@ 79b089

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_vmg TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 79b089 was 7faa5c, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit 'de061d9d851257a04e924d4472df4523d33bb08b' as 'ThirdParty/vmg'

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[de061d]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 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
35#include <iostream>
36#include <list>
37
38#include "grid/grid.hpp"
39
40namespace VMG
41{
42
43class Grid;
44class Index;
45
46namespace MPI
47{
48
49class KeyStorage
50{
51public:
52 KeyStorage(const Grid& grid) :
53 begin(grid.Global().LocalBegin()),
54 end(grid.Global().LocalEnd()),
55 size_local(grid.Local().SizeTotal()),
56 size_global(grid.Global().GlobalSizeFinest()),
57 level(grid.Level())
58 {}
59
60 KeyStorage(const Index& begin, const Index& end,
61 const Index& size_local, const Index& size_global,
62 const int& level) :
63 begin(begin),
64 end(end),
65 size_local(size_local),
66 size_global(size_global),
67 level(level)
68 {}
69
70 KeyStorage(const KeyStorage& other) :
71 begin(other.begin),
72 end(other.end),
73 size_local(other.size_local),
74 size_global(other.size_global),
75 level(other.level)
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 &&
85 this->size_global == other.size_global &&
86 this->level == other.level;
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;
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;
106 }
107
108private:
109 const Index begin, end, size_local, size_global;
110 const int level;
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
135 KeySorted(const Index& begin, const Index& end,
136 const Index& size_local, const Index& size_global,
137 const int& level)
138 {
139 keys.push_back(KeyStorage(begin, end, size_local, size_global, level));
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
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 */
170class KeyUnsorted {
171public:
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);
178 this->direction = other.direction;
179 }
180
181 KeyUnsorted(const Grid& grid, const int& direction)
182 {
183 keys.push_back(KeyStorage(grid));
184 this->direction = direction;
185 }
186
187 KeyUnsorted(const Grid& grid_1, const Grid& grid_2, const int& direction)
188 {
189 keys.push_back(KeyStorage(grid_1));
190 keys.push_back(KeyStorage(grid_2));
191 this->direction = direction;
192 }
193
194 KeyUnsorted(const Index& begin, const Index& end,
195 const Index& size_local, const Index& size_global,
196 const int& level, const int& direction)
197 {
198 keys.push_back(KeyStorage(begin, end, size_local, size_global, level));
199 this->direction = direction;
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;
208
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 }
216
217 if (this->direction < other.direction) return true;
218
219 return false;
220 }
221
222private:
223 std::list<KeyStorage> keys;
224 int direction;
225};
226
227}
228
229}
230
231#endif /* KEY_HPP_ */
Note: See TracBrowser for help on using the repository browser.