moab
|
00001 00006 #ifndef moab_SHARED_SET_DATA_HPP 00007 #define moab_SHARED_SET_DATA_HPP 00008 00009 #include "moab/Types.hpp" 00010 #include "moab/RangeMap.hpp" 00011 00012 #define STRINGIFY_(X) #X 00013 #define STRINGIFY(X) STRINGIFY_(X) 00014 #ifdef HAVE_UNORDERED_MAP 00015 # include STRINGIFY(HAVE_UNORDERED_MAP) 00016 # include STRINGIFY(HAVE_UNORDERED_SET) 00017 #else 00018 # include <map> 00019 # include <set> 00020 #endif 00021 00022 #include <vector> 00023 00024 namespace moab { 00025 00026 class Interface; 00027 00029 class SharedSetData 00030 { 00031 public: 00032 SharedSetData(Interface& moab, unsigned rank); 00033 00034 ~SharedSetData(); 00035 00041 ErrorCode get_owning_procs( std::vector<unsigned>& ranks_out ) const; 00042 00048 ErrorCode get_sharing_procs( EntityHandle entity_set, 00049 std::vector<unsigned>& ranks_out ) const; 00050 00052 ErrorCode get_shared_sets( Range& sets_out ) const; 00053 00055 ErrorCode get_shared_sets( unsigned rank, Range& sets_out ) const; 00056 00058 ErrorCode get_owner( EntityHandle set, 00059 unsigned& rank_out, 00060 EntityHandle& remote_handle_out ) const; 00061 00063 ErrorCode get_owner( EntityHandle set, unsigned& rank_out ) const 00064 { EntityHandle h; return get_owner( set, rank_out, h ); } 00065 00067 ErrorCode get_owner_handle( EntityHandle set, EntityHandle& handle_out ) const 00068 { unsigned rank; return get_owner( set, rank, handle_out); } 00069 00071 ErrorCode get_local_handle( unsigned owner_rank, 00072 EntityHandle remote_handle, 00073 EntityHandle& local_handle_out ) const; 00074 00075 ErrorCode set_owner( EntityHandle set, unsigned owner_rank, EntityHandle owner_handle ); 00076 00081 ErrorCode set_sharing_procs( EntityHandle set_handle, 00082 std::vector<unsigned>& ranks ); 00083 00084 private: 00085 00086 Interface& mb; 00087 unsigned myRank; 00088 00090 struct SharedSetTagData 00091 { 00092 unsigned ownerRank; 00093 EntityHandle ownerHandle; 00094 const std::vector<unsigned>* sharingProcs; 00095 }; 00096 00098 Tag sharedSetTag; 00099 00101 typedef RangeMap<EntityHandle,EntityHandle> ProcHandleMapType; 00102 00103 static void append_local_handles( const ProcHandleMapType& map, 00104 Range& append_to_this ); 00105 00106 00108 #ifdef HAVE_UNORDERED_MAP 00109 struct hash_vect { 00110 // Copied (more or less) from Boost 00111 template <typename T> static void hash_combine( size_t& seed, T val ) 00112 { seed ^= UNORDERED_MAP_NS::hash<T>().operator()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } 00113 template <typename IT> static size_t hash_range( IT it, IT last ) 00114 { size_t seed = 0; for (; it != last; ++it) hash_combine( seed, *it ); return seed; } 00115 size_t operator()(const std::vector<unsigned>& v) const 00116 { return hash_range( v.begin(), v.end() ); } 00117 }; 00118 00119 typedef UNORDERED_MAP_NS::unordered_map<unsigned,ProcHandleMapType> RHMap; 00120 typedef UNORDERED_MAP_NS::unordered_set<std::vector<unsigned>,hash_vect> RProcMap; 00121 #else 00122 struct less_vect { 00123 bool operator()( const std::vector<unsigned>& a, const std::vector<unsigned>& b ) const 00124 { 00125 // sort by size first 00126 if (a.size() != b.size()) 00127 return a.size() < b.size(); 00128 // if same size, sort by first non-equal value 00129 size_t i = 0; 00130 while (i != a.size() && a[i] == b[i]) ++i; 00131 return i != a.size() && a[i] < b[i]; 00132 } 00133 }; 00134 00135 typedef std::map<unsigned,ProcHandleMapType> RHMap; 00136 typedef std::set<std::vector<unsigned>,less_vect> RProcMap; 00137 #endif 00138 00140 RHMap handleMap; 00141 00143 RProcMap procListMap; 00144 }; 00145 00146 00147 } // namespace moab 00148 00149 #endif // moab_SHARED_SET_DATA_HPP