Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
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.
ErrorCode get_sharing_procs (EntityHandle entity_set, std::vector< unsigned > &ranks_out) const
 Get ranks of sharing procs.
ErrorCode get_shared_sets (Range &sets_out) const
 Get handles for all shared sets.
ErrorCode get_shared_sets (unsigned rank, Range &sets_out) const
 Get handles for all sets shared with specified process.
ErrorCode get_owner (EntityHandle set, unsigned &rank_out, EntityHandle &remote_handle_out) const
 Get owner and owner's handle for shared set.
ErrorCode get_owner (EntityHandle set, unsigned &rank_out) const
 Get owner of shared set.
ErrorCode get_owner_handle (EntityHandle set, EntityHandle &handle_out) const
 Get owner's handle for shared set.
ErrorCode get_local_handle (unsigned owner_rank, EntityHandle remote_handle, EntityHandle &local_handle_out) const
 Get local handle for shared set.
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

Private Types

typedef RangeMap< EntityHandle,
EntityHandle
ProcHandleMapType
typedef std::map< unsigned,
ProcHandleMapType
RHMap
typedef std::set< std::vector
< unsigned >, less_vect
RProcMap

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

Map type for lookup of local handle given remote handle

Definition at line 100 of file SharedSetData.hpp.

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

Definition at line 145 of file SharedSetData.hpp.

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

Definition at line 146 of file SharedSetData.hpp.


Constructor & Destructor Documentation

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

Definition at line 15 of file SharedSetData.cpp.

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().

                                                                       : mb( moab ), sharedSetTag( 0 )
{
    SharedSetTagData zero;

    // Zero out any padding bytes in SharedSetTagData (used for memory alignment)
    // Otherwise, memcmp could lead to unexpected false negatives for comparison
    memset( &zero, 0, sizeof( SharedSetTagData ) );

    zero.ownerRank    = rank;
    zero.ownerHandle  = 0;
    zero.sharingProcs = NULL;
    // band-aid: make sure the tag is unique, to not interfere with different pcID
    // maybe a better solution is needed
    // pcID can be at most 64, it ranges from 0 to 63; problems appear at migrate mesh
    std::ostringstream sharedTagUniqueName;
    sharedTagUniqueName << "__sharedSetTag" << pcID;
    ErrorCode rval = mb.tag_get_handle( sharedTagUniqueName.str().c_str(), sizeof( SharedSetTagData ), MB_TYPE_OPAQUE,
                                        sharedSetTag, MB_TAG_CREAT | MB_TAG_SPARSE, &zero );
    assert( MB_SUCCESS == rval );
    if( MB_SUCCESS != rval )
    {
        fprintf( stderr, "Aborted from the constructor of SharedSetData.\n" );
        abort();
    }
}

Member Function Documentation

void moab::SharedSetData::append_local_handles ( const ProcHandleMapType map,
Range append_to_this 
) [static, private]

Definition at line 178 of file SharedSetData.cpp.

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

Referenced by get_shared_sets().

{
    Range::iterator hint = range.begin();
    for( ProcHandleMapType::const_iterator i = map.begin(); i != map.end(); ++i )
        hint = range.insert( hint, i->value, i->value + i->count - 1 );
}
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.

References handleMap, and MB_SUCCESS.

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

{
    RHMap::const_iterator i = handleMap.find( owner_rank );
    assert( i != handleMap.end() );
    if( i == handleMap.end() )
    {
        local_handle = ~(EntityHandle)0;
        return MB_FAILURE;
    }

    if( !i->second.find( remote_handle, local_handle ) )
    {
        assert( false );
        local_handle = ~(EntityHandle)0;
        return MB_FAILURE;
    }

    return MB_SUCCESS;
}
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.

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().

{
    ErrorCode rval;
    SharedSetTagData data;
    rval = mb.tag_get_data( sharedSetTag, &entity_set, 1, &data );
    if( MB_SUCCESS != rval ) return rval;

    if( !data.ownerHandle )
    {                                  // not shared
        assert( !data.sharingProcs );  // really not shared
        data.ownerHandle = entity_set;
    }

    rank_out          = data.ownerRank;
    remote_handle_out = data.ownerHandle;
    return MB_SUCCESS;
}
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.

References get_owner().

    {
        EntityHandle h;
        return get_owner( set, rank_out, h );
    }
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.

References get_owner().

    {
        unsigned rank;
        return get_owner( set, rank, handle_out );
    }
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.

References handleMap, and MB_SUCCESS.

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

{
    ranks_out.clear();
    ranks_out.reserve( handleMap.size() );
    for( RHMap::const_iterator i = handleMap.begin(); i != handleMap.end(); ++i )
        ranks_out.push_back( i->first );
    return MB_SUCCESS;
}

Get handles for all shared sets.

Definition at line 67 of file SharedSetData.cpp.

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

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

{
    //  sets_out.clear();
    //  return mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &sharedSetTag, 1, 0, sets_out );

    sets_out.clear();
    for( RHMap::const_iterator i = handleMap.begin(); i != handleMap.end(); ++i )
        append_local_handles( i->second, sets_out );
    return MB_SUCCESS;
}
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.

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

{
    sets_out.clear();
    //  if (rank == myRank) {
    //    return mb.get_entities_by_type_and_tag( 0, MBENTITYSET,
    //  }
    //  else {
    RHMap::const_iterator i = handleMap.find( rank );
    if( i != handleMap.end() ) append_local_handles( i->second, sets_out );
    return MB_SUCCESS;
    //  }
}
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.

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

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

{
    ErrorCode rval;
    SharedSetTagData data;
    rval = mb.tag_get_data( sharedSetTag, &entity_set, 1, &data );
    if( MB_SUCCESS != rval ) return rval;

    ranks_out.clear();
    if( data.sharingProcs ) ranks_out = *data.sharingProcs;
    return MB_SUCCESS;
}
ErrorCode moab::SharedSetData::set_owner ( EntityHandle  set,
unsigned  owner_rank,
EntityHandle  owner_handle 
)

Definition at line 131 of file SharedSetData.cpp.

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().

{
    ErrorCode rval;
    SharedSetTagData data;
    rval = mb.tag_get_data( sharedSetTag, &set, 1, &data );
    if( MB_SUCCESS != rval ) return rval;

    if( data.ownerHandle )
    {
        RHMap::iterator i = handleMap.find( data.ownerRank );
        if( i != handleMap.end() )
        {
            i->second.erase( data.ownerHandle, 1 );
        }
    }

    data.ownerRank   = owner_rank;
    data.ownerHandle = owner_handle;
    rval             = mb.tag_set_data( sharedSetTag, &set, 1, &data );
    if( MB_SUCCESS != rval ) return rval;

    if( !handleMap[owner_rank].insert( owner_handle, set, 1 ).second )
    {
        assert( false );
        return MB_FAILURE;
    }

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

set/update sharing list for a set

sorts ranks vector

Definition at line 161 of file SharedSetData.cpp.

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().

{
    std::sort( ranks.begin(), ranks.end() );
    RProcMap::iterator it = procListMap.insert( ranks ).first;

    ErrorCode rval;
    SharedSetTagData data;
    rval = mb.tag_get_data( sharedSetTag, &entity_set, 1, &data );
    if( MB_SUCCESS != rval ) return rval;

    data.sharingProcs = &*it;
    rval              = mb.tag_set_data( sharedSetTag, &entity_set, 1, &data );
    if( MB_SUCCESS != rval ) return rval;

    return MB_SUCCESS;
}

Member Data Documentation

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().

Storage of sharing lists

Definition at line 153 of file SharedSetData.hpp.

Referenced by set_sharing_procs().

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().

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines