Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 /** \file SharedSetData.hpp 00002 * \author Jason Kraftcheck 00003 * \date 2011-06-23 00004 */ 00005 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 MOAB_HAVE_UNORDERED_MAP 00015 #include STRINGIFY( MOAB_HAVE_UNORDERED_MAP ) 00016 #include STRINGIFY( MOAB_HAVE_UNORDERED_SET ) 00017 #else 00018 #include <map> 00019 #include <set> 00020 #endif 00021 00022 #include <vector> 00023 00024 namespace moab 00025 { 00026 00027 class Interface; 00028 00029 /**\brief ParallelComm data about shared entity sets */ 00030 class SharedSetData 00031 { 00032 public: 00033 SharedSetData( Interface& moab, int pcID, unsigned rank ); 00034 00035 ~SharedSetData(); 00036 00037 /**\brief Get ranks of sharing procs 00038 * 00039 * Get list of all process ranks that own at least one set that 00040 * is shared with this process. 00041 */ 00042 ErrorCode get_owning_procs( std::vector< unsigned >& ranks_out ) const; 00043 00044 /**\brief Get ranks of sharing procs 00045 * 00046 * Get list of all process ranks with which this process the passed set. 00047 * Returns an empty list for non-shared sets. 00048 */ 00049 ErrorCode get_sharing_procs( EntityHandle entity_set, std::vector< unsigned >& ranks_out ) const; 00050 00051 /**\brief Get handles for all shared sets */ 00052 ErrorCode get_shared_sets( Range& sets_out ) const; 00053 00054 /**\brief Get handles for all sets shared with specified process */ 00055 ErrorCode get_shared_sets( unsigned rank, Range& sets_out ) const; 00056 00057 /**\brief Get owner and owner's handle for shared set */ 00058 ErrorCode get_owner( EntityHandle set, unsigned& rank_out, EntityHandle& remote_handle_out ) const; 00059 00060 /**\brief Get owner of shared set */ 00061 ErrorCode get_owner( EntityHandle set, unsigned& rank_out ) const 00062 { 00063 EntityHandle h; 00064 return get_owner( set, rank_out, h ); 00065 } 00066 00067 /**\brief Get owner's handle for shared set */ 00068 ErrorCode get_owner_handle( EntityHandle set, EntityHandle& handle_out ) const 00069 { 00070 unsigned rank; 00071 return get_owner( set, rank, handle_out ); 00072 } 00073 00074 /**\brief Get local handle for shared set */ 00075 ErrorCode get_local_handle( unsigned owner_rank, EntityHandle remote_handle, EntityHandle& local_handle_out ) const; 00076 00077 ErrorCode set_owner( EntityHandle set, unsigned owner_rank, EntityHandle owner_handle ); 00078 00079 /**\brief set/update sharing list for a set 00080 * 00081 *\NOTE sorts \c ranks vector 00082 */ 00083 ErrorCode set_sharing_procs( EntityHandle set_handle, std::vector< unsigned >& ranks ); 00084 00085 private: 00086 Interface& mb; 00087 00088 /**\brief per-set tag data */ 00089 struct SharedSetTagData 00090 { 00091 unsigned ownerRank; 00092 EntityHandle ownerHandle; 00093 const std::vector< unsigned >* sharingProcs; 00094 }; 00095 00096 /** Shared set data: opaque tag containing struct SharedSetTagData */ 00097 Tag sharedSetTag; 00098 00099 /** Map type for lookup of local handle given remote handle */ 00100 typedef RangeMap< EntityHandle, EntityHandle > ProcHandleMapType; 00101 00102 static void append_local_handles( const ProcHandleMapType& map, Range& append_to_this ); 00103 00104 /** Map type for lookup of ProcHandleMapType instance by rank */ 00105 #ifdef MOAB_HAVE_UNORDERED_MAP 00106 struct hash_vect 00107 { 00108 // Copied (more or less) from Boost 00109 template < typename T > 00110 static void hash_combine( size_t& seed, T val ) 00111 { 00112 seed ^= MOAB_UNORDERED_MAP_NS::hash< T >().operator()( val ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 ); 00113 } 00114 template < typename IT > 00115 static size_t hash_range( IT it, IT last ) 00116 { 00117 size_t seed = 0; 00118 for( ; it != last; ++it ) 00119 hash_combine( seed, *it ); 00120 return seed; 00121 } 00122 size_t operator()( const std::vector< unsigned >& v ) const 00123 { 00124 return hash_range( v.begin(), v.end() ); 00125 } 00126 }; 00127 00128 typedef MOAB_UNORDERED_MAP_NS::unordered_map< unsigned, ProcHandleMapType > RHMap; 00129 typedef MOAB_UNORDERED_MAP_NS::unordered_set< std::vector< unsigned >, hash_vect > RProcMap; 00130 #else 00131 struct less_vect 00132 { 00133 bool operator()( const std::vector< unsigned >& a, const std::vector< unsigned >& b ) const 00134 { 00135 // sort by size first 00136 if( a.size() != b.size() ) return a.size() < b.size(); 00137 // if same size, sort by first non-equal value 00138 size_t i = 0; 00139 while( i != a.size() && a[i] == b[i] ) 00140 ++i; 00141 return i != a.size() && a[i] < b[i]; 00142 } 00143 }; 00144 00145 typedef std::map< unsigned, ProcHandleMapType > RHMap; 00146 typedef std::set< std::vector< unsigned >, less_vect > RProcMap; 00147 #endif 00148 00149 /** Map for lookup of ProcHandleMapType instance by rank */ 00150 RHMap handleMap; 00151 00152 /** Storage of sharing lists */ 00153 RProcMap procListMap; 00154 }; 00155 00156 } // namespace moab 00157 00158 #endif // moab_SHARED_SET_DATA_HPP