Go to the documentation of this file. 1
5
6 #ifndef moab_SHARED_SET_DATA_HPP
7 #define moab_SHARED_SET_DATA_HPP
8
9 #include "moab/Types.hpp"
10 #include "moab/RangeMap.hpp"
11
12 #define STRINGIFY_( X ) #X
13 #define STRINGIFY( X ) STRINGIFY_( X )
14 #ifdef MOAB_HAVE_UNORDERED_MAP
15 #include STRINGIFY( MOAB_HAVE_UNORDERED_MAP )
16 #include STRINGIFY( MOAB_HAVE_UNORDERED_SET )
17 #else
18 #include <map>
19 #include <set>
20 #endif
21
22 #include <vector>
23
24 namespace moab
25 {
26
27 class Interface;
28
29
30 class SharedSetData
31 {
32 public:
33 SharedSetData( Interface& moab, int pcID, unsigned rank );
34
35 ~SharedSetData();
36
37
42 ErrorCode get_owning_procs( std::vector< unsigned >& ranks_out ) const;
43
44
49 ErrorCode get_sharing_procs( EntityHandle entity_set, std::vector< unsigned >& ranks_out ) const;
50
51
52 ErrorCode get_shared_sets( Range& sets_out ) const;
53
54
55 ErrorCode get_shared_sets( unsigned rank, Range& sets_out ) const;
56
57
58 ErrorCode get_owner( EntityHandle set, unsigned& rank_out, EntityHandle& remote_handle_out ) const;
59
60
61 ErrorCode get_owner( EntityHandle set, unsigned& rank_out ) const
62 {
63 EntityHandle h;
64 return get_owner( set, rank_out, h );
65 }
66
67
68 ErrorCode get_owner_handle( EntityHandle set, EntityHandle& handle_out ) const
69 {
70 unsigned rank;
71 return get_owner( set, rank, handle_out );
72 }
73
74
75 ErrorCode get_local_handle( unsigned owner_rank, EntityHandle remote_handle, EntityHandle& local_handle_out ) const;
76
77 ErrorCode set_owner( EntityHandle set, unsigned owner_rank, EntityHandle owner_handle );
78
79
83 ErrorCode set_sharing_procs( EntityHandle set_handle, std::vector< unsigned >& ranks );
84
85 private:
86 Interface& mb;
87
88
89 struct SharedSetTagData
90 {
91 unsigned ownerRank;
92 EntityHandle ownerHandle;
93 const std::vector< unsigned >* sharingProcs;
94 };
95
96
97 Tag sharedSetTag;
98
99
100 typedef RangeMap< EntityHandle, EntityHandle > ProcHandleMapType;
101
102 static void append_local_handles( const ProcHandleMapType& map, Range& append_to_this );
103
104
105 #ifdef MOAB_HAVE_UNORDERED_MAP
106 struct hash_vect
107 {
108
109 template < typename T >
110 static void hash_combine( size_t& seed, T val )
111 {
112 seed ^= MOAB_UNORDERED_MAP_NS::hash< T >().operator()( val ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
113 }
114 template < typename IT >
115 static size_t hash_range( IT it, IT last )
116 {
117 size_t seed = 0;
118 for( ; it != last; ++it )
119 hash_combine( seed, *it );
120 return seed;
121 }
122 size_t operator()( const std::vector< unsigned >& v ) const
123 {
124 return hash_range( v.begin(), v.end() );
125 }
126 };
127
128 typedef MOAB_UNORDERED_MAP_NS::unordered_map< unsigned, ProcHandleMapType > RHMap;
129 typedef MOAB_UNORDERED_MAP_NS::unordered_set< std::vector< unsigned >, hash_vect > RProcMap;
130 #else
131 struct less_vect
132 {
133 bool operator()( const std::vector< unsigned >& a, const std::vector< unsigned >& b ) const
134 {
135
136 if( a.size() != b.size() ) return a.size() < b.size();
137
138 size_t i = 0;
139 while( i != a.size() && a[i] == b[i] )
140 ++i;
141 return i != a.size() && a[i] < b[i];
142 }
143 };
144
145 typedef std::map< unsigned, ProcHandleMapType > RHMap;
146 typedef std::set< std::vector< unsigned >, less_vect > RProcMap;
147 #endif
148
149
150 RHMap handleMap;
151
152
153 RProcMap procListMap;
154 };
155
156 }
157
158 #endif