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