[MOAB-dev] parallel itaps (more patches)

Jed Brown jed at 59A2.org
Sat Sep 13 12:35:02 CDT 2008


I realize that the iMeshP interface has not stabilized, let alone been
fully implemented yet, but I'm beginning to use it anyway :-)
That is, I'm loading a mesh with

  PARALLEL=BCAST_DELETE;PARTITION=PARALLEL_PARTITION;PARTITION_DISTRIBUTE;PARALLEL_RESOLVE_SHARED_ENTS;

and interrogating it using iMeshP to create a global ordering from which
I can build a function space.  It would be handy to have
iMeshP_ExchTags() (inconsistent case in original) implemented for
managing adaptive p-refinement. (I think this is not difficult so I'll
look into it if nobody beats me to it.)  While implementing this stuff
in my code, I found more inconsistencies and made a few minor bug fixes.


The latest iMeshP.h mentioned on the itaps-parallel mailing list 

  http://www-unix.mcs.anl.gov/web-mail-archive/lists/itaps-parallel/2008/07/msg00016.html

does not provide a way to get a PartHandle.  You can create one, but
cannot access existing parts without significant obfuscation (find an
entity, get the part ID of the owning Part, then get the handle
associated with the part ID).  The MOAB implementation has
iMeshP_getPartsOnRank() which is only implemented when rank is the local
rank (I modified the function to return NOT_IMPLEMENTED rather than
erroneous part handles when the rank is remote).  There is a comment at
the bottom of the (mailing list version of) iMeshP.h that
iMeshP_getPartsOnRank() may not be a good idea due to memory costs to
provide this without communication.  For my usage, I would be happy with
the purely local

void iMeshP_getParts(iMesh_Instance instance,
                     iMeshP_PartitionHandle partition_handle,
		     iMeshP_PartHandle **part_handles,
		     int *part_handles_allocated,
		     int *part_handles_size,
		     int *err);

The 'const' annotations are meaningless for pass-by-value, but still
appear throughout the ITAPS headers.  Is there a reason for this?

In iMeshP_getEntStatus(), the returned status is not dependent on the
PartHandle that is passed in.  This is probably more useful, but it's
certainly not what the spec intended.  (Of course all implemented
functions ignore the PartitionHandle but that is clearly a deeper
issue.)

Bug fixes include off-by-one and indexing beyond an array.  I ran into
another incorrectly spec'd type in iMesh_extensions.h.

Since my previous patches have not hit the repository yet, the attached
patch is an aggregate.

Jed
-------------- next part --------------
Index: tools/iMesh/iMesh_MOAB.cpp
===================================================================
--- tools/iMesh/iMesh_MOAB.cpp	(revision 2065)
+++ tools/iMesh/iMesh_MOAB.cpp	(working copy)
@@ -175,6 +175,7 @@
   iBase_ENTITY_HANDLE
 };
 
+// If the MBErrorCode enum is changed, this *must* be updated!
 const iBase_ErrorType iBase_ERROR_MAP[] = 
 {
   iBase_SUCCESS, // MB_SUCCESS = 0,
@@ -188,6 +189,8 @@
   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};
 };
 
@@ -229,9 +232,7 @@
   void iMesh_getDescription(iMesh_Instance instance, 
                             char *descr, int *err, int descr_len)
   {
-    unsigned int len = MIN(strlen(iMesh_LAST_ERROR.description), ((unsigned int) descr_len));
-    strncpy(descr, iMesh_LAST_ERROR.description, len);
-    descr[len] = '\0';
+    strncpy(descr, iMesh_LAST_ERROR.description, descr_len);
     RETURN(iBase_SUCCESS);
   }
 
@@ -302,7 +303,7 @@
   }
    
   void iMesh_load(iMesh_Instance instance,
-                  const iBase_EntityHandle handle,
+                  const iBase_EntitySetHandle handle,
                   const char *name, const char *options, 
                   int *err, int name_len, int options_len) 
   {
@@ -337,7 +338,7 @@
   }
 
   void iMesh_save(iMesh_Instance instance,
-                  const iBase_EntityHandle handle,
+                  const iBase_EntitySetHandle handle,
                   const char *name, const char *options, 
                   int *err, const int name_len, int options_len) 
   {
@@ -378,7 +379,7 @@
   void iMesh_getDfltStorage(iMesh_Instance instance,
                             int *order, int *err)
   {
-    *order = iBase_BLOCKED;
+    *order = iBase_INTERLEAVED;
     RETURN(iBase_SUCCESS);
   }
   
@@ -830,13 +831,13 @@
                              /*in*/ const int requested_entity_type,
                              /*in*/ const int requested_entity_topology,
                              /*in*/ const int requested_array_size,
-                             /*out*/ iMesh_EntityIterator* entArr_iterator,
+                             /*out*/ iMesh_EntityArrIterator* entArr_iterator,
                              int *err) 
   {
     MBEntityType req_type = mb_topology_table[requested_entity_topology];
     int req_dimension = (req_type == MBMAXTYPE ? (int) requested_entity_type : -1);
     RangeIterator *new_it = new RangeIterator;
-    *entArr_iterator = reinterpret_cast<iMesh_EntityIterator>(new_it);
+    *entArr_iterator = reinterpret_cast<iMesh_EntityArrIterator>(new_it);
     new_it->requestedSize = requested_array_size;
   
     MBErrorCode result;
@@ -874,7 +875,7 @@
  * Method:  getEntArrNextIter[]
  */
   void iMesh_getNextEntArrIter (iMesh_Instance instance,
-                                /*in*/ iMesh_EntityIterator entArr_iterator,
+                                /*in*/ iMesh_EntityArrIterator entArr_iterator,
                                 /*inout*/ iBase_EntityHandle** entity_handles,
                                 /*inout*/ int* entity_handles_allocated,
                                 /*out*/ int* entity_handles_size,
@@ -910,7 +911,7 @@
  * Method:  resetEntArrIter[]
  */
   void iMesh_resetEntArrIter (iMesh_Instance instance,
-                              /*in*/ iMesh_EntityIterator entArr_iterator, int *err) 
+                              /*in*/ iMesh_EntityArrIterator entArr_iterator, int *err) 
   {
     RangeIterator *this_it = RANGE_ITERATOR(entArr_iterator);
 
@@ -920,7 +921,7 @@
   }
 
   void iMesh_endEntArrIter (iMesh_Instance instance,
-                            /*in*/ iMesh_EntityIterator entArr_iterator, int *err) 
+                            /*in*/ iMesh_EntityArrIterator entArr_iterator, int *err) 
   {
     RangeIterator *this_it = RANGE_ITERATOR(entArr_iterator);
 
@@ -1095,7 +1096,7 @@
     }
   
       // return EntitySet_Handle
-    *entity_set_created = (iBase_EntityHandle)meshset;
+    *entity_set_created = (iBase_EntitySetHandle)meshset;
     RETURN(iBase_ERROR_MAP[result]);
   }
 
@@ -1178,7 +1179,7 @@
     int k = 0;
 
     for (; iter != end_iter; iter++)
-      (*contained_entset_handles)[k++] = (iBase_EntityHandle)*iter;
+      (*contained_entset_handles)[k++] = (iBase_EntitySetHandle)*iter;
 
     *contained_entset_handles_size = sets.size();
     RETURN(iBase_SUCCESS);
@@ -1273,7 +1274,7 @@
 
   void iMesh_isEntContained (iMesh_Instance instance,
                              /*in*/ const iBase_EntitySetHandle containing_entity_set,
-                             /*in*/ const iBase_EntitySetHandle contained_entity,
+                             /*in*/ const iBase_EntityHandle contained_entity,
                              int *is_contained, int *err) 
   {
     MBRange all_ents;
@@ -1300,7 +1301,7 @@
                                 /*in*/ const iBase_EntitySetHandle contained_entity_set,
                                 int *is_contained, int *err) 
   {
-    iMesh_isEntContained(instance, containing_entity_set, contained_entity_set,
+    iMesh_isEntContained(instance, containing_entity_set, (iBase_EntityHandle)contained_entity_set,
                          is_contained, err);
   }
 
@@ -2431,7 +2432,7 @@
                           int *err) 
   {
     iMesh_initEntArrIter(instance, entity_set_handle, requested_entity_type,
-                         requested_entity_topology, 1, entity_iterator,
+                         requested_entity_topology, 1, (iMesh_EntityArrIterator*)entity_iterator,
                          err);
   }
 
@@ -2442,20 +2443,20 @@
   {
     int eh_size = 1;
     iMesh_getNextEntArrIter(instance,
-                            entity_iterator, &entity_handle, &eh_size, &eh_size, is_end, err);
+                            (iMesh_EntityArrIterator)entity_iterator, &entity_handle, &eh_size, &eh_size, is_end, err);
   
   }
 
   void iMesh_resetEntIter (iMesh_Instance instance,
                            /*in*/ iMesh_EntityIterator entity_iterator, int *err) 
   {
-    iMesh_resetEntArrIter(instance, entity_iterator, err);  
+    iMesh_resetEntArrIter(instance, (iMesh_EntityArrIterator)entity_iterator, err);  
   }
 
   void iMesh_endEntIter (iMesh_Instance instance,
                          /*in*/ iMesh_EntityIterator entity_iterator, int *err) 
   {
-    iMesh_endEntArrIter(instance, entity_iterator, err);
+    iMesh_endEntArrIter(instance, (iMesh_EntityArrIterator)entity_iterator, err);
   }
 
   void iMesh_getEntTopo (iMesh_Instance instance,
@@ -2889,7 +2890,7 @@
                                  /*in*/ const char * const *tag_vals,
                                  /*in*/ const int num_tags_vals,
                                  /*in*/ const int recursive,
-                                 /*out*/ iBase_EntityHandle** set_handles,
+                                 /*out*/ iBase_EntitySetHandle** set_handles,
                                  /*out*/ int* set_handles_allocated,
                                  /*out*/ int* set_handles_size,
                                  /*out*/ int *err)
@@ -2911,7 +2912,7 @@
     }
 
     CHECK_SIZE(*set_handles, *set_handles_allocated, 
-               (int)out_entities.size(), iBase_EntityHandle, iBase_MEMORY_ALLOCATION_FAILED);
+               (int)out_entities.size(), iBase_EntitySetHandle, iBase_MEMORY_ALLOCATION_FAILED);
 
     std::copy(out_entities.begin(), out_entities.end(), ((MBEntityHandle*) *set_handles));
   
Index: tools/iMesh/iMesh.h
===================================================================
--- tools/iMesh/iMesh.h	(revision 2065)
+++ tools/iMesh/iMesh.h	(working copy)
@@ -76,19 +76,19 @@
      *
      * Type used to store iMesh interface handle
      */
-  typedef void* iMesh_Instance;
+  typedef struct iMesh_Instance_private *iMesh_Instance;
 
     /**\brief  Type used to store an iterator returned by iMesh
      *
      * Type used to store an iterator returned by iMesh
      */
-  typedef void* iMesh_EntityIterator;
+  typedef struct iMesh_EntityIterator_private *iMesh_EntityIterator;
 
     /**\brief  Type used to store an array iterator returned by iMesh
      *
      * Type used to store an array iterator returned by iMesh
      */
-  typedef void* iMesh_EntityArrIterator;
+  typedef struct iMesh_EntityArrIterator_private *iMesh_EntityArrIterator;
 
     /**\brief  Enumerator specifying entity topology
      *
@@ -514,7 +514,7 @@
      * \param *err Pointer to error type returned from function
      */
   void iMesh_getAdjEntities(iMesh_Instance instance,
-                            /*in*/ const iBase_EntityHandle entity_set_handle,
+                            /*in*/ const iBase_EntitySetHandle entity_set_handle,
                             /*in*/ const int entity_type_requestor,
                             /*in*/ const int entity_topology_requestor,
                             /*in*/ const int entity_type_requested,
@@ -870,7 +870,7 @@
      * \param *err Pointer to error type returned from function
      */
   void iMesh_addEntSet(iMesh_Instance instance,
-                       /*in*/ const iBase_EntityHandle entity_set_to_add,
+                       /*in*/ const iBase_EntitySetHandle entity_set_to_add,
                        /*inout*/ iBase_EntitySetHandle* entity_set_handle,
                        /*out*/ int *err);
 
@@ -901,7 +901,7 @@
      */
   void iMesh_isEntContained(iMesh_Instance instance,
                             /*in*/ const iBase_EntitySetHandle containing_entity_set,
-                            /*in*/ const iBase_EntitySetHandle contained_entity,
+                            /*in*/ const iBase_EntityHandle contained_entity,
                             /*out*/ int *is_contained,
                             /*out*/ int *err);
 
Index: tools/iMesh/testc_cbind.c
===================================================================
--- tools/iMesh/testc_cbind.c	(revision 2065)
+++ tools/iMesh/testc_cbind.c	(working copy)
@@ -796,7 +796,7 @@
   }
 
     // check if parent is really added
-  iBase_EntityHandle *parents = NULL;
+  iBase_EntitySetHandle *parents = NULL;
   int parents_alloc = 0, parents_size;
   iMesh_getPrnts(mesh, parent_child, 0, 
                  &parents, &parents_alloc, &parents_size, &result);
@@ -1636,7 +1636,7 @@
 }
 
 int entityset_struct_tag_test(iMesh_Instance mesh, 
-                               iBase_EntityHandle *sets, int sets_size,
+                               iBase_EntitySetHandle *sets, int sets_size,
                                iBase_TagHandle *struct_tag) 
 {
   int result;
@@ -1692,7 +1692,7 @@
 }
 
 int entityset_tag_delete_test(iMesh_Instance mesh, 
-                               iBase_EntityHandle *sets, int sets_size) 
+                               iBase_EntitySetHandle *sets, int sets_size) 
 {
     // test forced, unforced deletion of tags from entities
   int result;
@@ -1700,7 +1700,7 @@
 
     // test getAlliBase_TagHandles for first entity
   iBase_TagHandle *all_tags = NULL;
-  iBase_EntityHandle dum_entity = sets[0];
+  iBase_EntitySetHandle dum_entity = sets[0];
   int all_tags_alloc = 0, all_tags_size;
   iMesh_getAllEntSetTags(mesh, sets[0], &all_tags, &all_tags_alloc,
 			 &all_tags_size, &result);
Index: tools/iMesh/iMeshP_MOAB.cpp
===================================================================
--- tools/iMesh/iMeshP_MOAB.cpp	(revision 2065)
+++ tools/iMesh/iMeshP_MOAB.cpp	(working copy)
@@ -14,7 +14,9 @@
 #define MBI reinterpret_cast<MBInterface*>(instance)
 
 #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;}
+#define iMesh_processError(a, b)                                        \
+  {snprintf(iMesh_LAST_ERROR.description, sizeof(iMesh_LAST_ERROR.description), "%s", b); \
+    iMesh_LAST_ERROR.error_type = a; *err = a;}
 
 #define CHECK_SIZE(array, allocated, size, type, retval)  \
   if (0 != allocated && NULL != array && allocated < (size)) {\
@@ -43,6 +45,8 @@
     if (NULL == array) {iMesh_processError(iBase_MEMORY_ALLOCATION_FAILED, \
           "Couldn't allocate array.");RETURN(iBase_MEMORY_ALLOCATION_FAILED); }\
   }
+#define NOT_IMPLEMENTED_IF(cond) \
+  if (cond) { iMesh_processError(iBase_ERROR_MAP[MB_NOT_IMPLEMENTED], "Not implemented."); RETURN(iBase_ERROR_MAP[MB_NOT_IMPLEMENTED]); }
 #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)
@@ -51,7 +55,10 @@
 #define CONST_ENTITY_HANDLE(handle) reinterpret_cast<const MBEntityHandle>(handle)
 #define RANGE_ITERATOR(it) reinterpret_cast<RangeIterator*>(it)
 #define CAST_TO_VOID(ptr) reinterpret_cast<void*>(ptr)
+#define CAST_TO_PART_HANDLE(ptr) reinterpret_cast<iMeshP_PartHandle>(ptr)
+#define CAST_TO_ENTITY_HANDLE(ptr) reinterpret_cast<iBase_EntityHandle>(ptr)
 
+// If the MBErrorCode enum is changed, this *must* be updated!
 const iBase_ErrorType iBase_ERROR_MAP[] = 
 {
   iBase_SUCCESS, // MB_SUCCESS = 0,
@@ -65,6 +72,8 @@
   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};
 };
 
@@ -141,6 +150,7 @@
   {
     MBParallelComm *pc = MBParallelComm::get_pcomm(MBI, 0);
     if (!pc) RETURN(iBase_ERROR_MAP[MB_FAILURE]);
+    NOT_IMPLEMENTED_IF(rank != MBI->proc_rank());
 
     MBRange part_sets;
   
@@ -150,7 +160,7 @@
     int i;
     for (i = 0, rit = pc->partition_sets().begin(); 
          rit != pc->partition_sets().end(); rit++, i++)
-      (*part_handles)[i] = CAST_TO_VOID(*rit);
+      (*part_handles)[i] = CAST_TO_PART_HANDLE(*rit);
   
     RETURN(iBase_SUCCESS);
   }
@@ -164,9 +174,7 @@
                                 /*out*/   int *part_handles_size, 
                                 int *err) 
   {
-    if (rank[0] != MBI->proc_rank() || rank_size > 1) {
-      RETURN(iBase_ERROR_MAP[MB_NOT_IMPLEMENTED]);
-    }
+    NOT_IMPLEMENTED_IF(rank[0] != MBI->proc_rank() || rank_size > 1);
   
     iMeshP_getPartsOnRank(instance, partition_handle, rank[0],
                           part_handles, part_handles_allocated, part_handles_size,
@@ -304,7 +312,7 @@
       CHECK_SIZE(*copies_entity_handles, *copies_entity_handles_allocated, 
                  *copies_entity_handles_size, iBase_EntityHandle, );
       (*part_handles)[0] = 0;
-      (*copies_entity_handles)[0] = CAST_TO_VOID(shared_handle);
+      (*copies_entity_handles)[0] = CAST_TO_ENTITY_HANDLE(shared_handle);
       RETURN(iBase_SUCCESS);
     }
   
@@ -331,10 +339,10 @@
     CHECK_SIZE(*part_handles, *part_handles_allocated, *part_handles_size, 
                iMeshP_PartHandle, );
     CHECK_SIZE(*copies_entity_handles, *copies_entity_handles_allocated, 
-               *copies_entity_handles_size, iMeshP_PartHandle, );
+               *copies_entity_handles_size, iBase_EntityHandle, );
     std::copy(&shared_handles[0], &shared_handles[index], 
               HANDLE_ARRAY_PTR(*copies_entity_handles));
-    std::fill(*part_handles, *part_handles+index, CAST_TO_VOID(0));
+    std::fill(*part_handles, *part_handles+index, CAST_TO_PART_HANDLE(0));
 
     RETURN(iBase_SUCCESS);
   }
Index: tools/iMesh/iBase.h
===================================================================
--- tools/iMesh/iBase.h	(revision 2065)
+++ tools/iMesh/iBase.h	(working copy)
@@ -15,10 +15,10 @@
      * TYPEDEF'S
      *==========================================================
      */
-  typedef void* iBase_Instance;
-  typedef void* iBase_EntityHandle;
-  typedef void* iBase_EntitySetHandle;
-  typedef void* iBase_TagHandle;
+  typedef struct iBase_Instance_private        *iBase_Instance;
+  typedef struct iBase_EntityHandle_private    *iBase_EntityHandle;
+  typedef struct iBase_EntitySetHandle_private *iBase_EntitySetHandle;
+  typedef struct iBase_TagHandle_private       *iBase_TagHandle;
 
     /*==========================================================
      * ENTITYTYPE ENUMERATION
Index: tools/iMesh/iMesh_extensions.h
===================================================================
--- tools/iMesh/iMesh_extensions.h	(revision 2065)
+++ tools/iMesh/iMesh_extensions.h	(working copy)
@@ -140,7 +140,7 @@
                                  /*in*/ const char * const *tag_vals,
                                  /*in*/ const int num_tags_vals,
                                  /*in*/ const int recursive,
-                                 /*out*/ iBase_EntityHandle** set_handles,
+                                 /*out*/ iBase_EntitySetHandle** set_handles,
                                  /*out*/ int* set_handles_allocated,
                                  /*out*/ int* set_handles_size,
                                  /*out*/ int *err);
Index: tools/iMesh/iMeshP.h
===================================================================
--- tools/iMesh/iMeshP.h	(revision 2065)
+++ tools/iMesh/iMeshP.h	(working copy)
@@ -20,13 +20,13 @@
      *
      * Type used to store a part handle
      */
-  typedef void* iMeshP_PartHandle;
+  typedef struct iMeshP_PartHandle_private *iMeshP_PartHandle;
 
     /**\brief  Type used to store a partition handle
      *
      * Type used to store a partition handle
      */
-  typedef void* iMeshP_PartitionHandle;
+  typedef struct iMeshP_PartitionHandle_private *iMeshP_PartitionHandle;
 
   const int iMeshP_INTERNAL = 0;
   const int iMeshP_BOUNDARY = 1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <https://lists.mcs.anl.gov/mailman/private/moab-dev/attachments/20080913/9f73d79f/attachment.pgp>


More information about the moab-dev mailing list