Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
moab::SharedSetData Class Reference

ParallelComm data about shared entity sets. More...

#include <SharedSetData.hpp>

+ Collaboration diagram for moab::SharedSetData:

Classes

struct  less_vect
 
struct  SharedSetTagData
 per-set tag data More...
 

Public Member Functions

 SharedSetData (Interface &moab, int pcID, unsigned rank)
 
 ~SharedSetData ()
 
ErrorCode get_owning_procs (std::vector< unsigned > &ranks_out) const
 Get ranks of sharing procs. More...
 
ErrorCode get_sharing_procs (EntityHandle entity_set, std::vector< unsigned > &ranks_out) const
 Get ranks of sharing procs. More...
 
ErrorCode get_shared_sets (Range &sets_out) const
 Get handles for all shared sets. More...
 
ErrorCode get_shared_sets (unsigned rank, Range &sets_out) const
 Get handles for all sets shared with specified process. More...
 
ErrorCode get_owner (EntityHandle set, unsigned &rank_out, EntityHandle &remote_handle_out) const
 Get owner and owner's handle for shared set. More...
 
ErrorCode get_owner (EntityHandle set, unsigned &rank_out) const
 Get owner of shared set. More...
 
ErrorCode get_owner_handle (EntityHandle set, EntityHandle &handle_out) const
 Get owner's handle for shared set. More...
 
ErrorCode get_local_handle (unsigned owner_rank, EntityHandle remote_handle, EntityHandle &local_handle_out) const
 Get local handle for shared set. More...
 
ErrorCode set_owner (EntityHandle set, unsigned owner_rank, EntityHandle owner_handle)
 
ErrorCode set_sharing_procs (EntityHandle set_handle, std::vector< unsigned > &ranks)
 set/update sharing list for a set More...
 

Private Types

typedef RangeMap< EntityHandle, EntityHandleProcHandleMapType
 
typedef std::map< unsigned, ProcHandleMapTypeRHMap
 
typedef std::set< std::vector< unsigned >, less_vectRProcMap
 

Static Private Member Functions

static void append_local_handles (const ProcHandleMapType &map, Range &append_to_this)
 

Private Attributes

Interfacemb
 
Tag sharedSetTag
 
RHMap handleMap
 
RProcMap procListMap
 

Detailed Description

ParallelComm data about shared entity sets.

Definition at line 30 of file SharedSetData.hpp.

Member Typedef Documentation

◆ ProcHandleMapType

Map type for lookup of local handle given remote handle

Definition at line 100 of file SharedSetData.hpp.

◆ RHMap

typedef std::map< unsigned, ProcHandleMapType > moab::SharedSetData::RHMap
private

Definition at line 145 of file SharedSetData.hpp.

◆ RProcMap

typedef std::set< std::vector< unsigned >, less_vect > moab::SharedSetData::RProcMap
private

Definition at line 146 of file SharedSetData.hpp.

Constructor & Destructor Documentation

◆ SharedSetData()

moab::SharedSetData::SharedSetData ( Interface moab,
int  pcID,
unsigned  rank 
)

Definition at line 15 of file SharedSetData.cpp.

15  : mb( moab ), sharedSetTag( 0 )
16 {
17  SharedSetTagData zero;
18 
19  // Zero out any padding bytes in SharedSetTagData (used for memory alignment)
20  // Otherwise, memcmp could lead to unexpected false negatives for comparison
21  memset( &zero, 0, sizeof( SharedSetTagData ) );
22 
23  zero.ownerRank = rank;
24  zero.ownerHandle = 0;
25  zero.sharingProcs = NULL;
26  // band-aid: make sure the tag is unique, to not interfere with different pcID
27  // maybe a better solution is needed
28  // pcID can be at most 64, it ranges from 0 to 63; problems appear at migrate mesh
29  std::ostringstream sharedTagUniqueName;
30  sharedTagUniqueName << "__sharedSetTag" << pcID;
31  ErrorCode rval = mb.tag_get_handle( sharedTagUniqueName.str().c_str(), sizeof( SharedSetTagData ), MB_TYPE_OPAQUE,
33  assert( MB_SUCCESS == rval );
34  if( MB_SUCCESS != rval )
35  {
36  fprintf( stderr, "Aborted from the constructor of SharedSetData.\n" );
37  abort();
38  }
39 }

References ErrorCode, mb, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_OPAQUE, moab::SharedSetData::SharedSetTagData::ownerHandle, moab::SharedSetData::SharedSetTagData::ownerRank, sharedSetTag, moab::SharedSetData::SharedSetTagData::sharingProcs, and moab::Interface::tag_get_handle().

◆ ~SharedSetData()

moab::SharedSetData::~SharedSetData ( )

Definition at line 41 of file SharedSetData.cpp.

42 {
44 }

References mb, sharedSetTag, and moab::Interface::tag_delete().

Member Function Documentation

◆ append_local_handles()

void moab::SharedSetData::append_local_handles ( const ProcHandleMapType map,
Range append_to_this 
)
staticprivate

Definition at line 178 of file SharedSetData.cpp.

179 {
180  Range::iterator hint = range.begin();
181  for( ProcHandleMapType::const_iterator i = map.begin(); i != map.end(); ++i )
182  hint = range.insert( hint, i->value, i->value + i->count - 1 );
183 }

References moab::Range::begin(), moab::RangeMap< KeyType, ValType, NullVal >::begin(), moab::RangeMap< KeyType, ValType, NullVal >::end(), and moab::Range::insert().

Referenced by get_shared_sets().

◆ get_local_handle()

ErrorCode moab::SharedSetData::get_local_handle ( unsigned  owner_rank,
EntityHandle  remote_handle,
EntityHandle local_handle_out 
) const

Get local handle for shared set.

Definition at line 109 of file SharedSetData.cpp.

112 {
113  RHMap::const_iterator i = handleMap.find( owner_rank );
114  assert( i != handleMap.end() );
115  if( i == handleMap.end() )
116  {
117  local_handle = ~(EntityHandle)0;
118  return MB_FAILURE;
119  }
120 
121  if( !i->second.find( remote_handle, local_handle ) )
122  {
123  assert( false );
124  local_handle = ~(EntityHandle)0;
125  return MB_FAILURE;
126  }
127 
128  return MB_SUCCESS;
129 }

References handleMap, and MB_SUCCESS.

Referenced by moab::ParallelComm::get_entityset_local_handle().

◆ get_owner() [1/2]

ErrorCode moab::SharedSetData::get_owner ( EntityHandle  set,
unsigned &  rank_out 
) const
inline

Get owner of shared set.

Definition at line 61 of file SharedSetData.hpp.

62  {
63  EntityHandle h;
64  return get_owner( set, rank_out, h );
65  }

References get_owner().

◆ get_owner() [2/2]

ErrorCode moab::SharedSetData::get_owner ( EntityHandle  set,
unsigned &  rank_out,
EntityHandle remote_handle_out 
) const

Get owner and owner's handle for shared set.

Definition at line 91 of file SharedSetData.cpp.

92 {
93  ErrorCode rval;
94  SharedSetTagData data;
95  rval = mb.tag_get_data( sharedSetTag, &entity_set, 1, &data );
96  if( MB_SUCCESS != rval ) return rval;
97 
98  if( !data.ownerHandle )
99  { // not shared
100  assert( !data.sharingProcs ); // really not shared
101  data.ownerHandle = entity_set;
102  }
103 
104  rank_out = data.ownerRank;
105  remote_handle_out = data.ownerHandle;
106  return MB_SUCCESS;
107 }

References ErrorCode, mb, MB_SUCCESS, moab::SharedSetData::SharedSetTagData::ownerHandle, moab::SharedSetData::SharedSetTagData::ownerRank, sharedSetTag, moab::SharedSetData::SharedSetTagData::sharingProcs, and moab::Interface::tag_get_data().

Referenced by moab::ParallelComm::get_entityset_owner(), get_owner(), and get_owner_handle().

◆ get_owner_handle()

ErrorCode moab::SharedSetData::get_owner_handle ( EntityHandle  set,
EntityHandle handle_out 
) const
inline

Get owner's handle for shared set.

Definition at line 68 of file SharedSetData.hpp.

69  {
70  unsigned rank;
71  return get_owner( set, rank, handle_out );
72  }

References get_owner().

◆ get_owning_procs()

ErrorCode moab::SharedSetData::get_owning_procs ( std::vector< unsigned > &  ranks_out) const

Get ranks of sharing procs.

Get list of all process ranks that own at least one set that is shared with this process.

Definition at line 46 of file SharedSetData.cpp.

47 {
48  ranks_out.clear();
49  ranks_out.reserve( handleMap.size() );
50  for( RHMap::const_iterator i = handleMap.begin(); i != handleMap.end(); ++i )
51  ranks_out.push_back( i->first );
52  return MB_SUCCESS;
53 }

References handleMap, and MB_SUCCESS.

Referenced by moab::ParallelComm::get_entityset_owners().

◆ get_shared_sets() [1/2]

ErrorCode moab::SharedSetData::get_shared_sets ( Range sets_out) const

Get handles for all shared sets.

Definition at line 67 of file SharedSetData.cpp.

68 {
69  // sets_out.clear();
70  // return mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &sharedSetTag, 1, 0, sets_out );
71 
72  sets_out.clear();
73  for( RHMap::const_iterator i = handleMap.begin(); i != handleMap.end(); ++i )
74  append_local_handles( i->second, sets_out );
75  return MB_SUCCESS;
76 }

References append_local_handles(), moab::Range::clear(), handleMap, and MB_SUCCESS.

Referenced by moab::ParallelComm::get_owned_sets(), and moab::ParallelComm::get_shared_sets().

◆ get_shared_sets() [2/2]

ErrorCode moab::SharedSetData::get_shared_sets ( unsigned  rank,
Range sets_out 
) const

Get handles for all sets shared with specified process.

Definition at line 78 of file SharedSetData.cpp.

79 {
80  sets_out.clear();
81  // if (rank == myRank) {
82  // return mb.get_entities_by_type_and_tag( 0, MBENTITYSET,
83  // }
84  // else {
85  RHMap::const_iterator i = handleMap.find( rank );
86  if( i != handleMap.end() ) append_local_handles( i->second, sets_out );
87  return MB_SUCCESS;
88  // }
89 }

References append_local_handles(), moab::Range::clear(), handleMap, and MB_SUCCESS.

◆ get_sharing_procs()

ErrorCode moab::SharedSetData::get_sharing_procs ( EntityHandle  entity_set,
std::vector< unsigned > &  ranks_out 
) const

Get ranks of sharing procs.

Get list of all process ranks with which this process the passed set. Returns an empty list for non-shared sets.

Definition at line 55 of file SharedSetData.cpp.

56 {
57  ErrorCode rval;
58  SharedSetTagData data;
59  rval = mb.tag_get_data( sharedSetTag, &entity_set, 1, &data );
60  if( MB_SUCCESS != rval ) return rval;
61 
62  ranks_out.clear();
63  if( data.sharingProcs ) ranks_out = *data.sharingProcs;
64  return MB_SUCCESS;
65 }

References ErrorCode, mb, MB_SUCCESS, sharedSetTag, moab::SharedSetData::SharedSetTagData::sharingProcs, and moab::Interface::tag_get_data().

Referenced by moab::ParallelComm::get_entityset_procs().

◆ set_owner()

ErrorCode moab::SharedSetData::set_owner ( EntityHandle  set,
unsigned  owner_rank,
EntityHandle  owner_handle 
)

Definition at line 131 of file SharedSetData.cpp.

132 {
133  ErrorCode rval;
134  SharedSetTagData data;
135  rval = mb.tag_get_data( sharedSetTag, &set, 1, &data );
136  if( MB_SUCCESS != rval ) return rval;
137 
138  if( data.ownerHandle )
139  {
140  RHMap::iterator i = handleMap.find( data.ownerRank );
141  if( i != handleMap.end() )
142  {
143  i->second.erase( data.ownerHandle, 1 );
144  }
145  }
146 
147  data.ownerRank = owner_rank;
148  data.ownerHandle = owner_handle;
149  rval = mb.tag_set_data( sharedSetTag, &set, 1, &data );
150  if( MB_SUCCESS != rval ) return rval;
151 
152  if( !handleMap[owner_rank].insert( owner_handle, set, 1 ).second )
153  {
154  assert( false );
155  return MB_FAILURE;
156  }
157 
158  return MB_SUCCESS;
159 }

References ErrorCode, handleMap, mb, MB_SUCCESS, moab::SharedSetData::SharedSetTagData::ownerHandle, moab::SharedSetData::SharedSetTagData::ownerRank, sharedSetTag, moab::Interface::tag_get_data(), and moab::Interface::tag_set_data().

Referenced by moab::ParallelComm::resolve_shared_sets().

◆ set_sharing_procs()

ErrorCode moab::SharedSetData::set_sharing_procs ( EntityHandle  set_handle,
std::vector< unsigned > &  ranks 
)

set/update sharing list for a set

\NOTE sorts ranks vector

Definition at line 161 of file SharedSetData.cpp.

162 {
163  std::sort( ranks.begin(), ranks.end() );
164  RProcMap::iterator it = procListMap.insert( ranks ).first;
165 
166  ErrorCode rval;
167  SharedSetTagData data;
168  rval = mb.tag_get_data( sharedSetTag, &entity_set, 1, &data );
169  if( MB_SUCCESS != rval ) return rval;
170 
171  data.sharingProcs = &*it;
172  rval = mb.tag_set_data( sharedSetTag, &entity_set, 1, &data );
173  if( MB_SUCCESS != rval ) return rval;
174 
175  return MB_SUCCESS;
176 }

References ErrorCode, mb, MB_SUCCESS, procListMap, sharedSetTag, moab::SharedSetData::SharedSetTagData::sharingProcs, moab::Interface::tag_get_data(), and moab::Interface::tag_set_data().

Referenced by moab::ParallelComm::resolve_shared_sets().

Member Data Documentation

◆ handleMap

RHMap moab::SharedSetData::handleMap
private

Map for lookup of ProcHandleMapType instance by rank

Definition at line 150 of file SharedSetData.hpp.

Referenced by get_local_handle(), get_owning_procs(), get_shared_sets(), and set_owner().

◆ mb

Interface& moab::SharedSetData::mb
private

◆ procListMap

RProcMap moab::SharedSetData::procListMap
private

Storage of sharing lists

Definition at line 153 of file SharedSetData.hpp.

Referenced by set_sharing_procs().

◆ sharedSetTag

Tag moab::SharedSetData::sharedSetTag
private

Shared set data: opaque tag containing struct SharedSetTagData

Definition at line 97 of file SharedSetData.hpp.

Referenced by get_owner(), get_sharing_procs(), set_owner(), set_sharing_procs(), SharedSetData(), and ~SharedSetData().


The documentation for this class was generated from the following files: