Changeset 894a5f for src/comm/mpi/key.hpp
- Timestamp:
- Feb 2, 2012, 1:58:12 PM (14 years ago)
- Children:
- 32ff22
- Parents:
- 01be70
- File:
-
- 1 edited
-
src/comm/mpi/key.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/comm/mpi/key.hpp
r01be70 r894a5f 15 15 #endif /* HAVE_MPI */ 16 16 17 #include <vector> 17 #include <iostream> 18 #include <list> 19 20 #include "grid/grid.hpp" 18 21 19 22 namespace VMG … … 26 29 { 27 30 28 class Key { 31 class KeyStorage 32 { 29 33 public: 30 Key(); 31 Key(const VMG::MPI::Key& other); 32 Key(const Grid& grid); 33 Key(const Grid& grid_1, const Grid& grid_2); 34 Key(const Index& i1, const Index& i2, const Index& i3); 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 {} 35 40 36 void AddKey(const Grid& grid); 37 void AddKey(const Index& index); 38 void AddKey(const int& i); 39 void AddKey(const void* addr); 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 {} 40 47 41 bool operator<(const Key& other) const; 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 } 42 81 43 82 private: 44 std::vector<int> int_keys; 45 std::vector<const void*> addr_keys; 83 const Index begin, end, size_local, size_global; 84 const void* ptr; 85 }; 86 87 class KeySorted { 88 public: 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 132 private: 133 std::list<KeyStorage> keys; 134 }; 135 136 class KeyUnsorted { 137 public: 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; 168 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 } 176 177 return false; 178 } 179 180 private: 181 std::list<KeyStorage> keys; 46 182 }; 47 183
Note:
See TracChangeset
for help on using the changeset viewer.
