Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ParallelData.cpp
Go to the documentation of this file.
1 #include "moab/ParallelData.hpp"
2 #include "moab/ParallelComm.hpp"
4 #include "moab/Interface.hpp"
5 
6 #include <map>
7 
8 namespace moab
9 {
10 
11 //! return partition sets; if tag_name is input, gets sets with
12 //! that tag name, otherwise uses PARALLEL_PARTITION tag
13 ErrorCode ParallelData::get_partition_sets( Range& part_sets, const char* tag_name )
14 {
15  Tag part_tag = 0;
16  ErrorCode result;
17 
18  if( NULL != tag_name )
19  result = mbImpl->tag_get_handle( tag_name, 1, MB_TYPE_INTEGER, part_tag );
20  else
22 
23  if( MB_SUCCESS != result )
24  return result;
25  else if( 0 == part_tag )
26  return MB_TAG_NOT_FOUND;
27 
28  result = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET, &part_tag, NULL, 1, part_sets, Interface::UNION );
29  return result;
30 }
31 
32 //! get communication interface sets and the processors with which
33 //! this processor communicates; sets are sorted by processor
34 ErrorCode ParallelData::get_interface_sets( std::vector< EntityHandle >& iface_sets, std::vector< int >& iface_procs )
35 {
36 #define CONTINUE \
37  { \
38  result = tmp_result; \
39  continue; \
40  }
41  iface_sets.clear();
42  iface_procs.clear();
43 
44  Tag proc_tag = 0, procs_tag = 0;
45  ErrorCode result = MB_SUCCESS;
46  int my_rank;
47  if( parallelComm )
48  my_rank = parallelComm->proc_config().proc_rank();
49  else
50  return MB_FAILURE;
51 
52  std::multimap< int, EntityHandle > iface_data;
53 
54  for( int i = 0; i < 2; i++ )
55  {
56  ErrorCode tmp_result;
57 
58  if( 0 == i )
60  else
61  tmp_result =
63  if( MB_SUCCESS != tmp_result ) CONTINUE;
64 
65  int tsize;
66  tmp_result = mbImpl->tag_get_length( proc_tag, tsize );
67  if( 0 == tsize || MB_SUCCESS != tmp_result ) CONTINUE;
68 
69  Range proc_sets;
70  tmp_result =
71  mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET, &proc_tag, NULL, 1, proc_sets, Interface::UNION );
72  if( MB_SUCCESS != tmp_result ) CONTINUE;
73 
74  if( proc_sets.empty() ) CONTINUE;
75 
76  std::vector< int > proc_tags( proc_sets.size() * tsize );
77  tmp_result = mbImpl->tag_get_data( procs_tag, proc_sets, &proc_tags[0] );
78  if( MB_SUCCESS != tmp_result ) CONTINUE;
79  int k;
80  Range::iterator rit;
81 
82  for( k = 0, rit = proc_sets.begin(); rit != proc_sets.end(); ++rit, k++ )
83  {
84  for( int j = 0; j < tsize; j++ )
85  {
86  if( my_rank != proc_tags[2 * k + j] && proc_tags[2 * k + j] >= 0 )
87  iface_data.insert( std::pair< int, EntityHandle >( proc_tags[2 * k + j], *rit ) );
88  }
89  }
90  }
91 
92  // now get the results in sorted order
93  std::multimap< int, EntityHandle >::iterator mit;
94  for( mit = iface_data.begin(); mit != iface_data.end(); ++mit )
95  iface_procs.push_back( ( *mit ).first ), iface_sets.push_back( ( *mit ).second );
96 
97  return result;
98 }
99 
100 } // namespace moab