[MOAB-dev] r1311 - in MOAB/trunk: . parallel tools/dagmc

tautges at mcs.anl.gov tautges at mcs.anl.gov
Fri Oct 12 14:02:11 CDT 2007


Author: tautges
Date: 2007-10-12 14:02:11 -0500 (Fri, 12 Oct 2007)
New Revision: 1311

Modified:
   MOAB/trunk/DenseTagCollections.cpp
   MOAB/trunk/DenseTagCollections.hpp
   MOAB/trunk/FileOptions.cpp
   MOAB/trunk/FileOptions.hpp
   MOAB/trunk/MBSkinner.cpp
   MOAB/trunk/MBSkinner.hpp
   MOAB/trunk/ReadNCDF.cpp
   MOAB/trunk/mbparallelcomm_test.cpp
   MOAB/trunk/parallel/MBParallelComm.cpp
   MOAB/trunk/parallel/MBParallelComm.hpp
   MOAB/trunk/parallel/ReadParallel.cpp
   MOAB/trunk/parallel/ReadParallel.hpp
   MOAB/trunk/tools/dagmc/DagMC.hpp
Log:
Various fixes and enhancements to parallel reading, including using
arbitrary specified partition & values.

Passes make check, except for dagmc check, which I probably broke
yesterday.


MBSkinner.cpp: added option to create vertex-element adjacencies if
they're not there, to speed up skin finding.

ReadNCDF.cpp: now handles case where there isn't a node number map
(which cubit doesn't generate).

mbparallelcomm_test.cpp:
- added option to input tag name and optional value(s) to determine
partition.  This allows one to partition on GEOM_DIMENSION tag, for
example.  This option is enabled using the PARTITION_VAL=<ints> option
substring, where <ints> is a comma-separated list of ints or int
ranges (e.g. 1-6).
 
DenseTagCollections.cpp: changed get_entities_by_type_and_tag to only
check values on a DensePage if that page has been allocated

FileOptions: added get_ints_list function

parallel/MBParallelComm.cpp: added debugging output; allow skinner to
create vert-element adjs when resolving shared entities; added another
function to check for global ids, based only on whether the tag exists
yet.

parallel/ReadParallel.cpp: moved functionality to create global ids
for vertices here from ReadNCDF.  Now, when using a BCAST or
BCAST_DELETE mode, and global ids haven't been found in the file set
read in, they're created before the bcast.  Added code to parse the
PARTITION_VALS option, which allowed me to remove the special case
processing for the PARTITION_TAG.

DagMC.hpp: fixing dimensioning of options vector



Modified: MOAB/trunk/DenseTagCollections.cpp
===================================================================
--- MOAB/trunk/DenseTagCollections.cpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/DenseTagCollections.cpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -197,25 +197,27 @@
                                                         const void* value, 
                                                         MBRange &entities)
 {
-  void* test_data = malloc(mBytesPerFlag);
-
     // for now, return if default value is requested
   if (mDefaultValue && !memcmp(value,mDefaultValue,mBytesPerFlag))
     return MB_FAILURE;
 
-  int dum = 0;
+    // iterate over dense pages
+  std::vector<DensePage>::iterator page_it;
+  const std::vector<DensePage>::iterator end = mDensePages[type].end();
+  int dum =0;
   MBEntityHandle handle = CREATE_HANDLE(type, MB_START_ID, dum);
-  MBEntityHandle end_handle = handle + mDensePages[type].size() * DensePage::mPageSize;
   MBRange::iterator insert_iter = entities.begin();
-  for(; handle < end_handle; handle++)
+  for(page_it = mDensePages[type].begin(); page_it != end; 
+      ++page_it, handle += DensePage::mPageSize)
   {
-    MBErrorCode result = get_data(handle, test_data);
-    if(result == MB_SUCCESS && !memcmp(test_data, value, mBytesPerFlag))
-      insert_iter = entities.insert(insert_iter, handle, handle);
+    if (page_it->has_data()) {
+      for (int i = 1; i <= DensePage::mPageSize; i++) {
+        if (!page_it->memcmp(i, mBytesPerFlag, value))
+          entities.insert(handle+i-1);
+      }
+    }
   }
 
-  free(test_data);
-
   return MB_SUCCESS;
 }
 

Modified: MOAB/trunk/DenseTagCollections.hpp
===================================================================
--- MOAB/trunk/DenseTagCollections.hpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/DenseTagCollections.hpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -19,6 +19,12 @@
  *  File   :      DenseTagCollections.hpp
  *  Creator:      Clinton Stimpson
  *  Date   :      10-28-2002
+ *
+ * DenseTagSuperCollection: contains a vector of DensePageGroup objects
+ * DensePageGroup: vector of vectors of DensePage objects, one vector per 
+ *   entity type, blocking possible handles in the type
+ * DensePage: block of values corresponding to a block of handles of a given
+ *   type; may or may not have data allocated
  */
 
 #ifndef DENSE_TAG_COLLECTIONS_HPP
@@ -69,6 +75,8 @@
   //! return whether has data or not
   bool has_data() const { return mByteArray != 0; }
 
+    //! do a memcmp on one of the values in this page
+  bool memcmp(int offset, int num_bytes_per_flag, const void *data);
 
   //!std::auto_ptr-style behavior
   DensePage( const DensePage& other )
@@ -108,6 +116,15 @@
   return MB_SUCCESS;
 }
 
+//! do a memcmp on one of the values in this page
+inline bool DensePage::memcmp(int offset, int num_bytes_per_flag, const void *data)
+{
+  // if no memory has been allocated, get the default value
+  assert(mByteArray);
+
+  return ::memcmp(mByteArray + offset*num_bytes_per_flag, data, num_bytes_per_flag);
+}
+
 /*! set the bytes in a page
     takes byte offset into the page
     takes how many bytes to set

Modified: MOAB/trunk/FileOptions.cpp
===================================================================
--- MOAB/trunk/FileOptions.cpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/FileOptions.cpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -129,6 +129,49 @@
   return MB_SUCCESS;
 }
 
+MBErrorCode FileOptions::get_ints_option( const char* name, 
+                                          std::vector<int>& values) const
+{
+  const char* s;
+  MBErrorCode rval = get_option( name, s );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // empty string
+  if (strempty(s))
+    return MB_TYPE_OUT_OF_RANGE;
+  
+    // parse values
+  while (!strempty(s)) {
+    char* endptr;
+    long int sval = strtol( s, &endptr, 0 );
+
+#define EATSPACE(a) while ((!strcmp(a, " ") || \
+          !strcmp(a, ",")) && !strempty(a)) a++;
+    EATSPACE(endptr);
+    long int eval = sval;
+    if (!strcmp(endptr, "-")) {
+      endptr++;
+      s = endptr;
+      eval = strtol(s, &endptr, 0);
+      EATSPACE(endptr);
+    }
+  
+      // check for overflow (parsing long int, returning int)
+    int value = sval;
+    if (sval != (long int)value)
+      return MB_TYPE_OUT_OF_RANGE;
+    value = eval;
+    if (eval != (long int)value)
+      return MB_TYPE_OUT_OF_RANGE;
+  
+    for (int i = sval; i <= eval; i++)
+      values.push_back(i);
+  }
+  
+  return MB_SUCCESS;
+}
+
 MBErrorCode FileOptions::get_real_option ( const char* name, double& value ) const
 {
   const char* s;

Modified: MOAB/trunk/FileOptions.hpp
===================================================================
--- MOAB/trunk/FileOptions.hpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/FileOptions.hpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -116,10 +116,11 @@
    */
   MBErrorCode match_option( const char* name, const char* const* values, int& index ) const;
   
-  /**\brief Check for option for which the value is an ID list
+  /**\brief Check for option for which the value is a list of ints
    *
-   * Check for and remove an ID list option.  The value is expected to
-   * be a comma-separated list of ID ranges, where an ID range can be 
+   * Check for and remove an options which is an int list.  The value is 
+   * expected to
+   * be a comma-separated list of int ranges, where an int range can be 
    * either a single integer value or a range of integer values separated
    * by a dash ('-').
    *
@@ -130,7 +131,7 @@
    *        - MB_TYPE_OUT_OF_RANGE if options is found, but does not contain an ID list
    *        - MB_ENTITY_NOT_FOUND if option is not found.
    */
-  //MBErrorCode get_id_list_option( const char* name, std::vector<unsigned>& value, bool remove = true );
+  MBErrorCode get_ints_option( const char* name, std::vector<int>& values) const;
   
   /** number of options */
   inline unsigned size() const 

Modified: MOAB/trunk/MBSkinner.cpp
===================================================================
--- MOAB/trunk/MBSkinner.cpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/MBSkinner.cpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -52,7 +52,7 @@
 }
 
 
-void MBSkinner::initialize(const bool use_adjs)
+void MBSkinner::initialize()
 {
   // go through and mark all the target dimension entities
   // that already exist as not deleteable
@@ -64,40 +64,33 @@
   void* null_ptr = NULL;
   MBErrorCode result;
 
-  if(mAdjTag == 0 && !use_adjs)
-  {
-    result = thisMB->tag_create("skinner adj", sizeof(void*), MB_TAG_DENSE, mAdjTag, &null_ptr);
-    assert(MB_SUCCESS == result);
-  }
+  result = thisMB->tag_create("skinner adj", sizeof(void*), MB_TAG_DENSE, mAdjTag, &null_ptr);
+  assert(MB_SUCCESS == result);
 
-  if(mDeletableMBTag == 0 && !use_adjs) {
+  if(mDeletableMBTag == 0) {
     result = thisMB->tag_create("skinner deletable", 1, MB_TAG_BIT, mDeletableMBTag, NULL);
     assert(MB_SUCCESS == result);
   }
   
   MBRange entities;
 
-    // only need to mark entities if we're not using adjacencies
-  if (!use_adjs) {
-    
-      // go through each type at this dimension 
-    for(type = target_ent_types.first; type <= target_ent_types.second; ++type)
+    // go through each type at this dimension 
+  for(type = target_ent_types.first; type <= target_ent_types.second; ++type)
+  {
+      // get the entities of this type in the MB
+    thisMB->get_entities_by_type(0, type, entities);
+
+      // go through each entity of this type in the MB
+      // and set its deletable tag to NO
+    MBRange::iterator iter, end_iter;
+    end_iter = entities.end();
+    for(iter = entities.begin(); iter != end_iter; ++iter)
     {
-        // get the entities of this type in the MB
-      thisMB->get_entities_by_type(0, type, entities);
-
-        // go through each entity of this type in the MB
-        // and set its deletable tag to NO
-      MBRange::iterator iter, end_iter;
-      end_iter = entities.end();
-      for(iter = entities.begin(); iter != end_iter; ++iter)
-      {
-        unsigned char bit = 0x1;
-        result = thisMB->tag_set_data(mDeletableMBTag, &(*iter), 1, &bit);
-        assert(MB_SUCCESS == result);
-          // add adjacency information too
-        add_adjacency(*iter);
-      }
+      unsigned char bit = 0x1;
+      result = thisMB->tag_set_data(mDeletableMBTag, &(*iter), 1, &bit);
+      assert(MB_SUCCESS == result);
+        // add adjacency information too
+      add_adjacency(*iter);
     }
   }
 }
@@ -231,8 +224,9 @@
 }
 
 MBErrorCode MBSkinner::find_skin(const MBRange &source_entities,
-                                   MBRange &forward_target_entities,
-                                   MBRange &reverse_target_entities)
+                                 MBRange &forward_target_entities,
+                                 MBRange &reverse_target_entities,
+                                 bool create_vert_elem_adjs)
 {
   if(source_entities.empty())
     return MB_FAILURE;
@@ -248,11 +242,14 @@
 
   MBCore *this_core = dynamic_cast<MBCore*>(thisMB);
   bool use_adjs = false;
+  if (!this_core->a_entity_factory()->vert_elem_adjacencies() &&
+    create_vert_elem_adjs)
+    this_core->a_entity_factory()->create_vert_elem_adjacencies();
+
   if (this_core->a_entity_factory()->vert_elem_adjacencies())
     use_adjs = true;
   
-  // initialize
-  initialize(use_adjs);
+  else initialize();
 
   MBRange::const_iterator iter, end_iter;
   end_iter = source_entities.end();
@@ -867,18 +864,25 @@
   // get skin entities of prescribed dimension
 MBErrorCode MBSkinner::find_skin(const MBRange &entities,
                                  int dim,
-                                 MBRange &skin_entities) 
+                                 MBRange &skin_entities,
+                                 bool create_vert_elem_adjs) 
 {
   if (MBCN::Dimension(TYPE_FROM_HANDLE(*entities.begin())) !=
       MBCN::Dimension(TYPE_FROM_HANDLE(*entities.rbegin())))
     return MB_FAILURE;
   
   MBRange tmp_skin_for, tmp_skin_rev;
-  MBErrorCode result = find_skin(entities, tmp_skin_for, tmp_skin_rev);
+  MBErrorCode result = find_skin(entities, tmp_skin_for, tmp_skin_rev, 
+                                 create_vert_elem_adjs);
   if (MB_SUCCESS != result) return result;
   
   tmp_skin_for.merge(tmp_skin_rev);
-  result = thisMB->get_adjacencies(tmp_skin_for, dim, true, skin_entities);
+  if (MBCN::Dimension(TYPE_FROM_HANDLE(*tmp_skin_for.begin())) != dim ||
+      MBCN::Dimension(TYPE_FROM_HANDLE(*tmp_skin_for.rbegin())) != dim)
+    result = thisMB->get_adjacencies(tmp_skin_for, dim, true, skin_entities);
+  else
+    skin_entities.swap(tmp_skin_for);
+  
   return result;
 }
 

Modified: MOAB/trunk/MBSkinner.hpp
===================================================================
--- MOAB/trunk/MBSkinner.hpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/MBSkinner.hpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -46,13 +46,15 @@
   // will accept entities all of one dimension
   // and return entities of n-1 dimension
   MBErrorCode find_skin( const MBRange &entities,
-                        MBRange &forward_lower_entities,
-                        MBRange &reverse_lower_entities);
+                         MBRange &forward_lower_entities,
+                         MBRange &reverse_lower_entities,
+                         bool create_vert_elem_adjs = false);
 
     // get skin entities of prescribed dimension
   MBErrorCode find_skin(const MBRange &entities,
                         int dim,
-                        MBRange &skin_entities);
+                        MBRange &skin_entities,
+                        bool create_vert_elem_adjs = false);
 
   MBErrorCode classify_2d_boundary( const MBRange &boundary,
                                      const MBRange &bar_elements,
@@ -74,7 +76,7 @@
 
 protected:
   
-  void initialize(const bool use_adjs = false);
+  void initialize();
   
   void deinitialize();
 

Modified: MOAB/trunk/ReadNCDF.cpp
===================================================================
--- MOAB/trunk/ReadNCDF.cpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/ReadNCDF.cpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -981,28 +981,28 @@
     ptr = new int [numberNodes_loading];
   }
 
-  temp_var = ncFile->get_var("node_num_map");
-  if (NULL == temp_var || !temp_var->is_valid()) {
-    readMeshIface->report_error("ReadNCDF:: Problem getting node number map variable.");
-    delete [] ptr;
-    return MB_FAILURE;
+  int varid = -1;
+  int cstatus = nc_inq_varid (ncFile->id(), "node_num_map", &varid);
+  if (cstatus == NC_NOERR && varid != -1) {
+    temp_var = ncFile->get_var("node_num_map");
+    status = temp_var->get(ptr, numberNodes_loading);
+    if (0 == status) {
+      readMeshIface->report_error("ReadNCDF:: Problem getting node number map data.");
+      delete [] ptr;
+      return MB_FAILURE;
+  
+      MBRange range(MB_START_ID+vertexOffset, 
+                    MB_START_ID+vertexOffset+numberNodes_loading-1);
+      MBErrorCode error = mdbImpl->tag_set_data(mGlobalIdTag, 
+                                                range, &ptr[0]);
+      if (MB_SUCCESS != error)
+        readMeshIface->report_error("ReadNCDF:: Problem setting node global ids.");
+    }
   }
-  status = temp_var->get(ptr, numberNodes_loading);
-  if (0 == status) {
-    readMeshIface->report_error("ReadNCDF:: Problem getting node number map data.");
-    delete [] ptr;
-    return MB_FAILURE;
-  }
-
-  MBRange range(1+vertexOffset, 1+vertexOffset+numberNodes_loading-1);
-  MBErrorCode error = mdbImpl->tag_set_data(mGlobalIdTag, 
-                                            range, &ptr[0]);
-  if (MB_SUCCESS != error)
-    readMeshIface->report_error("ReadNCDF:: Problem setting node global ids.");
-
+  
   delete [] ptr;
   
-  return error;
+  return MB_SUCCESS;
 }
 
 MBErrorCode ReadNCDF::read_nodesets() 

Modified: MOAB/trunk/mbparallelcomm_test.cpp
===================================================================
--- MOAB/trunk/mbparallelcomm_test.cpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/mbparallelcomm_test.cpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -15,6 +15,7 @@
 #include "EntitySequenceManager.hpp"
 #include "mpi.h"
 #include <iostream>
+#include <sstream>
 
 #define REALTFI 1
 
@@ -32,7 +33,8 @@
 MBErrorCode create_scd_mesh(MBInterface *mbImpl,
                             int IJK, int &nshared);
 
-MBErrorCode read_file(MBInterface *mbImpl, const char *filename);
+MBErrorCode read_file(MBInterface *mbImpl, const char *filename,
+                      const char *tag_name, int tag_val);
 
 int main(int argc, char **argv) 
 {
@@ -93,8 +95,11 @@
     }
     else if (2 == i && argc > 4) {
         // read a file in parallel from the filename on the command line
-
-      tmp_result = read_file(mbImpl, argv[4]);
+      const char *tag_name = NULL;
+      int tag_val = -1;
+      if (argc > 5) tag_name = argv[5];
+      if (argc > 6) tag_val = strtol(argv[6], NULL, 0);
+      tmp_result = read_file(mbImpl, argv[4], tag_name, tag_val);
       if (MB_SUCCESS != tmp_result) {
         result = tmp_result;
         std::cerr << "Couldn't read mesh; error message:" << std::endl;
@@ -166,12 +171,19 @@
   return (MB_SUCCESS == result ? 0 : 1);
 }
 
-MBErrorCode read_file(MBInterface *mbImpl, const char *filename) 
+MBErrorCode read_file(MBInterface *mbImpl, const char *filename,
+                      const char *tag_name, int tag_val) 
 {
-  std::string options = "PARALLEL=BCAST_DELETE;PARTITION=MATERIAL_SET";
+  std::ostringstream options("PARALLEL=BCAST_DELETE;PARTITION=");
+  if (NULL == tag_name) options << "MATERIAL_SET";
+  else options << tag_name;
+  
+  if (-1 != tag_val)
+    options << ";PARTITION_VAL=" << tag_val;
+    
   MBEntityHandle file_set;
   MBErrorCode result = mbImpl->load_file(filename, file_set, 
-                                         options.c_str());
+                                         options.str().c_str());
   return result;
 }
 

Modified: MOAB/trunk/parallel/MBParallelComm.cpp
===================================================================
--- MOAB/trunk/parallel/MBParallelComm.cpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/parallel/MBParallelComm.cpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -11,8 +11,12 @@
 #include "MBCore.hpp"
 #include "MBError.hpp"
 
+#include <iostream>
+
 #define MAX_SHARING_PROCS 10  
 
+const bool debug = true;
+
 extern "C" 
 {
 #include "gs.h"
@@ -82,16 +86,18 @@
 
 //! assign a global id space, for largest-dimension or all entities (and
 //! in either case for vertices too)
-MBErrorCode MBParallelComm::assign_global_ids(const int dimension, 
+MBErrorCode MBParallelComm::assign_global_ids(MBEntityHandle this_set,
+                                              const int dimension, 
                                               const int start_id,
-                                              const bool largest_dim_only) 
+                                              const bool largest_dim_only,
+                                              const bool parallel) 
 {
   MBRange entities[4];
   int local_num_elements[4];
   MBErrorCode result;
   for (int dim = 0; dim <= dimension; dim++) {
     if (dim == 0 || !largest_dim_only || dim == dimension) {
-      result = mbImpl->get_entities_by_dimension(0, dim, entities[dim]); 
+      result = mbImpl->get_entities_by_dimension(this_set, dim, entities[dim]); 
       RR("Failed to get vertices in assign_global_ids.");
     }
 
@@ -109,7 +115,7 @@
     // communicate numbers
   std::vector<int> num_elements(procConfig.proc_size()*4);
 #ifdef USE_MPI
-  if (procConfig.proc_size() > 1) {
+  if (procConfig.proc_size() > 1 && parallel) {
     int retval = MPI_Alltoall(local_num_elements, 4, MPI_INTEGER,
                               &num_elements[0], procConfig.proc_size()*4, 
                               MPI_INTEGER, procConfig.proc_comm());
@@ -126,7 +132,7 @@
     for (int dim = 0; dim < 4; dim++) total_elems[dim] += num_elements[4*proc + dim];
   }
   
-    //.assign global ids now
+    //assign global ids now
   MBTag gid_tag;
   int zero = 0;
   result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int), 
@@ -1062,6 +1068,8 @@
 MBErrorCode MBParallelComm::resolve_shared_ents(MBRange &proc_ents,
                                                 int shared_dim) 
 {
+  if (debug) std::cerr << "Resolving shared entities." << std::endl;
+  
   MBRange::iterator rit;
   MBSkinner skinner(mbImpl);
   
@@ -1076,8 +1084,9 @@
       // start with skin entities
     skin_dim = upper_dim-1;
     result = skinner.find_skin(proc_ents, skin_ents[skin_dim],
-                               skin_ents[skin_dim]);
+                               skin_ents[skin_dim], true);
     RR("Failed to find skin.");
+    if (debug) std::cerr << "Found skin, now resolving." << std::endl;
   }
   else {
       // otherwise start with original entities
@@ -1106,7 +1115,7 @@
 
   else if (MB_ALREADY_ALLOCATED != result) {
       // just created it, so we need global ids
-    result = assign_global_ids(upper_dim);
+    result = assign_global_ids(0, upper_dim);
     RR("Failed assigning global ids.");
   }
 
@@ -1308,6 +1317,32 @@
   return MB_SUCCESS;
 }
   
+MBErrorCode MBParallelComm::check_global_ids(MBEntityHandle this_set,
+                                             const int dimension, 
+                                             const int start_id,
+                                             const bool largest_dim_only,
+                                             const bool parallel)
+{
+    // global id tag
+  MBTag gid_tag; int def_val = -1;
+  MBErrorCode result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int),
+                                          MB_TAG_DENSE, MB_TYPE_INTEGER, gid_tag,
+                                          &def_val, true);
+  if (MB_ALREADY_ALLOCATED != result &&
+      MB_SUCCESS != result) {
+    RR("Failed to create/get gid tag handle.");
+  }
+
+  else if (MB_ALREADY_ALLOCATED != result) {
+      // just created it, so we need global ids
+    result = assign_global_ids(this_set, dimension, start_id, largest_dim_only,
+                               parallel);
+    RR("Failed assigning global ids.");
+  }
+
+  return result;
+}
+
 #ifdef TEST_PARALLELCOMM
 
 #include <iostream>

Modified: MOAB/trunk/parallel/MBParallelComm.hpp
===================================================================
--- MOAB/trunk/parallel/MBParallelComm.hpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/parallel/MBParallelComm.hpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -47,10 +47,21 @@
 
     //! assign a global id space, for largest-dimension or all entities (and
     //! in either case for vertices too)
-  MBErrorCode assign_global_ids(const int dimension,
+  MBErrorCode assign_global_ids(MBEntityHandle this_set,
+                                const int dimension,
                                 const int start_id = 1,
-                                const bool largest_dim_only = true);
+                                const bool largest_dim_only = true,
+                                const bool parallel = true);
 
+    //! check for global ids; based only on tag handle being there or not;
+    //! if it's not there, create them for the specified dimensions
+  MBErrorCode check_global_ids(MBEntityHandle this_set,
+                               const int dimension, 
+                               const int start_id = 1,
+                               const bool largest_dim_only = true,
+                               const bool parallel = true);
+  
+
     //! communicate entities from/to this range
   MBErrorCode communicate_entities(const int from_proc, const int to_proc,
                                    MBRange &entities,

Modified: MOAB/trunk/parallel/ReadParallel.cpp
===================================================================
--- MOAB/trunk/parallel/ReadParallel.cpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/parallel/ReadParallel.cpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -9,6 +9,10 @@
 #include "MBParallelConventions.h"
 #include "MBCN.hpp"
 
+#include <iostream>
+
+const bool debug = true;
+
 #define RR(a) if (MB_SUCCESS != result) {\
           dynamic_cast<MBCore*>(mbImpl)->get_error_handler()->set_last_error(a);\
           return result;}
@@ -47,6 +51,10 @@
   if (MB_ENTITY_NOT_FOUND == result || partition_tag_name.empty())
     partition_tag_name += "PARTITION";
 
+    // Get partition tag value(s), if any
+  std::vector<int> partition_tag_vals;
+  result = opts.get_ints_option("PARTITION_VAL", partition_tag_vals);
+
     // get MPI IO processor rank
   int reader_rank;
   result = opts.get_int_option( "MPI_IO_RANK", reader_rank );
@@ -110,9 +118,16 @@
   if (parallel_mode == POPT_BCAST ||
       parallel_mode == POPT_BCAST_DELETE) {
     MBRange entities; 
+    MBParallelComm pcom( mbImpl);
 
       // get which entities need to be broadcast, only if I'm the reader
     if (reader_rank == (int)(mbImpl->proc_rank())) {
+
+        // if I'm root, check to make sure we have global ids (at least for
+        // vertices, anyway) & generate (in serial) if not
+      result = pcom.check_global_ids(file_set, 0, 1, true, false);
+      RR("Failed to generate/find global ids for parallel read.");
+      
       result = mbImpl->get_entities_by_handle( file_set, entities );
       if (MB_SUCCESS != result)
         entities.clear();
@@ -137,8 +152,7 @@
     }
 
       // do the actual broadcast; if single-processor, ignore error
-    MBParallelComm tool( mbImpl);
-    result = tool.broadcast_entities( reader_rank, entities );
+    result = pcom.broadcast_entities( reader_rank, entities );
     if (mbImpl->proc_size() == 1 && MB_SUCCESS != result) 
       result = MB_SUCCESS;
       
@@ -170,7 +184,9 @@
 
   if (parallel_mode == POPT_BCAST_DELETE ||
       parallel_mode == POPT_READ_DELETE) {
-    result = delete_nonlocal_entities(partition_tag_name, file_set);
+    result = delete_nonlocal_entities(partition_tag_name, 
+                                      partition_tag_vals, 
+                                      file_set);
     if (MB_SUCCESS != result) return result;
   }
   
@@ -178,6 +194,7 @@
 }
 
 MBErrorCode ReadParallel::delete_nonlocal_entities(std::string &ptag_name,
+                                                   std::vector<int> &ptag_vals,
                                                    MBEntityHandle file_set) 
 {
   MBRange partition_sets, my_sets;
@@ -187,25 +204,16 @@
   result = mbImpl->tag_get_handle(ptag_name.c_str(), ptag); 
   RR("Failed getting tag handle in delete_nonlocal_entities.");
 
-  if (ptag_name == PARALLEL_PARTITION_TAG_NAME) {
-    int my_rank = mbImpl->proc_rank(), *my_rank_ptr = &my_rank;
-    
-    result = mbImpl->get_entities_by_type_and_tag(file_set, MBENTITYSET,
-                                                  &ptag, 
-                                                  (void* const*) &my_rank_ptr, 1,
-                                                  my_sets); 
-    RR("Couldn't get entities with partition tag.");
-  }
-  else {
-      // no explicit stategy to assign sets, so just balance # sets
-    result = mbImpl->get_entities_by_type_and_tag(file_set, MBENTITYSET,
-                                                  &ptag, NULL, 1,
-                                                  partition_sets);
-    RR("Failed to get sets with partition-type tag.");
+  result = mbImpl->get_entities_by_type_and_tag(file_set, MBENTITYSET,
+                                                &ptag, NULL, 1,
+                                                partition_sets);
+  RR("Failed to get sets with partition-type tag.");
 
-    int proc_sz = mbImpl->proc_size();
-    int proc_rk = mbImpl->proc_rank();
-    
+  int proc_sz = mbImpl->proc_size();
+  int proc_rk = mbImpl->proc_rank();
+
+  if (ptag_vals.empty()) {
+      // no values input, just distribute sets
     int num_sets = partition_sets.size() / proc_sz, orig_numsets = num_sets;
     if (partition_sets.size() % proc_sz != 0) {
       num_sets++;
@@ -217,6 +225,19 @@
     for (int i = 0; i < num_sets; i++) 
       my_sets.insert(partition_sets[istart+i]);
   }
+  else {
+      // values input, get sets with those values
+    std::vector<int> tag_vals(partition_sets.size());
+    result = mbImpl->tag_get_data(ptag, partition_sets, &tag_vals[0]);
+    RR("Failed to get tag data for partition vals tag.");
+    for (std::vector<int>::iterator pit = ptag_vals.begin(); 
+         pit != ptag_vals.end(); pit++) {
+      std::vector<int>::iterator pit2 = std::find(tag_vals.begin(),
+                                                  tag_vals.end(), *pit);
+      if (pit2 == tag_vals.end()) RR("Couldn't find partition tag value.");
+      my_sets.insert(partition_sets[pit2 - tag_vals.begin()]);
+    }
+  }
   
   return delete_nonlocal_entities(my_sets, file_set);
 }
@@ -224,6 +245,9 @@
 MBErrorCode ReadParallel::delete_nonlocal_entities(MBRange &partition_sets,
                                                    MBEntityHandle file_set) 
 {
+
+  if (debug) std::cerr << "Deleting non-local entities." << std::endl;
+  
   MBErrorCode result;
   MBError *merror = ((MBCore*)mbImpl)->get_error_handler();
 
@@ -263,9 +287,10 @@
   deletable_ents = deletable_ents.subtract(deletable_sets);
   result = mbImpl->delete_entities(deletable_ents);
   RR("Failure deleting entities in delete_nonlocal_entities.");
-  
-  result = ((MBCore*)mbImpl)->check_adjacencies();
 
+//  if (debug)
+//    result = ((MBCore*)mbImpl)->check_adjacencies();
+
   return result;
 
 /*  

Modified: MOAB/trunk/parallel/ReadParallel.hpp
===================================================================
--- MOAB/trunk/parallel/ReadParallel.hpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/parallel/ReadParallel.hpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -34,6 +34,7 @@
   MBInterface *mbImpl;
   
   MBErrorCode delete_nonlocal_entities(std::string &ptag_name,
+                                       std::vector<int> &ptag_vals,
                                        MBEntityHandle file_set);
   
   MBErrorCode delete_nonlocal_entities(MBRange &partition_sets,

Modified: MOAB/trunk/tools/dagmc/DagMC.hpp
===================================================================
--- MOAB/trunk/tools/dagmc/DagMC.hpp	2007-10-11 19:30:24 UTC (rev 1310)
+++ MOAB/trunk/tools/dagmc/DagMC.hpp	2007-10-12 19:02:11 UTC (rev 1311)
@@ -192,7 +192,7 @@
   MBOrientedBoxTreeTool obbTree;
   MBTag obbTag, geomTag, idTag, nameTag, senseTag;
   
-  Option options[4];
+  Option options[5];
 
   char specReflectName[NAME_TAG_SIZE];
   char whiteReflectName[NAME_TAG_SIZE];




More information about the moab-dev mailing list