moab
ParallelData.cpp
Go to the documentation of this file.
00001 #include "moab/ParallelData.hpp"
00002 #include "moab/ParallelComm.hpp"
00003 #include "MBParallelConventions.h"
00004 #include "moab/Interface.hpp"
00005 
00006 #include <map>
00007 
00008 namespace moab {
00009 
00012 ErrorCode ParallelData::get_partition_sets(Range &part_sets,
00013                                                const char *tag_name) 
00014 {
00015   Tag part_tag = 0;
00016   ErrorCode result;
00017   
00018   if (NULL != tag_name) 
00019     result = mbImpl->tag_get_handle(tag_name, 1, MB_TYPE_INTEGER, part_tag);
00020   else
00021     result = mbImpl->tag_get_handle(PARALLEL_PARTITION_TAG_NAME, 1, MB_TYPE_INTEGER, part_tag);
00022     
00023   if (MB_SUCCESS != result) return result;
00024   else if (0 == part_tag) return MB_TAG_NOT_FOUND;
00025   
00026   result = mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag, 
00027                                                 NULL, 1, part_sets,
00028                                                 Interface::UNION);
00029   return result;
00030 }
00031   
00032 
00035 ErrorCode ParallelData::get_interface_sets(std::vector<EntityHandle> &iface_sets,
00036                                                std::vector<int> &iface_procs) 
00037 {
00038 #define CONTINUE {result = tmp_result; continue;}
00039   iface_sets.clear();
00040   iface_procs.clear();
00041   
00042   Tag proc_tag = 0, procs_tag = 0;
00043   ErrorCode result = MB_SUCCESS;
00044   int my_rank;
00045   if (parallelComm) 
00046     my_rank = parallelComm->proc_config().proc_rank();
00047   else 
00048     return MB_FAILURE;
00049 
00050   std::multimap<int, EntityHandle> iface_data;
00051 
00052   for (int i = 0; i < 2; i++) {
00053     ErrorCode tmp_result;
00054     
00055     if (0 == i)
00056       tmp_result = mbImpl->tag_get_handle(PARALLEL_SHARED_PROC_TAG_NAME, 
00057                                       1, MB_TYPE_INTEGER, proc_tag);
00058     else
00059       tmp_result = mbImpl->tag_get_handle(PARALLEL_SHARED_PROCS_TAG_NAME, 
00060                                       MAX_SHARING_PROCS, MB_TYPE_INTEGER, proc_tag);
00061     if (MB_SUCCESS != tmp_result) CONTINUE;
00062 
00063     int tsize;
00064     tmp_result = mbImpl->tag_get_length(proc_tag, tsize);
00065     if (0 == tsize || MB_SUCCESS != tmp_result) CONTINUE;
00066     
00067     Range proc_sets;
00068     tmp_result = mbImpl->get_entities_by_type_and_tag(0, MBENTITYSET, 
00069                                                   &proc_tag, NULL, 1,
00070                                                   proc_sets, Interface::UNION);
00071     if (MB_SUCCESS != tmp_result) CONTINUE;
00072     
00073     if (proc_sets.empty()) CONTINUE;
00074       
00075     std::vector<int> proc_tags(proc_sets.size()*tsize);
00076     tmp_result = mbImpl->tag_get_data(procs_tag, proc_sets, &proc_tags[0]);
00077     if (MB_SUCCESS != tmp_result) CONTINUE;
00078     int k;
00079     Range::iterator rit;
00080     
00081     for (k = 0, rit = proc_sets.begin(); rit != proc_sets.end(); rit++, k++) {
00082       for (int j = 0; j < tsize; j++) {
00083         if (my_rank != proc_tags[2*k+j] && proc_tags[2*k+j] >= 0)
00084           iface_data.insert(std::pair<int,EntityHandle>(proc_tags[2*k+j], *rit));
00085       }
00086     }
00087   }
00088 
00089     // now get the results in sorted order
00090   std::multimap<int,EntityHandle>::iterator mit;
00091   for (mit = iface_data.begin(); mit != iface_data.end(); mit++)
00092     iface_procs.push_back((*mit).first),
00093       iface_sets.push_back((*mit).second);
00094     
00095   return result;
00096 }
00097 
00098 
00099 } // namespace moab
00100 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines