MOAB: Mesh Oriented datABase  (version 5.2.1)
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 {
00010 
00011 //! return partition sets; if tag_name is input, gets sets with
00012 //! that tag name, otherwise uses PARALLEL_PARTITION tag
00013 ErrorCode ParallelData::get_partition_sets( Range& part_sets, 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 )
00024         return result;
00025     else if( 0 == part_tag )
00026         return MB_TAG_NOT_FOUND;
00027 
00028     result = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET, &part_tag, NULL, 1, part_sets, Interface::UNION );
00029     return result;
00030 }
00031 
00032 //! get communication interface sets and the processors with which
00033 //! this processor communicates; sets are sorted by processor
00034 ErrorCode ParallelData::get_interface_sets( std::vector< EntityHandle >& iface_sets, std::vector< int >& iface_procs )
00035 {
00036 #define CONTINUE             \
00037     {                        \
00038         result = tmp_result; \
00039         continue;            \
00040     }
00041     iface_sets.clear();
00042     iface_procs.clear();
00043 
00044     Tag proc_tag = 0, procs_tag = 0;
00045     ErrorCode result = MB_SUCCESS;
00046     int my_rank;
00047     if( parallelComm )
00048         my_rank = parallelComm->proc_config().proc_rank();
00049     else
00050         return MB_FAILURE;
00051 
00052     std::multimap< int, EntityHandle > iface_data;
00053 
00054     for( int i = 0; i < 2; i++ )
00055     {
00056         ErrorCode tmp_result;
00057 
00058         if( 0 == i )
00059             tmp_result = mbImpl->tag_get_handle( PARALLEL_SHARED_PROC_TAG_NAME, 1, MB_TYPE_INTEGER, proc_tag );
00060         else
00061             tmp_result =
00062                 mbImpl->tag_get_handle( PARALLEL_SHARED_PROCS_TAG_NAME, MAX_SHARING_PROCS, MB_TYPE_INTEGER, proc_tag );
00063         if( MB_SUCCESS != tmp_result ) CONTINUE;
00064 
00065         int tsize;
00066         tmp_result = mbImpl->tag_get_length( proc_tag, tsize );
00067         if( 0 == tsize || MB_SUCCESS != tmp_result ) CONTINUE;
00068 
00069         Range proc_sets;
00070         tmp_result =
00071             mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET, &proc_tag, NULL, 1, proc_sets, Interface::UNION );
00072         if( MB_SUCCESS != tmp_result ) CONTINUE;
00073 
00074         if( proc_sets.empty() ) CONTINUE;
00075 
00076         std::vector< int > proc_tags( proc_sets.size() * tsize );
00077         tmp_result = mbImpl->tag_get_data( procs_tag, proc_sets, &proc_tags[0] );
00078         if( MB_SUCCESS != tmp_result ) CONTINUE;
00079         int k;
00080         Range::iterator rit;
00081 
00082         for( k = 0, rit = proc_sets.begin(); rit != proc_sets.end(); ++rit, k++ )
00083         {
00084             for( int j = 0; j < tsize; j++ )
00085             {
00086                 if( my_rank != proc_tags[2 * k + j] && proc_tags[2 * k + j] >= 0 )
00087                     iface_data.insert( std::pair< int, EntityHandle >( proc_tags[2 * k + j], *rit ) );
00088             }
00089         }
00090     }
00091 
00092     // now get the results in sorted order
00093     std::multimap< int, EntityHandle >::iterator mit;
00094     for( mit = iface_data.begin(); mit != iface_data.end(); ++mit )
00095         iface_procs.push_back( ( *mit ).first ), iface_sets.push_back( ( *mit ).second );
00096 
00097     return result;
00098 }
00099 
00100 }  // namespace moab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines