[MOAB-dev] r2154 - MOAB/trunk/tools/iMesh
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Mon Oct 20 12:50:59 CDT 2008
Author: kraftche
Date: 2008-10-20 12:50:57 -0500 (Mon, 20 Oct 2008)
New Revision: 2154
Modified:
MOAB/trunk/tools/iMesh/iMeshP.h
MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp
Log:
Partial and untested (it compiles) iMeshP
- some functions completely implemented
- a couple of functions partially implemented (print warning but
do correct thing most of the time)
- remaining functions stubbed (print warning and return NOT_SUPPORTED)
Modified: MOAB/trunk/tools/iMesh/iMeshP.h
===================================================================
--- MOAB/trunk/tools/iMesh/iMeshP.h 2008-10-16 19:27:31 UTC (rev 2153)
+++ MOAB/trunk/tools/iMesh/iMeshP.h 2008-10-20 17:50:57 UTC (rev 2154)
@@ -136,7 +136,7 @@
* invalidate it.
* COMMUNICATION: Collective.*/
void iMeshP_destroyPartitionAll(iMesh_Instance instance,
- /*inout*/ iMeshP_PartitionHandle *partition_handle,
+ /*inout*/ iMeshP_PartitionHandle partition_handle,
int *err);
/** Given a partition handle, return its communicator.
@@ -194,7 +194,7 @@
void iMeshP_getLocalParts(iMesh_Instance instance,
const iMeshP_PartitionHandle partition_handle,
int *num_local_part,
- iMeshP_PartHandle *part_handles,
+ iMeshP_PartHandle **part_handles,
int *part_handles_allocated,
int *part_handles_size,
int *err);
@@ -254,7 +254,7 @@
* COMMUNICATION: None.*/
void iMeshP_destroyPart(iMesh_Instance instance,
/*in*/ iMeshP_PartitionHandle partition_handle,
- /*inout*/ iMeshP_PartHandle *part_handle,
+ /*inout*/ iMeshP_PartHandle part_handle,
int *err);
/********************************
Modified: MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp
===================================================================
--- MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp 2008-10-16 19:27:31 UTC (rev 2153)
+++ MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp 2008-10-20 17:50:57 UTC (rev 2154)
@@ -7,38 +7,18 @@
#include "MBParallelComm.hpp"
#include "MBParallelConventions.h"
+#define IS_BUILDING_MB
+#include "MBInternals.hpp"
+#undef IS_BUILDING_MB
+
+#include <assert.h>
+
#ifdef USE_MPI
#include "mpi.h"
#endif
-#define MBI reinterpret_cast<MBInterface*>(instance)
+/********************* enum conversion tables **************************/
-#define RETURN(a) {iMesh_LAST_ERROR.error_type = a; *err = a;return;}
-#define iMesh_processError(a, b) {sprintf(iMesh_LAST_ERROR.description, "%s", b); iMesh_LAST_ERROR.error_type = a; *err = a;}
-
-// TAG_CHECK_SIZE is like CHECK_SIZE except it checks for and makes the allocated memory
-// size a multiple of sizeof(void*), and the pointer is assumed to be type char*
-#define TAG_CHECK_SIZE(array, allocated, size) \
- if (0 != allocated && NULL != array && allocated < (size)) {\
- iMesh_processError(iBase_MEMORY_ALLOCATION_FAILED, \
- "Allocated array not large enough to hold returned contents.");\
- RETURN(iBase_MEMORY_ALLOCATION_FAILED);\
- }\
- if (NULL == array || allocated == 0) {\
- allocated=(size); \
- if (allocated%sizeof(void*) != 0) allocated=((size)/sizeof(void*)+1)*sizeof(void*);\
- array = (char*)malloc(allocated); \
- if (NULL == array) {iMesh_processError(iBase_MEMORY_ALLOCATION_FAILED, \
- "Couldn't allocate array.");RETURN(iBase_MEMORY_ALLOCATION_FAILED); }\
- }
-#define HANDLE_ARRAY_PTR(array) reinterpret_cast<MBEntityHandle*>(array)
-#define CONST_HANDLE_ARRAY_PTR(array) reinterpret_cast<const MBEntityHandle*>(array)
-#define TAG_HANDLE(handle) reinterpret_cast<MBTag>(handle)
-#define CONST_TAG_HANDLE(handle) static_cast<const MBTag>(handle)
-#define ENTITY_HANDLE(handle) reinterpret_cast<MBEntityHandle>(handle)
-#define CONST_ENTITY_HANDLE(handle) reinterpret_cast<const MBEntityHandle>(handle)
-#define RANGE_ITERATOR(it) reinterpret_cast<RangeIterator*>(it)
-
const iBase_ErrorType iBase_ERROR_MAP[] =
{
iBase_SUCCESS, // MB_SUCCESS = 0,
@@ -52,11 +32,173 @@
iBase_FILE_WRITE_ERROR, // MB_FILE_WRITE_ERROR,
iBase_NOT_SUPPORTED, // MB_NOT_IMPLEMENTED,
iBase_TAG_ALREADY_EXISTS, // MB_ALREADY_ALLOCATED,
+ iBase_FAILURE, // MB_VARIABLE_DATA_LENGTH,
+ iBase_FAILURE, // MB_INVALID_SIZE,
iBase_FAILURE // MB_FAILURE};
};
+// map to MB's entity type from TSTT's entity topology
+const MBEntityType mb_topology_table[] =
+{
+ MBVERTEX,
+ MBEDGE,
+ MBPOLYGON,
+ MBTRI,
+ MBQUAD,
+ MBPOLYHEDRON,
+ MBTET,
+ MBHEX,
+ MBPRISM,
+ MBPYRAMID,
+ MBMAXTYPE,
+ MBMAXTYPE
+};
+
+const iMesh_EntityTopology tstt_topology_table[] =
+{
+ iMesh_POINT, // MBVERTEX
+ iMesh_LINE_SEGMENT, // MBEDGE
+ iMesh_TRIANGLE, // MBTRI
+ iMesh_QUADRILATERAL, // MBQUAD
+ iMesh_POLYGON, // MBPOLYGON
+ iMesh_TETRAHEDRON, // MBTET
+ iMesh_PYRAMID, // MBPYRAMID
+ iMesh_PRISM, // MBPRISM
+ iMesh_ALL_TOPOLOGIES, // MBKNIFE
+ iMesh_HEXAHEDRON, // MBHEX
+ iMesh_POLYHEDRON, // MBPOLYHEDRON
+ iMesh_ALL_TOPOLOGIES, // MBENTITYSET
+ iMesh_ALL_TOPOLOGIES, // MBMAXTYPE
+};
+
+/********************* Error Handling **************************/
+
extern iBase_Error iMesh_LAST_ERROR;
+static inline MBInterface* MBI_cast( iMesh_Instance i )
+ { return reinterpret_cast<MBInterface*>(i); }
+#define MBI MBI_cast(instance)
+
+#define RETURN(a) do {iMesh_LAST_ERROR.error_type = a; *err = a; return;} while(false)
+
+#define CHKERR(err) if (MB_SUCCESS != (err)) RETURN(iBase_ERROR_MAP[err])
+
+#define FIXME printf("Warning: function has incomplete implementation: %s\n", __func__ )
+
+
+/********************* Part IDs **************************/
+
+static inline
+unsigned PART_ID( unsigned rank, unsigned local_id ) {
+ const unsigned rank_bits = sizeof(unsigned)*4 - 1;
+ const unsigned id_bits = sizeof(unsigned)*4;
+ assert(local_id < (1 << id_bits));
+ assert(rank < (1 << rank_bits));
+ return (rank << id_bits) | local_id;
+}
+
+static inline
+unsigned RANK( unsigned part_id ) {
+ const unsigned id_bits = sizeof(unsigned)*4;
+ return (part_id >> id_bits);
+}
+
+static inline
+unsigned LOCAL_ID( unsigned part_id ) {
+ const unsigned id_bits = sizeof(unsigned)*4;
+ const unsigned mask = ~((1 << id_bits) - 1);
+ return (part_id & mask);
+}
+
+
+/******** Type-safe casting between MOAB and ITAPS types *********/
+
+#ifndef NO_SPEICALIZED_TEMPLATE_FUNCTIONS
+// if no template specializtion, disable some type checking
+template <typename T> inline
+T itaps_cast( MBEntityHandle handle )
+{
+ assert(sizeof(handle) >= sizeof(T));
+ return reinterpret_cast<T>(handle);
+}
+#else
+
+// basic template method : only works to cast to equivalent types (no-op)
+template <typename T> inline
+T itaps_cast( MBEntityHandle )
+{ return h; }
+// verify size and do reinterpret cast
+template <typename T> inline T itaps_cast_internal_( MBEntityHandle h )
+{
+ assert(sizeof(T) >= sizeof(MBEntityHandle));
+ return reinterpret_cast<T>(h);
+}
+// verify set-type handle before cast
+template <typename T> inline T itaps_set_cast_( MBEntityHandle h )
+{
+ assert(TYPE_FROM_HANDLE(h) == MBENTITYSET);
+ return itaps_cast_internal_<T>(h);
+}
+// Specializations if generic template for ITAPS types that
+// an MBEntityHandle can be legitimately cast to.
+template <> inline
+iMeshP_PartitionHandle itaps_cast<iMeshP_PartitionHandle>( MBEntityHandle h )
+ { return itaps_set_cast_<iMeshP_PartitionHandle>(h); }
+template <> inline
+iMeshP_PartHandle itaps_cast<iMeshP_PartHandle>( MBEntityHandle h )
+ { return itaps_set_cast_<iMeshP_PartHandle>(h); }
+template <> inline
+iBase_EntitySetHandle itaps_cast<iBase_EntitySetHandle>( MBEntityHandle h )
+ { return itaps_set_cast_<iBase_EntitySetHandle>(h); }
+template <> inline
+iBase_EntityHandle itaps_cast<iBase_EntityHandle>( MBEntityHandle h )
+ { return itaps_cast_internal_<iBase_EntityHandle>(h); }
+
+#endif
+
+// Need a different function name for MBTag because (currently)
+// both MBTag and iBase_EntityHandle are void**.
+iBase_TagHandle itaps_tag_cast( MBTag t )
+{
+ assert(sizeof(iBase_TagHandle) >= sizeof(MBTag));
+ return reinterpret_cast<iBase_TagHandle>(t);
+}
+
+// No template needed when casting from ITAPS types because
+// only one valid type to cast to (MBEntityHandle).
+MBEntityHandle itaps_cast( iMeshP_PartitionHandle handle )
+ { return reinterpret_cast<MBEntityHandle>(handle); }
+MBEntityHandle itaps_cast( iMeshP_PartHandle handle )
+ { return reinterpret_cast<MBEntityHandle>(handle); }
+//MBEntityHandle itaps_cast( iBase_EntitySetHandle handle )
+// { return reinterpret_cast<MBEntityHandle>(handle); }
+MBEntityHandle itaps_cast( iBase_EntityHandle handle )
+ { return reinterpret_cast<MBEntityHandle>(handle); }
+
+// Cast arrays of ITAPS types to array of MBEntityHandle
+MBEntityHandle* itaps_cast( iMeshP_PartitionHandle* ptr )
+ { return reinterpret_cast<MBEntityHandle*>(ptr); }
+MBEntityHandle* itaps_cast( iMeshP_PartHandle* ptr )
+ { return reinterpret_cast<MBEntityHandle*>(ptr); }
+//MBEntityHandle* itaps_cast( iBase_EntitySetHandle* ptr )
+// { return reinterpret_cast<MBEntityHandle*>(ptr); }
+MBEntityHandle* itaps_cast( iBase_EntityHandle* ptr )
+ { return reinterpret_cast<MBEntityHandle*>(ptr); }
+
+// Cast const arrays of ITAPS types to array of MBEntityHandle
+const MBEntityHandle* itaps_cast( const iMeshP_PartitionHandle* ptr )
+ { return reinterpret_cast<const MBEntityHandle*>(ptr); }
+const MBEntityHandle* itaps_cast( const iMeshP_PartHandle* ptr )
+ { return reinterpret_cast<const MBEntityHandle*>(ptr); }
+//const MBEntityHandle* itaps_cast( const iBase_EntitySetHandle* ptr )
+// { return reinterpret_cast<const MBEntityHandle*>(ptr); }
+const MBEntityHandle* itaps_cast( const iBase_EntityHandle* ptr )
+ { return reinterpret_cast<const MBEntityHandle*>(ptr); }
+
+
+/********************* ITAPS arrays **************************/
+
+// Access this method using ALLOCATE_ARRAY macro, rather than callind directly.
template <typename ArrType> inline bool
allocate_itaps_array( ArrType*& array, int& allocated, int& size, int requested )
{
@@ -71,6 +213,7 @@
}
}
+// For use by ALLOCATE_ARRAY macro
inline int allocate_itaps_array_failed()
{
strcpy( iMesh_LAST_ERROR.description,
@@ -80,228 +223,906 @@
return iBase_MEMORY_ALLOCATION_FAILED;
}
+// If ITAPS array is NULL, allocate it to the requested size, otherwise
+// verify that it can hold at least SIZE values.
#define ALLOCATE_ARRAY( NAME, SIZE ) \
if (!allocate_itaps_array( *NAME, *NAME##_allocated, *NAME##_size, (SIZE) )) \
RETURN(allocate_itaps_array_failed())
+// Handle returning MBRange in ITAPS array (do ALLOCATE_ARRAY and copy).
+#define MBRANGE_TO_ITAPS_ARRAY( RANGE, NAME ) do { \
+ ALLOCATE_ARRAY( NAME, (RANGE).size() ); \
+ std::copy( (RANGE).begin(), (RANGE).end(), itaps_cast(*(NAME)) ); \
+ } while (false)
+
+
+/********************* iMeshP API **************************/
+
#ifdef __cplusplus
extern "C" {
#endif
-void iMeshP_createPartitionAll( iMesh_Instance /*instance*/,
- /*in*/ MPI_Comm /*communicator*/,
- /*out*/ iMeshP_PartitionHandle */*partition_handle*/,
+void iMeshP_createPartitionAll( iMesh_Instance instance,
+ /*in*/ MPI_Comm communicator,
+ /*out*/ iMeshP_PartitionHandle *partition_handle,
int *err )
{
- RETURN(iBase_NOT_SUPPORTED);
+ partition_handle = 0;
+
+ MBTag prtn_tag;
+ MBErrorCode rval = MBI->tag_create( PARALLEL_PARITIONING_TAG_NAME,
+ sizeof(int),
+ MB_TAG_SPARSE,
+ MB_TYPE_INTEGER,
+ prtn_tag,
+ 0,
+ true ); CHKERR(rval);
+
+ MBEntityHandle handle;
+ rval = MBI->create_meshset( MESHSET_SET, handle ); CHKERR(rval);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, handle, &communicator );
+ if (!pcomm) {
+ MBI->delete_entities( &handle, 1 );
+ RETURN(MB_FAILURE);
+ }
+
+ *partition_handle = itaps_cast<iMeshP_PartitionHandle>(handle);
+ RETURN (iBase_SUCCESS);
}
-// Given a partition handle, a part handle, and an entity handle, return a
-// flag indicating whether the entity is strictly internal, on a
-// boundary, or a ghost.
-// If part_handle is remote, an error is returned.
-// COMMUNICATION: None.
- void iMeshP_getEntStatus(iMesh_Instance instance,
- /*in*/ const iMeshP_PartitionHandle,
- /*in*/ const iMeshP_PartHandle,
- /*in*/ const iBase_EntityHandle entity_handle,
- /*out*/ int* par_status, // Values=INTERNAL,BOUNDARY,GHOST
- int *err)
- {
- MBParallelComm pc(MBI);
- unsigned char pstatus;
- MBErrorCode result = MBI->tag_get_data(pc.pstatus_tag(),
- CONST_HANDLE_ARRAY_PTR(&entity_handle), 1,
- &pstatus);
- if (MB_SUCCESS != result) RETURN(result);
- *par_status = iMeshP_INTERNAL;
- if (pstatus & PSTATUS_GHOST) *par_status = iMeshP_GHOST;
- else if (pstatus & PSTATUS_INTERFACE) *par_status = iMeshP_BOUNDARY;
+void iMeshP_destroyPartitionAll( iMesh_Instance instance,
+ iMeshP_PartitionHandle partition_handle,
+ int *err)
+{
+ MBEntityHandle handle = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, handle );
+ if (pcomm)
+ delete pcomm;
+ MBErrorCode rval = MBI->delete_entities( &handle, 1 ); CHKERR(rval);
+ RETURN (iBase_SUCCESS);
+}
- RETURN(iBase_SUCCESS);
+void iMeshP_getPartitionComm( iMesh_Instance instance,
+ iMeshP_PartitionHandle partition_handle,
+ MPI_Comm* communicator_out,
+ int* err )
+{
+ MBEntityHandle handle = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, handle );
+ if (pcomm)
+ RETURN (iBase_FAILURE);
+ *communicator_out = pcomm->proc_config().proc_rank();
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_syncPartitionAll( iMesh_Instance /*instance*/,
+ iMeshP_PartitionHandle /*partition_handle*/,
+ int* err )
+{
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_getNumPartitions( iMesh_Instance instance,
+ int* num_partitions_out,
+ int* err )
+{
+ MBTag prtn_tag;
+ MBErrorCode rval = MBI->tag_get_handle( PARALLEL_PARITIONING_TAG_NAME, prtn_tag );
+ if (MB_TAG_NOT_FOUND == rval) {
+ *num_partitions_out = 0;
+ RETURN (iBase_SUCCESS);
}
+ CHKERR(rval);
+
+ rval = MBI->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &prtn_tag, 0, 1,
+ *num_partitions_out );
+ CHKERR(rval);
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_getPartitions( iMesh_Instance instance,
+ iMeshP_PartitionHandle **partition_handle,
+ int *partition_handle_allocated,
+ int *partition_handle_size,
+ int *err )
+{
+ MBRange range;
+ MBTag prtn_tag;
+ MBErrorCode rval = MBI->tag_get_handle( PARALLEL_PARITIONING_TAG_NAME, prtn_tag );
+ if (MB_SUCCESS == rval)
+ rval = MBI->get_entities_by_type_and_tag( 0, MBENTITYSET, &prtn_tag, 0, 1,
+ range );
+ else if (MB_TAG_NOT_FOUND == rval)
+ rval = MB_SUCCESS;
- void iMeshP_getEntStatusArr(iMesh_Instance instance,
- /*in*/ const iMeshP_PartitionHandle,
- /*in*/ const iMeshP_PartHandle part_handle,
- /*in*/ const iBase_EntityHandle *entity_handles,
- /*in*/ const int entity_handles_size,
- /*inout*/ int** par_status, // Values=INTERNAL,BOUNDARY,GHOST
- /*inout*/ int* par_status_allocated,
- /*inout*/ int* par_status_size,
- int *err)
- {
- MBParallelComm pc(MBI);
- std::vector<unsigned char> pstatus(entity_handles_size);
- MBErrorCode result = MBI->tag_get_data(pc.pstatus_tag(),
- CONST_HANDLE_ARRAY_PTR(entity_handles),
- entity_handles_size,
- &pstatus[0]);
- if (MB_SUCCESS != result) RETURN(result);
+ CHKERR(rval);
+ MBRANGE_TO_ITAPS_ARRAY( range, partition_handle );
+ RETURN (iBase_SUCCESS );
+}
- ALLOCATE_ARRAY( par_status, entity_handles_size );
+void iMeshP_getNumGobalParts( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ int *num_global_part,
+ int *err )
+{
+ FIXME;
+ RETURN (iBase_NOT_SUPPORTED);
+}
+
+void iMeshP_getNumLocalParts(iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ int *num_local_part,
+ int *err)
+{
+ MBEntityHandle prtn = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, prtn );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
- for (int i = 0; i < entity_handles_size; i++) {
- if (!pstatus[i]) (*par_status)[i] = iMeshP_INTERNAL;
- else if (pstatus[i] & PSTATUS_GHOST) (*par_status)[i] = iMeshP_GHOST;
- else if (pstatus[i] & PSTATUS_INTERFACE) (*par_status)[i] = iMeshP_BOUNDARY;
- }
+ MBRange parts;
+ MBErrorCode rval = pcomm->get_partition_sets( prtn, parts );
+ CHKERR(rval);
+
+ *num_local_part = parts.size();
+ RETURN (iBase_SUCCESS);
+}
- RETURN(iBase_SUCCESS);
+void iMeshP_getLocalParts( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ int *num_local_part,
+ iMeshP_PartHandle **part_handles,
+ int *part_handles_allocated,
+ int *part_handles_size,
+ int *err )
+{
+ MBEntityHandle prtn = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, prtn );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
+
+ MBRange parts;
+ MBErrorCode rval = pcomm->get_partition_sets( prtn, parts );
+ CHKERR(rval);
+
+ MBRANGE_TO_ITAPS_ARRAY( parts, part_handles );
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_getRankOfPart( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_Part part_id,
+ int *rank,
+ int *err )
+{
+ int junk1 = 1, junk2 = 1;
+ iMeshP_getRankOfPartArr( instance, partition_handle, &part_id,
+ 1, &rank, &junk1, &junk2, err );
+}
+
+void iMeshP_getRankOfPartArr( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_Part *part_ids,
+ const int part_ids_size,
+ int **rank,
+ int *rank_allocated,
+ int *rank_size,
+ int *err )
+{
+ FIXME; // need to handle handles to "remote parts" ?
+
+ MBEntityHandle prtn = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, prtn );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
+
+ ALLOCATE_ARRAY( rank, part_ids_size );
+ std::fill( *rank, (*rank) + part_ids_size, pcomm->proc_config().proc_rank() );
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_getNumOfTypeAll( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntitySetHandle entity_set_handle,
+ const int entity_type,
+ int *num_type,
+ int *err )
+{
+ FIXME; // need to prune out entities that are remote
+
+ MBEntityHandle prtn = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, prtn );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
+
+ iMesh_getNumOfType( instance, entity_set_handle, entity_type, num_type, err );
+ int vals[2] = { *num_type, *err }, sums[2];
+ int ierr = MPI_Allreduce( vals, sums, 2, MPI_INT, MPI_SUM, pcomm->proc_config().proc_comm() );
+ assert(iBase_SUCCESS == 0);
+ if (ierr || sums[1])
+ RETURN (iBase_FAILURE);
+
+ *num_type = sums[0];
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_getNumOfTopoAll( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntitySetHandle entity_set_handle,
+ const int entity_topology,
+ int *num_topo,
+ int *err )
+{
+ FIXME; // need to prune out entities that are remote
+
+ MBEntityHandle prtn = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, prtn );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
+
+ iMesh_getNumOfTopo( instance, entity_set_handle, entity_topology, num_topo, err );
+ int vals[2] = { *num_topo, *err }, sums[2];
+ int ierr = MPI_Allreduce( vals, sums, 2, MPI_INT, MPI_SUM, pcomm->proc_config().proc_comm() );
+ assert(iBase_SUCCESS == 0);
+ if (ierr || sums[1])
+ RETURN (iBase_FAILURE);
+
+ *num_topo = sums[0];
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_createPart( iMesh_Instance instance,
+ iMeshP_PartitionHandle partition_handle,
+ iMeshP_PartHandle *part_handle,
+ int *err )
+{
+ MBEntityHandle h, p = itaps_cast(partition_handle);
+ MBErrorCode rval;
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, p );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
+
+ const MBTag tag = pcomm->partition_tag();
+
+ MBRange parts;
+ rval = MBI->get_entities_by_handle( p, parts ); CHKERR(rval);
+ std::vector<int> part_ids( parts.size() );
+ rval = MBI->tag_get_data( tag, parts, &part_ids[0] ); CHKERR(rval);
+ int max_loc_id = -1, loc_id;
+ for (size_t i = 0; i < part_ids.size(); ++i) {
+ loc_id = LOCAL_ID( part_ids[i] );
+ if (loc_id > max_loc_id)
+ max_loc_id = loc_id;
}
+ int new_id = PART_ID( pcomm->proc_config().proc_rank(), max_loc_id + 1 );
+
-// Map from processes to parts:
-// Given a partition handle and a process rank,
-// return the part handles owned by the process.
-// COMMUNICATION: None++.
- void iMeshP_getPartsOnRank(iMesh_Instance instance,
+ rval = MBI->create_meshset( MESHSET_SET, h ); CHKERR(rval);
+ if (MB_SUCCESS == rval)
+ rval = MBI->add_entities( p, &h, 1 );
+ if (MB_SUCCESS == rval)
+ rval = MBI->tag_set_data( tag, &h, 1, &new_id );
+ if (MB_SUCCESS != rval) {
+ MBI->delete_entities( &h, 1 );
+ CHKERR(rval);
+ }
+
+ *part_handle = itaps_cast<iMeshP_PartHandle>(h);
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_destroyPart( iMesh_Instance instance,
+ iMeshP_PartitionHandle partition_handle,
+ iMeshP_PartHandle part_handle,
+ int *err )
+{
+ MBErrorCode rval;
+ MBEntityHandle h = itaps_cast(part_handle),
+ p = itaps_cast(partition_handle);
+
+
+ rval = MBI->remove_entities( p, &h, 1 ); CHKERR(rval);
+ rval = MBI->delete_entities( &h, 1 ); CHKERR(rval);
+}
+
+void iMeshP_getPartIdFromPartHandle( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ iMeshP_Part *part_id,
+ int *err )
+{
+ int junk1 = 1, junk2 = 1;
+ iMeshP_getPartIdsFromPartHandlesArr( instance,
+ partition_handle,
+ &part_handle,
+ 1,
+ &part_id,
+ &junk1,
+ &junk2,
+ err );
+}
+
+void iMeshP_getPartIdsFromPartHandlesArr( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle *part_handles,
+ const int part_handles_size,
+ iMeshP_Part **part_ids,
+ int *part_ids_allocated,
+ int *part_ids_size,
+ int *err )
+{
+ MBEntityHandle p = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, p );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
+
+ const MBTag tag = pcomm->partition_tag();
+
+ ALLOCATE_ARRAY( part_ids, part_handles_size );
+
+ int* array;
+ std::vector<int> tmp_storage;
+ if (sizeof(iMeshP_Part) == sizeof(int)) {
+ array = reinterpret_cast<int*>(*part_ids);
+ }
+ else {
+ tmp_storage.resize(part_handles_size);
+ array = &tmp_storage[0];
+ }
+
+ MBErrorCode rval = MBI->tag_get_data( tag,
+ itaps_cast(part_handles),
+ part_handles_size,
+ array ); CHKERR(rval);
+
+ if (sizeof(iMeshP_Part) != sizeof(int))
+ std::copy( array, array + part_handles_size, *part_ids );
+
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_getNumPartNbors( iMesh_Instance instance,
+ iMeshP_PartitionHandle partition_handle,
+ iMeshP_PartHandle part_handle,
+ int entity_type,
+ int *num_part_nbors,
+ int *err )
+{
+ int junk1 = 1, junk2 = 1;
+ iMeshP_getNumPartNborsArr( instance, partition_handle,
+ &part_handle, 1, entity_type,
+ &num_part_nbors, &junk1, &junk2,
+ err );
+}
+
+void iMeshP_getNumPartNborsArr( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle *part_handles,
+ const int part_handles_size,
+ int entity_type,
+ int **num_part_nbors,
+ int *num_part_nbors_allocated,
+ int *num_part_nbors_size,
+ int *err )
+{
+ FIXME;
+ RETURN( iBase_NOT_SUPPORTED );
+}
+
+
+void iMeshP_getPartNbors( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ int entity_type,
+ int *num_part_nbors,
+ iMeshP_Part **nbor_part_ids,
+ int *nbor_part_ids_allocated,
+ int *nbor_part_ids_size,
+ int *err )
+{
+ int junk1 = 1, junk2 = 1;
+ iMeshP_getPartNborsArr( instance, partition_handle,
+ &part_handle, 1, entity_type,
+ &num_part_nbors, &junk1, &junk2,
+ nbor_part_ids, nbor_part_ids_allocated,
+ nbor_part_ids_size, err );
+}
+
+void iMeshP_getPartNborsArr( iMesh_Instance instance,
const iMeshP_PartitionHandle partition_handle,
- /*in*/ const int rank,
- /*inout*/ iMeshP_PartHandle **part_handles,
- /*inout*/ int *part_handles_allocated,
- /*out*/ int *part_handles_size,
- int *err)
- {
- MBParallelComm *pc = MBParallelComm::get_pcomm(MBI, 0);
- if (!pc) RETURN(iBase_ERROR_MAP[MB_FAILURE]);
+ const iMeshP_PartHandle *part_handles,
+ const int part_handles_size,
+ int entity_type,
+ int **num_part_nbors,
+ int *num_part_nbors_allocated,
+ int *num_part_nbors_size,
+ iMeshP_Part **nbor_part_ids,
+ int *nbor_part_ids_allocated,
+ int *nbor_part_ids_size,
+ int *err )
+{
+ FIXME;
+ RETURN(iBase_NOT_SUPPORTED);
+}
- MBRange part_sets;
+void iMeshP_getNumPartBdryEnts( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const int entity_type,
+ const int entity_topology,
+ const iMeshP_Part target_part_id,
+ int *num_entities,
+ int *err )
+{
+ FIXME;
+ RETURN(iBase_NOT_SUPPORTED);
+}
+
+void iMeshP_getPartBdryEnts( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const int entity_type,
+ const int entity_topology,
+ const iMeshP_Part target_part_id,
+ iBase_EntityHandle **entity_handles,
+ int *entity_handles_allocated,
+ int *entity_handles_size,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_initPartBdryEntIter( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const int entity_type,
+ const int entity_topology,
+ const iMeshP_Part nbor_part_id,
+ iMesh_EntityIterator* entity_iterator,
+ int* err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_initPartBdryEntArrIter( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const int entity_type,
+ const int entity_topology,
+ const int array_size,
+ const iMeshP_Part nbor_part_id,
+ iMesh_EntityIterator* entity_iterator,
+ int* err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+
+
+static void set_intersection_query( iMesh_Instance instance,
+ iMeshP_PartHandle set1,
+ iBase_EntitySetHandle set2,
+ int type,
+ int topo,
+ MBRange& result,
+ int* err )
+{
+ MBErrorCode rval;
+ MBRange r1, r2;
+ MBEntityHandle h1 = itaps_cast(set1);
+ MBEntityHandle h2 = itaps_cast(set2);
- ALLOCATE_ARRAY( part_handles, pc->partition_sets().size() );
- MBRange::iterator rit;
- int i;
- for (i = 0, rit = pc->partition_sets().begin();
- rit != pc->partition_sets().end(); rit++, i++)
- (*part_handles)[i] = reinterpret_cast<iMeshP_PartHandle>(*rit);
+ if (topo != iMesh_ALL_TOPOLOGIES) {
+ if ((unsigned)topo > sizeof(mb_topology_table)/sizeof(mb_topology_table[0]))
+ RETURN (iBase_INVALID_ENTITY_TYPE);
+ MBEntityType t = mb_topology_table[topo];
+ if (t == MBMAXTYPE) {
+ result.clear();
+ RETURN (iBase_SUCCESS); // if unsupported topo, then there are zero of them
+ }
+ rval = MBI->get_entities_by_type( h1, t, r1 ); CHKERR(rval);
+ rval = MBI->get_entities_by_type( h2, t, r2 ); CHKERR(rval);
+ }
+ else if (type != iBase_ALL_TYPES) {
+ if (type < 0 || type > 3)
+ RETURN (iBase_INVALID_ENTITY_TYPE);
+ rval = MBI->get_entities_by_dimension( h1, type, r1 ); CHKERR(rval);
+ rval = MBI->get_entities_by_dimension( h2, type, r2 ); CHKERR(rval);
+ }
+ else {
+ rval = MBI->get_entities_by_handle( h1, r1 ); CHKERR(rval);
+ rval = MBI->get_entities_by_handle( h2, r2 ); CHKERR(rval);
+ }
- RETURN(iBase_SUCCESS);
+ result = r1.intersect( r2 );
+ RETURN (iBase_SUCCESS);
+}
+
+
+void iMeshP_getNumOfType( iMesh_Instance instance,
+ const iMeshP_PartitionHandle ,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntitySetHandle entity_set_handle,
+ const int entity_type,
+ int *num_type,
+ int *err )
+{
+ MBRange r;
+ set_intersection_query( instance, part_handle, entity_set_handle,
+ entity_type, iMesh_ALL_TOPOLOGIES, r, err );
+ *num_type = r.size();
+}
+
+void iMeshP_getNumOfTopo( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntitySetHandle entity_set_handle,
+ const int entity_topology,
+ int *num_topo,
+ int *err )
+{
+ MBRange r;
+ set_intersection_query( instance, part_handle, entity_set_handle,
+ iBase_ALL_TYPES, entity_topology, r, err );
+ *num_topo = r.size();
+}
+
+void iMeshP_getAllVtxCoords( iMesh_Instance instance,
+ const iMeshP_PartitionHandle ,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntitySetHandle entity_set_handle,
+ double** coordinates,
+ int* coordinates_allocated,
+ int* coordinates_size,
+ int** in_entity_set,
+ int* in_entity_set_allocated,
+ int* in_entity_set_size,
+ int* storage_order,
+ int *err )
+{
+ int dim;
+ MBErrorCode rval = MBI->get_dimension( dim ); CHKERR(rval);
+
+ MBRange r;
+ set_intersection_query( instance, part_handle, entity_set_handle,
+ iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, r, err );
+ if (*err != iBase_SUCCESS)
+ return;
+
+ MBRange v;
+ rval = MBI->get_adjacencies( r, 0, false, v, MBInterface::UNION );
+ CHKERR(rval);
+
+ const size_t n = v.size();
+ ALLOCATE_ARRAY( coordinates, dim*n );
+ ALLOCATE_ARRAY( in_entity_set, n );
+ std::fill( *in_entity_set, (*in_entity_set)+n, 1 );
+
+ switch (*storage_order) {
+ case iBase_UNDETERMINED:
+ *storage_order = iBase_INTERLEAVED;
+ // NO BREAK -- fall through
+ case iBase_INTERLEAVED:
+ rval = MBI->get_coords( v, *coordinates );
+ break;
+ case iBase_BLOCKED:
+ rval = MBI->get_coords( v,
+ *coordinates,
+ (*coordinates)+n,
+ (*coordinates)+2*n );
+ break;
+ default:
+ RETURN (iBase_INVALID_ARGUMENT);
}
+
+ CHKERR(rval);
+ RETURN (iBase_SUCCESS);
+}
+
+void iMeshP_getVtxCoordIndex( iMesh_Instance instance,
+ const iMeshP_PartitionHandle ,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntitySetHandle entity_set_handle,
+ const int requested_entity_type,
+ const int requested_entity_topology,
+ const int entity_adjacency_type,
+ int** offset,
+ int* offset_allocated,
+ int* offset_size,
+ int** index,
+ int* index_allocated,
+ int* index_size,
+ int** entity_topologies,
+ int* entity_topologies_allocated,
+ int* entity_topologies_size,
+ int *err )
+{
+ MBRange::iterator i;
+ MBRange r;
+ set_intersection_query( instance, part_handle, entity_set_handle,
+ iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, r, err );
+ if (*err != iBase_SUCCESS)
+ return;
- void iMeshP_getPartsArrOnRank(iMesh_Instance instance,
- const iMeshP_PartitionHandle partition_handle,
- /*in*/ const int *rank,
- /*in*/ const int rank_size,
- /*inout*/ iMeshP_PartHandle **part_handles,
- /*inout*/ int *part_handles_allocated,
- /*out*/ int *part_handles_size,
- int *err)
- {
- MBParallelComm *pc = MBParallelComm::get_pcomm(MBI, 0);
- if (!pc) RETURN(iBase_ERROR_MAP[MB_FAILURE]);
+ MBRange v;
+ MBErrorCode rval = MBI->get_adjacencies( r, 0, false, v, MBInterface::UNION );
+ CHKERR(rval);
- if (rank[0] != pc->proc_config().proc_rank() || rank_size > 1) {
- RETURN(iBase_ERROR_MAP[MB_NOT_IMPLEMENTED]);
+ r.clear();
+ set_intersection_query( instance, part_handle, entity_set_handle,
+ requested_entity_type, requested_entity_topology,
+ r, err );
+ if (*err != iBase_SUCCESS)
+ return;
+
+ std::vector<MBEntityHandle> sorted(v.size());
+ std::copy( v.begin(), v.end(), sorted.begin() );
+
+ if (!r.all_of_dimension(entity_adjacency_type)) {
+ MBRange r2;
+ rval = MBI->get_adjacencies( r, entity_adjacency_type, false, r2, MBInterface::UNION );
+ CHKERR(rval);
+ r.swap(r2);
+ }
+
+ // count size of connectivity data
+ size_t cn = 0;
+ int num;
+ const MBEntityHandle* conn;
+ std::vector<MBEntityHandle>::iterator s;
+ std::vector<MBEntityHandle> store;
+ for (i = r.begin(); i != r.end(); ++i) {
+ rval = MBI->get_connectivity( *i, conn, num, true, &store );
+ CHKERR(rval);
+ cn += num;
+ }
+
+ const size_t n = r.size();
+ ALLOCATE_ARRAY( offset, n );
+ ALLOCATE_ARRAY( index, cn );
+ ALLOCATE_ARRAY( entity_topologies, n );
+
+ // populate output arrays
+ int* offset_iterator = *offset;
+ int* index_iterator = *index;
+ int* topo_iterator = *entity_topologies;
+ for (i = r.begin(); i != r.end(); ++i) {
+ *offset_iterator = index_iterator - *index;
+ ++offset_iterator;
+
+ rval = MBI->get_connectivity( *i, conn, num, true, &store );
+ CHKERR(rval);
+ for (int j = 0; j < num; ++j) {
+ s = std::lower_bound( sorted.begin(), sorted.end(), conn[j] );
+ if (s == sorted.end() || *s != conn[j])
+ RETURN(iBase_FAILURE);
+ *index_iterator = s - sorted.begin();
+ ++index_iterator;
}
+
+ *topo_iterator = tstt_topology_table[ TYPE_FROM_HANDLE(*i) ];
+ ++topo_iterator;
+ }
+}
+
+void iMeshP_getEntities( iMesh_Instance instance,
+ const iMeshP_PartitionHandle ,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntitySetHandle entity_set_handle,
+ const int entity_type,
+ const int entity_topology,
+ iBase_EntityHandle** entity_handles,
+ int* entity_handles_allocated,
+ int* entity_handles_size,
+ int *err )
+{
+ MBRange r;
+ set_intersection_query( instance, part_handle, entity_set_handle,
+ entity_type, entity_topology, r, err );
+ if (iBase_SUCCESS != *err)
+ return;
- iMeshP_getPartsOnRank(instance, partition_handle, rank[0],
- part_handles, part_handles_allocated, part_handles_size,
- err);
+ MBRANGE_TO_ITAPS_ARRAY( r, entity_handles );
+ RETURN(iBase_SUCCESS);
+}
+
+void iMeshP_getAdjEntities( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntityHandle entity_set_handle,
+ const int entity_type_requestor,
+ const int entity_topology_requestor,
+ const int entity_type_requested,
+ iBase_EntityHandle** adj_entity_handles,
+ int* adj_entity_handles_allocated,
+ int* adj_entity_handles_size,
+ int** offset,
+ int* offset_allocated,
+ int* offset_size,
+ int** in_entity_set,
+ int* in_entity_set_allocated,
+ int* in_entity_set_size,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_initEntIter( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntitySetHandle entity_set_handle,
+ const int requested_entity_type,
+ const int requested_entity_topology,
+ iMesh_EntityIterator* entity_iterator,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_initEntArrIter( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntitySetHandle entity_set_handle,
+ const int requested_entity_type,
+ const int requested_entity_topology,
+ const int requested_array_size,
+ iMesh_EntityArrIterator* entArr_iterator,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_getEntOwnerPart( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntityHandle entity_handle,
+ iMeshP_Part *part_id,
+ int* err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_getEntOwnerPartArr( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntityHandle *entity_handles,
+ const int entity_handles_size,
+ iMeshP_Part **part_ids,
+ int *part_ids_allocated,
+ int *part_ids_size,
+ int* err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_isEntOwner( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntityHandle entity_handle,
+ int* is_owner,
+ int *err )
+{
+ int junk1 = 1, junk2 = 1;
+ iMeshP_isEntOwnerArr( instance, partition_handle,
+ part_handle, &entity_handle, 1,
+ &is_owner, &junk1, &junk2,
+ err );
+}
+
+void iMeshP_isEntOwnerArr( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntityHandle *entity_handles,
+ const int entity_handles_size,
+ int** is_owner,
+ int* is_owner_allocated,
+ int* is_owner_size,
+ int *err )
+{
+ MBEntityHandle p = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, p );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
+
+ const MBEntityHandle* handles = itaps_cast(entity_handles);
+ std::vector<unsigned char> pstatus(entity_handles_size);
+ MBErrorCode result = MBI->tag_get_data( pcomm->pstatus_tag(),
+ handles,
+ entity_handles_size,
+ &pstatus[0] ); CHKERR(result);
+
+ MBEntityHandle part = itaps_cast(part_handle);
+ MBRange part_ents;
+ result = MBI->get_entities_by_handle( part, part_ents );
+ CHKERR(result);
+
+ ALLOCATE_ARRAY( is_owner, entity_handles_size );
+ for (int i = 0; i < entity_handles_size; i++) {
+ if (pstatus[i] & PSTATUS_NOT_OWNED)
+ (*is_owner)[i] = 0;
+ else if (part_ents.find(handles[i]) == part_ents.end())
+ (*is_owner)[i] = 0;
+ else
+ (*is_owner)[i] = 1;
}
-// Provide entity categorization within part.
-// Given a partition handle, a part handle, and an entity handle, return a
-// flag indicating whether the entity is owned by the part.
-// If part_handle is remote, an error is returned.
-// COMMUNICATION: None.
- void iMeshP_isEntOwner(iMesh_Instance instance,
- /*in*/ const iMeshP_PartitionHandle,
+ RETURN(iBase_SUCCESS);
+}
+
+void iMeshP_getEntStatus(iMesh_Instance instance,
+ /*in*/ const iMeshP_PartitionHandle partition_handle,
/*in*/ const iMeshP_PartHandle part_handle,
/*in*/ const iBase_EntityHandle entity_handle,
- /*out*/ int* is_owner,
+ /*out*/ int* par_status, // Values=INTERNAL,BOUNDARY,GHOST
int *err)
- {
- MBParallelComm pc(MBI);
- unsigned char pstatus;
- MBErrorCode result = MBI->tag_get_data(pc.pstatus_tag(),
- CONST_HANDLE_ARRAY_PTR(&entity_handle), 1,
- &pstatus);
- if (MB_SUCCESS != result) RETURN(result);
+{
+ int junk1 = 1, junk2 = 1;
+ iMeshP_getEntStatusArr( instance, partition_handle,
+ part_handle, &entity_handle, 1,
+ &par_status, &junk1, &junk2,
+ err );
+}
- if (pstatus & PSTATUS_NOT_OWNED) *is_owner = 0;
- else *is_owner = 1;
-
- RETURN(iBase_SUCCESS);
- }
-
- void iMeshP_isEntOwnerArr(iMesh_Instance instance,
- /*in*/ const iMeshP_PartitionHandle,
+void iMeshP_getEntStatusArr(iMesh_Instance instance,
+ /*in*/ const iMeshP_PartitionHandle partition_handle,
/*in*/ const iMeshP_PartHandle part_handle,
/*in*/ const iBase_EntityHandle *entity_handles,
/*in*/ const int entity_handles_size,
- /*inout*/ int** is_owner,
- /*inout*/ int* is_owner_allocated,
- /*inout*/ int* is_owner_size,
- int *err)
- {
- MBParallelComm pc(MBI);
- std::vector<unsigned char> pstatus(entity_handles_size);
- MBErrorCode result = MBI->tag_get_data(pc.pstatus_tag(),
- CONST_HANDLE_ARRAY_PTR(entity_handles),
- entity_handles_size,
- &pstatus[0]);
- if (MB_SUCCESS != result) RETURN(result);
+ /*inout*/ int** par_status, // Values=INTERNAL,BOUNDARY,GHOST
+ /*inout*/ int* par_status_allocated,
+ /*inout*/ int* par_status_size,
+ int *err)
+{
+ MBEntityHandle p = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, p );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
- ALLOCATE_ARRAY( is_owner, entity_handles_size );
-
- for (int i = 0; i < entity_handles_size; i++) {
- if (pstatus[i] & PSTATUS_NOT_OWNED) (*is_owner)[i] = 0;
- else (*is_owner)[i] = 1;
- }
+ std::vector<unsigned char> pstatus(entity_handles_size);
+ MBErrorCode result = MBI->tag_get_data(pcomm->pstatus_tag(),
+ itaps_cast(entity_handles),
+ entity_handles_size,
+ &pstatus[0]); CHKERR(result);
- RETURN(iBase_SUCCESS);
+ ALLOCATE_ARRAY( par_status, entity_handles_size );
+ for (int i = 0; i < entity_handles_size; i++) {
+ if (!pstatus[i])
+ (*par_status)[i] = iMeshP_INTERNAL;
+ else if (pstatus[i] & PSTATUS_GHOST)
+ (*par_status)[i] = iMeshP_GHOST;
+ else if (pstatus[i] & PSTATUS_INTERFACE)
+ (*par_status)[i] = iMeshP_BOUNDARY;
}
-// Provide information about copies of entities.
-// All these functions should work on the local process as well as
-// remote processes; entity handles returned are likely but not
-// necessarily remote.
-// Given a partition handle and an entity handle, return the number
-// of copies of the entity in the partition.
-// COMMUNICATION: None++.
- void iMeshP_getNumCopies(iMesh_Instance instance,
- /*in*/ const iMeshP_PartitionHandle partition_handle,
- /*in*/ const iBase_EntityHandle entity_handle,
- /*out*/ int *num_copies_ent,
- int *err)
- {
- MBParallelComm pc(MBI);
- int shared_proc;
- MBErrorCode result = MBI->tag_get_data(pc.sharedp_tag(),
- CONST_HANDLE_ARRAY_PTR(&entity_handle), 1,
- &shared_proc);
- if (MB_SUCCESS != result) {
- RETURN(iBase_ERROR_MAP[result]);
- }
-
- if (-1 != shared_proc) {
- *num_copies_ent = 1;
- RETURN(iBase_SUCCESS);
- }
-
- static int tag_size = 0;
- if (!tag_size) {
- result = MBI->tag_get_size(pc.sharedps_tag(), tag_size);
- if (MB_SUCCESS != result) {
- RETURN(iBase_ERROR_MAP[result]);
- }
- }
- static std::vector<int> shared_procs(tag_size);
+ RETURN(iBase_SUCCESS);
+}
- result = MBI->tag_get_data(pc.sharedps_tag(),
- CONST_HANDLE_ARRAY_PTR(&entity_handle), 1,
- &shared_procs[0]);
- if (MB_SUCCESS != result) {
- RETURN(iBase_ERROR_MAP[result]);
- }
+void iMeshP_getNumCopies( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntityHandle entity_handle,
+ int *num_copies_ent,
+ int *err )
+{
+ MBEntityHandle p = itaps_cast(partition_handle);
+ MBParallelComm* pcomm = MBParallelComm::get_pcomm( MBI, p );
+ if (!pcomm)
+ RETURN (iBase_FAILURE);
- *num_copies_ent = std::find(shared_procs.begin(), shared_procs.end(), -1) - shared_procs.begin();
+ int shared_proc;
+ MBErrorCode result = MBI->tag_get_data(pcomm->sharedp_tag(),
+ itaps_cast(&entity_handle), 1,
+ &shared_proc); CHKERR(result);
+ if (-1 != shared_proc) {
+ *num_copies_ent = 1;
RETURN(iBase_SUCCESS);
}
-// Given a partition handle and an entity handle, return (remote) entity
-// handles and part handles of all copies of the entity.
-// COMMUNICATION: None++.
+ const void* data_ptr = 0;
+ int data_size = 0;
+ result = MBI->tag_get_data( pcomm->sharedps_tag(),
+ itaps_cast(&entity_handle),
+ 1,
+ &data_ptr,
+ &data_size ); CHKERR(result);
+
+ const int* shared_procs = reinterpret_cast<const int*>(data_ptr);
+ int tag_size = data_size / sizeof(int);
+ *num_copies_ent = std::find(shared_procs, shared_procs + tag_size, -1) - shared_procs;
+
+ RETURN(iBase_SUCCESS);
+}
+
+void iMeshP_getCopyParts( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntityHandle entity_handle,
+ iMeshP_Part **part_ids,
+ int *part_ids_allocated,
+ int *part_ids_size,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
void iMeshP_getCopies(iMesh_Instance instance,
/*in*/ const iMeshP_PartitionHandle partition_handle,
/*in*/ const iBase_EntityHandle entity_handle,
@@ -316,7 +1137,7 @@
MBParallelComm pc(MBI);
MBEntityHandle shared_handle;
MBErrorCode result = MBI->tag_get_data(pc.sharedh_tag(),
- CONST_HANDLE_ARRAY_PTR(&entity_handle), 1,
+ itaps_cast(&entity_handle), 1,
&shared_handle);
if (MB_SUCCESS != result) {
RETURN(iBase_ERROR_MAP[result]);
@@ -327,7 +1148,7 @@
part_handles.resize( 1 );
ALLOCATE_ARRAY(copies_entity_handles, 1);
part_handles[0] = 0;
- (*copies_entity_handles)[0] = reinterpret_cast<iBase_EntityHandle>(shared_handle);
+ (*copies_entity_handles)[0] = itaps_cast<iBase_EntityHandle>(shared_handle);
}
else {
@@ -341,7 +1162,7 @@
static std::vector<MBEntityHandle> shared_handles(tag_size);
result = MBI->tag_get_data(pc.sharedhs_tag(),
- CONST_HANDLE_ARRAY_PTR(&entity_handle), 1,
+ itaps_cast(&entity_handle), 1,
&shared_handles[0]);
if (MB_SUCCESS != result) {
RETURN(iBase_ERROR_MAP[result]);
@@ -352,7 +1173,7 @@
part_handles.resize(index+1, 0);
ALLOCATE_ARRAY( copies_entity_handles, index+1 );
std::copy(&shared_handles[0], &shared_handles[index],
- HANDLE_ARRAY_PTR(*copies_entity_handles));
+ itaps_cast(*copies_entity_handles));
}
ALLOCATE_ARRAY(part_ids, part_handles.size());
@@ -363,8 +1184,261 @@
*part_ids_size = part_handles.size();
RETURN(*err);
}
+
+void iMeshP_getCopyOnPart( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntityHandle entity_handle,
+ const iMeshP_Part* part_id,
+ iBase_EntityHandle* copy_entity_handle,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+
+void iMeshP_getOwnerCopy( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntityHandle entity_handle,
+ iMeshP_Part *owner_part_id,
+ iBase_EntityHandle *owner_entity_handle,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_Wait( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ iMeshP_RequestHandle req,
+ iMeshP_Status *stat,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_WaitAny( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ iMeshP_RequestHandle *req,
+ int req_size,
+ int *index,
+ iMeshP_Status *stat,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_WaitAll( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ iMeshP_RequestHandle *req,
+ int req_size,
+ iMeshP_Status *stat,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_WaitEnt( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ iMeshP_RequestHandle req,
+ iBase_EntityHandle **out_entities,
+ int *out_entities_alloc,
+ int *out_entities_size,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_Test( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ iMeshP_RequestHandle req,
+ int *flag,
+ iMeshP_Status *stat,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_pollForRequests( iMesh_Instance instance,
+ iMeshP_PartitionHandle partition_handle,
+ iMeshP_RequestHandle **requests_completed,
+ int *requests_allocated,
+ int *requests_size,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_exchEntArrToPartsAll( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntityHandle *entity_handles,
+ const int entity_handles_size,
+ const iMeshP_Part *target_part_ids,
+ int command_code,
+ int update_ghost,
+ iMeshP_RequestHandle *request,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_migrateEntity( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_PartHandle part_handle,
+ const iBase_EntityHandle local_entity_handle,
+ iMeshP_RequestHandle *request,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_updateVtxCoords( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntityHandle local_vertex_handle,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_replaceOnPartBdry( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iBase_EntityHandle *old_entities,
+ const int old_entities_size,
+ const iBase_EntityHandle *new_entities,
+ const int new_entities_size,
+ const int *offset,
+ const int offset_size,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_addGhostOf( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_Part target_part_id,
+ const iBase_EntityHandle entity_to_copy,
+ iMeshP_RequestHandle *request,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_rmvGhostOf( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ const iMeshP_Part target_part_id,
+ const iBase_EntityHandle copy_to_purge,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_syncMeshAll( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_pushTags( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ iBase_TagHandle tag,
+ int entity_type,
+ int entity_topo,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_pushTagsEnt( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ iBase_TagHandle tag,
+ const iBase_EntityHandle *entities,
+ int entities_size,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_iPushTags( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ iBase_TagHandle tag,
+ int entity_type,
+ int entity_topo,
+ iMeshP_RequestHandle *req,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_iPushTagsEnt( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ iBase_TagHandle tag,
+ const iBase_EntityHandle *entities,
+ int entities_size,
+ iMeshP_RequestHandle *req,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_createGhostEnts( iMesh_Instance instance,
+ iMeshP_PartitionHandle partition_handle,
+ int ghost_dim,
+ int bridge_dim,
+ int num_layers,
+ int include_copies,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_deleteGhostEnts( iMesh_Instance instance,
+ iMeshP_PartitionHandle partition_handle,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_ghostEntInfo( iMesh_Instance instance,
+ iMeshP_PartitionHandle partition_handle,
+ int *num_ghost_rules,
+ int *ghost_rules_allocated,
+ int *ghost_rules_size,
+ int **ghost_dim,
+ int **bridge_dim,
+ int **num_layers,
+ int *err )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_load( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition,
+ const iBase_EntitySetHandle entity_set_handle,
+ const char *name,
+ const char *options,
+ int *err,
+ int name_len,
+ int options_len )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+void iMeshP_save( iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition,
+ const iBase_EntitySetHandle entity_set_handle,
+ const char *name,
+ const char *options,
+ int *err,
+ const int name_len,
+ int options_len )
+{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+
+
+
+
+// Map from processes to parts:
+// Given a partition handle and a process rank,
+// return the part handles owned by the process.
+// COMMUNICATION: None++.
+ void iMeshP_getPartsOnRank(iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ /*in*/ const int rank,
+ /*inout*/ iMeshP_PartHandle **part_handles,
+ /*inout*/ int *part_handles_allocated,
+ /*out*/ int *part_handles_size,
+ int *err)
+ {
+ MBEntityHandle p = itaps_cast(partition_handle);
+ MBParallelComm *pc = MBParallelComm::get_pcomm(MBI, p);
+ if (!pc) RETURN(iBase_ERROR_MAP[MB_FAILURE]);
+
+ MBRange part_sets;
+ ALLOCATE_ARRAY( part_handles, pc->partition_sets().size() );
+ MBRange::iterator rit;
+ int i;
+ for (i = 0, rit = pc->partition_sets().begin();
+ rit != pc->partition_sets().end(); rit++, i++)
+ (*part_handles)[i] = itaps_cast<iMeshP_PartHandle>(*rit);
+
+ RETURN(iBase_SUCCESS);
+ }
+
+ void iMeshP_getPartsArrOnRank(iMesh_Instance instance,
+ const iMeshP_PartitionHandle partition_handle,
+ /*in*/ const int *rank,
+ /*in*/ const int rank_size,
+ /*inout*/ iMeshP_PartHandle **part_handles,
+ /*inout*/ int *part_handles_allocated,
+ /*out*/ int *part_handles_size,
+ int *err)
+ {
+ MBEntityHandle p = itaps_cast(partition_handle);
+ MBParallelComm *pc = MBParallelComm::get_pcomm(MBI, p);
+ if (!pc) RETURN(iBase_ERROR_MAP[MB_FAILURE]);
+ if (rank[0] != (int)pc->proc_config().proc_rank() || rank_size > 1) {
+ RETURN(iBase_ERROR_MAP[MB_NOT_IMPLEMENTED]);
+ }
+
+ iMeshP_getPartsOnRank(instance, partition_handle, rank[0],
+ part_handles, part_handles_allocated, part_handles_size,
+ err);
+ }
+
#ifdef __cplusplus
} // extern "C"
#endif
More information about the moab-dev
mailing list