[MOAB-dev] commit/MOAB: 2 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Sep 24 17:55:26 CDT 2013


2 new commits in MOAB:

https://bitbucket.org/fathomteam/moab/commits/d061ada4ca8c/
Changeset:   d061ada4ca8c
Branch:      None
User:        iulian07
Date:        2013-09-25 00:31:01
Summary:     add NDEBUG guards for printf statements in Coupler

also, report correctly how many points are local

Affected #:  1 file

diff --git a/tools/mbcoupler/Coupler.cpp b/tools/mbcoupler/Coupler.cpp
index f7f74b2..28f67ca 100644
--- a/tools/mbcoupler/Coupler.cpp
+++ b/tools/mbcoupler/Coupler.cpp
@@ -299,7 +299,6 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
     // appending results to tuple_list;
     // keep local points separately, in local_pts, which has pairs
     // of <local_index, mapped_index>, where mapped_index is the index
-    // of <local_index, mapped_index>, where mapped_index is the index
     // into the mappedPts tuple list
 
   unsigned int my_rank = (myPc ? myPc->proc_config().proc_rank() : 0);
@@ -333,19 +332,21 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
   int num_to_me = 0;
   for (unsigned int i = 0; i < target_pts.get_n(); i++)
     if (target_pts.vi_rd[2*i] == (int)my_rank) num_to_me++;
-
+#ifndef NDEBUG
   printf("rank: %d local points: %d, nb sent target pts: %d mappedPts: %d num to me: %d \n",
          my_rank, num_points, target_pts.get_n(), mappedPts->get_n(), num_to_me);
-    // perform scatter/gather, to gather points to source mesh procs
+#endif
+  // perform scatter/gather, to gather points to source mesh procs
   if (myPc) {
     (myPc->proc_config().crystal_router())->gs_transfer(1, target_pts, 0);
 
     num_to_me = 0;
     for (unsigned int i = 0; i < target_pts.get_n(); i++)
       if (target_pts.vi_rd[2*i] == (int)my_rank) num_to_me++;
-
+#ifndef NDEBUG
     printf("rank: %d after first gs nb received_pts: %d; num_from_me = %d\n",
            my_rank, target_pts.get_n(), num_to_me);
+#endif
       // after scatter/gather:
       // target_pts.set_n( # points local proc has to map );
       // target_pts.vi_wr[2*i] = proc sending point i
@@ -374,15 +375,19 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
 
       // no longer need target_pts
     target_pts.reset();
-
+#ifndef NDEBUG
     printf("rank: %d nb sent source pts: %d, mappedPts now: %d\n",
            my_rank, source_pts.get_n(),  mappedPts->get_n());
+#endif
       // send target points back to target procs
     (myPc->proc_config().crystal_router())->gs_transfer(1, source_pts, 0);
 
+#ifndef NDEBUG
     printf("rank: %d nb received source pts: %d\n",
            my_rank, source_pts.get_n());
+#endif
   }
+
   
     // store proc/index tuples in targetPts, and/or pass back to application;
     // the tuple this gets stored to looks like:
@@ -411,7 +416,7 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
   unsigned int local_pts = 0;
   for (unsigned int i = 0; i < source_pts.get_n(); i++) {
     if (-1 != source_pts.vi_rd[3*i+2]) { //why bother sending message saying "i don't have the point" if it gets discarded?
-      if (source_pts.vi_rd[3*i] == (int)my_rank) local_pts++;
+      //if (source_pts.vi_rd[3*i] == (int)my_rank) local_pts++;
       int tgt_index = 3*source_pts.vi_rd[3*i+1];
       tl_tmp->vi_wr[tgt_index]   = source_pts.vi_rd[3*i];
       tl_tmp->vi_wr[tgt_index+1] = source_pts.vi_rd[3*i+1];
@@ -422,11 +427,18 @@ ErrorCode Coupler::locate_points(double *xyz, int num_points,
     // count missing points
   unsigned int missing_pts = 0;
   for (int i = 0; i < num_points; i++) 
-    if (tl_tmp->vi_rd[3*i+1] == -1) missing_pts++;
-  
+  {
+    if (tl_tmp->vi_rd[3*i+1] == -1)
+      missing_pts++;
+    else
+      if (tl_tmp->vi_rd[3*i]==(int)my_rank)
+        local_pts++;
+  }
+#ifndef NDEBUG
   printf("rank: %d point location: wanted %d got %u locally, %d remote, missing %d\n",
          my_rank, num_points, local_pts,  num_points-missing_pts-local_pts, missing_pts);
-  assert(0==missing_pts); //will litely break on curved geometries
+#endif
+  assert(0==missing_pts); //will likely break on curved geometries
   
     // no longer need source_pts
   source_pts.reset();


https://bitbucket.org/fathomteam/moab/commits/82b6f2624ab0/
Changeset:   82b6f2624ab0
Branch:      master
User:        iulian07
Date:        2013-09-25 00:48:20
Summary:     Merge branch 'master' of https://bitbucket.org/fathomteam/moab

Affected #:  13 files

diff --git a/examples/GetEntities.cpp b/examples/GetEntities.cpp
index d9dc34e..5124529 100644
--- a/examples/GetEntities.cpp
+++ b/examples/GetEntities.cpp
@@ -29,19 +29,28 @@ int main(int argc, char **argv) {
     // instantiate & load a mesh from a file
   Core *mb = new Core();
   ErrorCode rval = mb->load_mesh(test_file_name.c_str());
-  if (MB_SUCCESS != rval) return 1;
+  if (MB_SUCCESS != rval) {
+    delete mb;
+    return 1;
+  }
 
   Range ents;
 
     // get all entities in the database
   rval = mb->get_entities_by_handle(0, ents);
-  if (MB_SUCCESS != rval) return 1;
+  if (MB_SUCCESS != rval) {
+    delete mb;
+    return 1;
+  }
 
   for (Range::iterator it = ents.begin(); it != ents.end(); it++) {
     if (MBVERTEX == mb->type_from_handle(*it)) {
       Range adjs;
       rval = mb->get_adjacencies(&(*it), 1, 3, false, adjs);
-      if (MB_SUCCESS != rval) return 1;
+      if (MB_SUCCESS != rval) {
+        delete mb;
+        return 1;
+      }
       cout << "Vertex " << mb->id_from_handle(*it) << " adjacencies:" << endl;
       adjs.print();
     }
@@ -49,9 +58,13 @@ int main(int argc, char **argv) {
       const EntityHandle *connect;
       int num_connect;
       rval = mb->get_connectivity(*it, connect, num_connect);
-      if (MB_SUCCESS != rval) return 1;
+      if (MB_SUCCESS != rval) {
+        delete mb;
+        return 1;
+      }
       cout << CN::EntityTypeName(mb->type_from_handle(*it)) << " " << mb->id_from_handle(*it) << " vertex connectivity is: ";
-      for (int i = 0; i < num_connect; i++) cout << mb->id_from_handle(connect[i]) << " ";
+      for (int i = 0; i < num_connect; i++)
+        cout << mb->id_from_handle(connect[i]) << " ";
       cout << endl;
     }
   }

diff --git a/examples/HelloParMOAB.cpp b/examples/HelloParMOAB.cpp
index 03366f9..5bcc4ab 100644
--- a/examples/HelloParMOAB.cpp
+++ b/examples/HelloParMOAB.cpp
@@ -20,20 +20,23 @@ int main(int argc, char **argv)
 
   string options;
 
-    // need option handling here for input filename
+  // Need option handling here for input filename
   if (argc > 1){
-    //user has input a mesh file
+    // user has input a mesh file
     test_file_name = argv[1];
   }  
 
   options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS";
 
-  // get MOAB instance and read the file with the specified options
-  Interface *mb = new Core;
-  if (NULL == mb) return 1;
-  // get the ParallelComm instance
+  // Get MOAB instance and read the file with the specified options
+  Interface* mb = new Core;
+  if (NULL == mb)
+    return 1;
+
+  // Get the ParallelComm instance
   ParallelComm* pcomm = new ParallelComm(mb, MPI_COMM_WORLD);
-  int nprocs = pcomm->proc_config().proc_size(), rank = pcomm->proc_config().proc_rank();
+  int nprocs = pcomm->proc_config().proc_size();
+  int rank = pcomm->proc_config().proc_rank();
   MPI_Comm comm = pcomm->proc_config().proc_comm();
 
   if (rank == 0)
@@ -41,59 +44,76 @@ int main(int argc, char **argv)
          << " on " << nprocs << " processors\n";
 
   ErrorCode rval = mb->load_file(test_file_name.c_str(), 0, options.c_str());
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
   Range shared_ents;
-    // get entities shared with all other processors
+  // Get entities shared with all other processors
   rval = pcomm->get_shared_entities(-1, shared_ents);
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
-    // filter shared entities with not not_owned, which means owned
+  // Filter shared entities with not not_owned, which means owned
   Range owned_entities;
   rval = pcomm->filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &owned_entities);
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
-  unsigned int nums[4]={0}; // to store the owned entities per dimension
-  for (int i=0; i<4; i++) nums[i]=(int)owned_entities.num_of_dimension(i);
+  unsigned int nums[4] = {0}; // to store the owned entities per dimension
+  for (int i = 0; i < 4; i++)
+    nums[i] = (int)owned_entities.num_of_dimension(i);
   vector<int> rbuf(nprocs*4, 0);
-  MPI_Gather( nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, MPI_COMM_WORLD);
-  // print the stats gathered:
+  MPI_Gather(nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, MPI_COMM_WORLD);
+  // Print the stats gathered:
   if (rank == 0) {
-    for (int i=0; i<nprocs; i++)
+    for (int i = 0; i < nprocs; i++)
       cout << " Shared, owned entities on proc " << i << ": " << rbuf[4*i] << " verts, " <<
-          rbuf[4*i+1] << " edges, " << rbuf[4*i+2] << " faces, " << rbuf[4*i+3] << " elements" << endl;
+          rbuf[4*i + 1] << " edges, " << rbuf[4*i + 2] << " faces, " << rbuf[4*i + 3] << " elements" << endl;
   }
 
-    // Now exchange 1 layer of ghost elements, using vertices as bridge
-    // (we could have done this as part of reading process, using the PARALLEL_GHOSTS read option)
+  // Now exchange 1 layer of ghost elements, using vertices as bridge
+  // (we could have done this as part of reading process, using the PARALLEL_GHOSTS read option)
   rval = pcomm->exchange_ghost_cells(3, // int ghost_dim,
                                      0, // int bridge_dim,
                                      1, //int num_layers,
                                      0, //int addl_ents,
                                      true); // bool store_remote_handles);
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
-  // repeat the reports, after ghost exchange
+  // Repeat the reports, after ghost exchange
   shared_ents.clear();
   owned_entities.clear();
   rval = pcomm->get_shared_entities(-1, shared_ents);
-  if (rval != MB_SUCCESS) return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
   rval = pcomm->filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &owned_entities);
-  if (rval != MB_SUCCESS)  return 1;
+  if (rval != MB_SUCCESS) {
+    delete mb;
+    return 1;
+  }
 
   // find out how many shared entities of each dimension are owned on this processor
-  for (int i=0; i<4; i++)
-    nums[i]=(int)owned_entities.num_of_dimension(i);
+  for (int i = 0; i < 4; i++)
+    nums[i] = (int)owned_entities.num_of_dimension(i);
 
   // gather the statistics on processor 0
-  MPI_Gather( nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, comm);
-  if (rank == 0)
-  {
+  MPI_Gather(nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, comm);
+  if (rank == 0) {
     cout << " \n\n After exchanging one ghost layer: \n";
-    for (int i=0; i<nprocs; i++)
-    {
+    for (int i = 0; i < nprocs; i++) {
       cout << " Shared, owned entities on proc " << i << ": " << rbuf[4*i] << " verts, " <<
-          rbuf[4*i+1] << " edges, " << rbuf[4*i+2] << " faces, " << rbuf[4*i+3] << " elements" << endl;
+          rbuf[4*i + 1] << " edges, " << rbuf[4*i + 2] << " faces, " << rbuf[4*i + 3] << " elements" << endl;
     }
   }
 

diff --git a/examples/old/ObbTree.cpp b/examples/old/ObbTree.cpp
index f83b440..ff4aadf 100644
--- a/examples/old/ObbTree.cpp
+++ b/examples/old/ObbTree.cpp
@@ -22,9 +22,10 @@ int main(int argc, char **argv) {
   moab::Range tris;
   //moab::OrientedBoxTreeTool::Settings settings;
 
-  rval = mb->get_entities_by_type( 0, moab::MBTRI, tris );
+  rval = mb->get_entities_by_type(0, moab::MBTRI, tris);
   if (rval != moab::MB_SUCCESS) {
     std::cerr << "Couldn't get triangles." << std::endl;
+    delete mb;
     return 1;
   }
 
@@ -33,7 +34,8 @@ int main(int argc, char **argv) {
   //rval = tool.build(tris, tree_root, &settings);
   rval = tool.build(tris, tree_root);
   if (rval != moab::MB_SUCCESS) {
-    std::cerr << "Could'nt build tree." << std::endl;    
+    std::cerr << "Could'nt build tree." << std::endl;
+    delete mb;
     return 1;
   }
   
@@ -42,6 +44,7 @@ int main(int argc, char **argv) {
   rval = tool.box(tree_root, box_center, box_axis1, box_axis2, box_axis3);
   if (rval != moab::MB_SUCCESS) {
     std::cerr << "Couldn't get box for tree root set.";
+    delete mb;
     return 1;
   }
 
@@ -52,17 +55,19 @@ int main(int argc, char **argv) {
   std::vector<double> intersections;
   std::vector<moab::EntityHandle> intersection_facets;
 
-  for (int i=0; i<3; i++)
-    pnt_start[i] = box_center[i]-box_axis1[i];
+  for (int i = 0; i < 3; i++)
+    pnt_start[i] = box_center[i] - box_axis1[i];
 
-  if (ray_length>0) // normalize ray direction
-    for (int j=0; j<3; j++)
-      box_axis1[j]=2*box_axis1[j]/ray_length;
+  if (ray_length > 0) { // normalize ray direction
+    for (int j = 0; j < 3; j++)
+      box_axis1[j] = 2 * box_axis1[j] / ray_length;
+  }
   rval = tool.ray_intersect_triangles(intersections, intersection_facets, 
 				      tree_root, 10e-12, pnt_start, box_axis1,
 				      &ray_length);
   if (rval != moab::MB_SUCCESS) {
     std::cerr << "Couldn't ray tracing.";
+    delete mb;
     return 1;
   }
   
@@ -71,9 +76,8 @@ int main(int argc, char **argv) {
   std::cout << " ray direction: " << box_axis1[0] << " " << box_axis1[1] << " " << box_axis1[2] << "\n";
   std::cout << "# of intersections : " << intersections.size() << std::endl;
   std::cout << "intersection distances are on";
-  for (unsigned int i = 0; i < intersections.size(); i++) {
+  for (unsigned int i = 0; i < intersections.size(); i++)
     std::cout << " " << intersections[i];
-  }
   std::cout << " of ray length " << ray_length << std::endl;
 
   delete mb;

diff --git a/examples/old/simple/GetEntities.cpp b/examples/old/simple/GetEntities.cpp
index 8d235fd..31d24d7 100644
--- a/examples/old/simple/GetEntities.cpp
+++ b/examples/old/simple/GetEntities.cpp
@@ -8,18 +8,24 @@ int main(int argc, char **argv) {
     return 0;
   }
 
-    // instantiate & load a mesh from a file
+  // Instantiate & load a mesh from a file
   moab::Core *mb = new moab::Core();
   moab::ErrorCode rval = mb->load_mesh(argv[1]);
-  if (moab::MB_SUCCESS != rval) return 1;
+  if (moab::MB_SUCCESS != rval) {
+    delete mb;
+    return 1;
+  }
 
   moab::Range ents;
 
-    // iterate over dimensions
+  // Iterate over dimensions
   for (int d = 0; d <= 3; d++) {
     ents.clear();
     rval = mb->get_entities_by_dimension(0, d, ents);
-    if (moab::MB_SUCCESS != rval) return 1;
+    if (moab::MB_SUCCESS != rval) {
+      delete mb;
+      return 1;
+    }
     std::cout << "Found " << ents.size() << " " << d << "-dimensional entities:" << std::endl;
     for (moab::Range::iterator it = ents.begin(); it != ents.end(); it++) {
       moab::EntityHandle ent = *it;

diff --git a/src/io/ReadNCDF.cpp b/src/io/ReadNCDF.cpp
index 3ed25d1..c400cd2 100644
--- a/src/io/ReadNCDF.cpp
+++ b/src/io/ReadNCDF.cpp
@@ -171,13 +171,11 @@ void ReadNCDF::reset()
     nodesInLoadedBlocks.clear();
 }
 
-
 ReadNCDF::~ReadNCDF() 
 {
   mdbImpl->release_interface(readMeshIface);
 }
   
-
 ErrorCode ReadNCDF::read_tag_values(const char* file_name,
                                     const char* tag_name,
                                     const FileOptions& ,
@@ -236,8 +234,6 @@ ErrorCode ReadNCDF::read_tag_values(const char* file_name,
   return MB_SUCCESS;
 }
 
-
-
 ErrorCode ReadNCDF::load_file(const char *exodus_file_name,
                               const EntityHandle* file_set,
                               const FileOptions& opts,
@@ -328,8 +324,6 @@ ErrorCode ReadNCDF::load_file(const char *exodus_file_name,
   return MB_SUCCESS;
 }
 
-
-
 ErrorCode ReadNCDF::read_exodus_header()
 {
   CPU_WORD_SIZE = sizeof(double);  // With ExodusII version 2, all floats
@@ -403,17 +397,18 @@ ErrorCode ReadNCDF::read_exodus_header()
     readMeshIface->report_error("ReadNCDF:: Problem getting title attribute.");
     return MB_FAILURE;
   }
-  char *title = new char[att_len+1];
   if (att_type != NC_CHAR) {
     readMeshIface->report_error("ReadNCDF:: title didn't have type char.");
     return MB_FAILURE;
   }
+  char *title = new char[att_len + 1];
   fail = nc_get_att_text(ncFile, NC_GLOBAL, "title", title);
   if (NC_NOERR != fail) {
     readMeshIface->report_error("ReadNCDF:: trouble getting title.");
+    delete[] title;
     return MB_FAILURE;
   }
-  delete [] title;
+  delete[] title;
 
   return MB_SUCCESS;
 }
@@ -683,12 +678,10 @@ ErrorCode ReadNCDF::read_elements(const Tag* file_id_tag)
     const int* reorder = exodus_elem_order_map[mb_type][verts_per_element];
     if (reorder)
       ReadUtilIface::reorder( reorder, conn, this_it->numElements, verts_per_element );
-    
 
-      
     readMeshIface->update_adjacencies((*this_it).startMBId, (*this_it).numElements,
                                       ExoIIUtil::VerticesPerElement[(*this_it).elemType], conn);
-    
+
     if ( result == -1 )
     {
       readMeshIface->report_error("ReadNCDF:: error getting element connectivity for block %i",
@@ -701,8 +694,7 @@ ErrorCode ReadNCDF::read_elements(const Tag* file_id_tag)
       return MB_FAILURE;
     if( mdbImpl->tag_set_data( mGlobalIdTag, &ms_handle, 1, &block_id ) != MB_SUCCESS )
       return MB_FAILURE;
-      
-      
+
     if (file_id_tag) {
       Range range;
       range.insert( this_it->startMBId, this_it->startMBId + this_it->numElements - 1 );
@@ -1199,7 +1191,6 @@ ErrorCode ReadNCDF::create_ss_elements( int *element_ids,
     else if( type == MBQUAD &&
              exoii_type >= EXOII_SHELL && exoii_type <= EXOII_SHELL9 )
     {
-
       //ent_handle = CREATE_HANDLE(MBQUAD, base_id, error );
 
       //just use this quad
@@ -1325,9 +1316,7 @@ ErrorCode ReadNCDF::create_ss_elements( int *element_ids,
             dist_factor_vector.push_back( temp_dist_factor_vector[df_index++] );
         }
       }
-
     }
-
   }
 
   return MB_SUCCESS; 
@@ -1411,11 +1400,9 @@ ErrorCode ReadNCDF::create_sideset_element( const std::vector<EntityHandle>& con
   return error;
 }
 
-
 ErrorCode ReadNCDF::find_side_element_type( const int exodus_id, ExoIIElementType &elem_type, 
                                                 ReadBlockData &block_data, int &df_index, int side_id)
 {
-
   std::vector<ReadBlockData>::iterator iter, end_iter;
   iter = blocksLoading.begin();
   end_iter = blocksLoading.end();
@@ -1450,7 +1437,6 @@ ErrorCode ReadNCDF::find_side_element_type( const int exodus_id, ExoIIElementTyp
           df_index += 3;
 
         return MB_FAILURE;
-
       }
 
       block_data = *iter;

diff --git a/src/io/WriteSmf.cpp b/src/io/WriteSmf.cpp
index 9d7f5f0..d2c4fc9 100644
--- a/src/io/WriteSmf.cpp
+++ b/src/io/WriteSmf.cpp
@@ -13,7 +13,6 @@
  * 
  */
 
-
 #ifdef WIN32
 #ifdef _DEBUG
 // turn off warnings that say they debugging identifier has been truncated
@@ -22,7 +21,6 @@
 #endif
 #endif
 
-
 #include "WriteSmf.hpp"
 
 #include <fstream>
@@ -48,15 +46,16 @@ namespace moab {
 const int DEFAULT_PRECISION = 10;
 //const bool DEFAULT_STRICT = true;
 
-WriterIface *WriteSmf::factory( Interface* iface )
-  { return new WriteSmf( iface ); }
+WriterIface *WriteSmf::factory(Interface* iface)
+{
+  return new WriteSmf(iface);
+}
 
-WriteSmf::WriteSmf(Interface *impl) 
-    : mbImpl(impl), writeTool(0)
+WriteSmf::WriteSmf(Interface *impl)
+  : mbImpl(impl), writeTool(0)
 {
   assert(impl != NULL);
-
-  impl->query_interface( writeTool );
+  impl->query_interface(writeTool);
 }
 
 WriteSmf::~WriteSmf() 
@@ -72,119 +71,124 @@ ErrorCode WriteSmf::write_file(const char *file_name,
                                  const std::vector<std::string>& ,
                                  const Tag* /*tag_list*/,
                                  int /*num_tags*/,
-                                 int )
+                                 int /*export_dimension*/)
 {
   ErrorCode rval;
 
-    // Get precision for node coordinates
+  // Get precision for node coordinates
   int precision;
-  if (MB_SUCCESS != opts.get_int_option( "PRECISION", precision ))
+  if (MB_SUCCESS != opts.get_int_option("PRECISION", precision))
     precision = DEFAULT_PRECISION;
-  
-   // Honor overwrite flag
-  if (!overwrite)
-  {
-    rval = writeTool->check_doesnt_exist( file_name );
+
+  // Honor overwrite flag
+  if (!overwrite) {
+    rval = writeTool->check_doesnt_exist(file_name);
     if (MB_SUCCESS != rval)
       return rval;
   }
-  
-    // Create file
-  std::ofstream file( file_name );
-  if (!file)
-  {
-    writeTool->report_error("Could not open file: %s\n", file_name );
+
+  // Create file
+  std::ofstream file(file_name);
+  if (!file) {
+    writeTool->report_error("Could not open file: %s\n", file_name);
     return MB_FILE_WRITE_ERROR;
   }
-  file.precision( precision );
-    // Get entities to write
-  
+  file.precision(precision);
+
+  // Get entities to write
   Range triangles;
-  if (!output_list || !num_sets)
-  {
-    rval = mbImpl->get_entities_by_type( 0, MBTRI, triangles, false);
-    if (MB_SUCCESS != rval) return rval;
+  if (!output_list || !num_sets) {
+    rval = mbImpl->get_entities_by_type(0, MBTRI, triangles, false);
+    if (MB_SUCCESS != rval)
+      return rval;
 
-    // somehow get all the nodes from this range, order them, uniquify, then use binary search
+  // Somehow get all the nodes from this range, order them, uniquify, then use binary search
   }
-  else
-  {
+  else {
     // get all triangles from output sets
-    for (int i=0; i<num_sets; i++)
-      rval = mbImpl->get_entities_by_type( output_list[i], MBTRI, triangles, false);
+    for (int i = 0; i < num_sets; i++)
+      rval = mbImpl->get_entities_by_type(output_list[i], MBTRI, triangles, false);
   }
-  // use an array with all the connectivities in the triangles; it will be converted later to ints
+  // Use an array with all the connectivities in the triangles; it will be converted later to ints
   int numTriangles = triangles.size();
-  int array_alloc = 3*numTriangles;       // allocated size of 'array'
+  int array_alloc = 3 * numTriangles;       // allocated size of 'array'
   EntityHandle* array = new EntityHandle[array_alloc]; // ptr to working array of result handles
-  // fill up array with node handles; reorder and uniquify 
+  // Fill up array with node handles; reorder and uniquify
   if (!array)
      return MB_MEMORY_ALLOCATION_FAILED;
   int fillA = 0;
-  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e)
-    {
+  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e) {
       const EntityHandle* conn;
       int conn_len;
-      rval = mbImpl->get_connectivity( *e, conn, conn_len );
-      if (MB_SUCCESS != rval  ) 
-	return rval;
-      if ( 3!=conn_len) 
+      rval = mbImpl->get_connectivity(*e, conn, conn_len);
+      if (MB_SUCCESS != rval) {
+        delete[] array;
+        return rval;
+      }
+      if (3 != conn_len) {
+        delete[] array;
         return MB_INVALID_SIZE;
+      }
 
       for (int i = 0; i < conn_len; ++i)
         array[fillA++] = conn[i];
-    }
-  if (fillA != array_alloc)
-	 return MB_INVALID_SIZE;
-    
-  std::sort( array, array + array_alloc);
-  int numNodes = std::unique(array, array + array_alloc ) - array;
-  
+  }
+  if (fillA != array_alloc) {
+    delete[] array;
+    return MB_INVALID_SIZE;
+  }
+
+  std::sort(array, array + array_alloc);
+  int numNodes = std::unique(array, array + array_alloc) - array;
+
   file << "#$SMF 1.0\n";
   file << "#$vertices " << numNodes << std::endl;
   file << "#$faces " << numTriangles << std::endl;
   file << "# \n";
   file << "# output from MOAB \n";
   file << "# \n";
-  
+
   // output first the nodes
   // num nodes??
   // write the nodes 
   double coord[3];
-  for(int i=0; i<numNodes; i++)
-    {
-      EntityHandle node_handle = array[i];
-     
-      rval = mbImpl->get_coords(&node_handle,1, coord);
-      if(rval !=MB_SUCCESS) return rval;
-      
-      file << "v " << coord[0] << " " << coord[1] << " " << coord[2] << std::endl; 
+  for (int i = 0; i < numNodes; i++) {
+    EntityHandle node_handle = array[i];
+
+    rval = mbImpl->get_coords(&node_handle, 1, coord);
+    if (rval != MB_SUCCESS) {
+      delete[] array;
+      return rval;
     }
-  // write faces now
-  // leave a blank line for cosmetics
+
+    file << "v " << coord[0] << " " << coord[1] << " " << coord[2] << std::endl;
+  }
+  // Write faces now
+  // Leave a blank line for cosmetics
   file << " \n";
-  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e)
-    {
-      const EntityHandle* conn;
-      int conn_len;
-      rval = mbImpl->get_connectivity( *e, conn, conn_len );
-      if (MB_SUCCESS != rval  ) 
-	return rval;
-      if ( 3!=conn_len) 
-        return MB_INVALID_SIZE;
-      file << "f ";
-      for (int i = 0; i < conn_len; ++i)
-      {
-	int indexInArray = std::lower_bound( array, array + numNodes, conn[i] ) - array;
-        file << indexInArray + 1 << " " ;
-      }
-      file << std::endl;
+  for (Range::const_iterator e = triangles.begin(); e != triangles.end(); ++e) {
+    const EntityHandle* conn;
+    int conn_len;
+    rval = mbImpl->get_connectivity(*e, conn, conn_len);
+    if (MB_SUCCESS != rval) {
+      delete[] array;
+      return rval;
     }
+    if (3!= conn_len) {
+      delete[] array;
+      return MB_INVALID_SIZE;
+    }
+    file << "f ";
+    for (int i = 0; i < conn_len; ++i) {
+      int indexInArray = std::lower_bound(array, array + numNodes, conn[i]) - array;
+      file << indexInArray + 1 << " ";
+    }
+    file << std::endl;
+  }
 
   file.close();
-  delete [] array;
+  delete[] array;
   return MB_SUCCESS;
 }
 
 } // namespace moab
-

diff --git a/src/parallel/ParallelComm.cpp b/src/parallel/ParallelComm.cpp
index 2d9e61c..d9e06d5 100644
--- a/src/parallel/ParallelComm.cpp
+++ b/src/parallel/ParallelComm.cpp
@@ -614,6 +614,10 @@ namespace moab {
       
         result = pack_buffer(entities[i], adjacencies, tags, 
                              false, -1, &buff); 
+        if (MB_SUCCESS != result) {
+          delete[] sendCounts;
+          delete[] displacements;
+        }
         RRA("Failed to compute buffer size in scatter_entities.");
 
         buff_size = buff.buff_ptr - buff.mem_ptr - prev_size;
@@ -626,6 +630,8 @@ namespace moab {
     success = MPI_Bcast(sendCounts, nProcs, MPI_INT, from_proc, procConfig.proc_comm());
     if (MPI_SUCCESS != success) {
       result = MB_FAILURE;
+      delete[] sendCounts;
+      delete[] displacements;
       RRA("MPI_Bcast of buffer size failed.");
     }
   
@@ -643,6 +649,8 @@ namespace moab {
   
     if (MPI_SUCCESS != success) {
       result = MB_FAILURE;
+      delete[] sendCounts;
+      delete[] displacements;
       RRA("MPI_Scatterv of buffer failed.");
     }
 
@@ -655,10 +663,17 @@ namespace moab {
       rec_buff.reset_ptr(sizeof(int));
       result = unpack_buffer(rec_buff.buff_ptr, false, from_proc, -1, 
                              dum1a, dum1b, dum1p, dum2, dum2, dum3, dum4);
+      if (MB_SUCCESS != result) {
+        delete[] sendCounts;
+        delete[] displacements;
+      }
       RRA("Failed to unpack buffer in scatter_entities.");
       std::copy(dum4.begin(), dum4.end(), range_inserter(entities[my_proc]));
     }
 
+    delete[] sendCounts;
+    delete[] displacements;
+
     return MB_SUCCESS;
 #endif
   }

diff --git a/test/h5file/h5file_test.cpp b/test/h5file/h5file_test.cpp
index 66703a5..94dc218 100644
--- a/test/h5file/h5file_test.cpp
+++ b/test/h5file/h5file_test.cpp
@@ -42,7 +42,6 @@ const int REGION_SET_ID = 1103;
 const int EMPTY_SET_ID  = 1100;
 const int SET_SET_ID    = 1105;
 
-
 Interface* iface;
 
 void create();
@@ -83,7 +82,6 @@ int main(int argc, char* argv[])
     }
   }
   
-  
   iface = new Core();
   
   // create a dodecahedron and inscribed hex
@@ -98,6 +96,7 @@ int main(int argc, char* argv[])
     fprintf( stderr, "Failed to write \"%s\"\n", filename );
     if (MB_SUCCESS == iface->get_last_error( msg ))
       fprintf( stderr, "%s\n", msg.c_str() );
+    delete iface;
     return 1;
   }
   
@@ -109,6 +108,7 @@ int main(int argc, char* argv[])
     fprintf( stderr, "Failed to read \"%s\"\n", filename );
     if (MB_SUCCESS == iface->get_last_error( msg ))
       fprintf( stderr, "%s\n", msg.c_str() );
+    delete iface;
     return 1;
   }
   
@@ -117,6 +117,7 @@ int main(int argc, char* argv[])
   if (!compare())
   {
     fprintf(stderr, "Comparison failed.\n");
+    delete iface;
     return 1;
   }
   fprintf( stderr, "success!\n" );
@@ -129,6 +130,7 @@ int main(int argc, char* argv[])
     fprintf( stderr, "Failed to write \"%s\"\n", filename );
     if (MB_SUCCESS == iface->get_last_error( msg ))
       fprintf( stderr, "%s\n", msg.c_str() );
+    delete iface;
     return 1;
   }
  
@@ -146,6 +148,7 @@ int main(int argc, char* argv[])
     fprintf( stderr, "Failed to read \"%s\"\n", filename );
     if (MB_SUCCESS == iface->get_last_error( msg ))
       fprintf( stderr, "%s\n", msg.c_str() );
+    delete iface;
     return 1;
   }
 
@@ -154,6 +157,7 @@ int main(int argc, char* argv[])
   if (!compare())
   {
     fprintf(stderr, "Comparison failed.\n");
+    delete iface;
     return 1;
   }
   fprintf( stderr, "success!\n" );
@@ -167,6 +171,7 @@ int main(int argc, char* argv[])
   // Clean up the file.
   remove( filename );
   fprintf( stderr, "done.\n" );
+  delete iface;
   return 0;
 }
 
@@ -233,7 +238,6 @@ EntityHandle make_set( unsigned int options,
   return handle;
 }
 
-
 void create()
 {
   // Create dodecahedron
@@ -427,8 +431,7 @@ bool compare_conn( std::vector<EntityHandle>& conn1,
       return false;
     }
   }
- 
-  
+
   std::vector<int> tags[2];
   tags[0].resize( conn1.size() ); tags[1].resize( conn2.size() );
   Tag tag;
@@ -486,9 +489,8 @@ bool compare_sets( int id, const char* tag_name = 0 )
   EntityHandle set1 = *range.begin();
   EntityHandle set2 = *++range.begin();
   
-  
     // Compare set descriptions
-  
+
   unsigned opt1, opt2;
   if (MB_SUCCESS != iface->get_meshset_options( set1, opt1 ) ||
       MB_SUCCESS != iface->get_meshset_options( set2, opt2 ))
@@ -509,7 +511,6 @@ bool compare_sets( int id, const char* tag_name = 0 )
     return false;
   }
 
-
     // Compare set contents
     // First check if same number of entities.
     // Then select from three possible methods to compare set contents
@@ -599,10 +600,9 @@ bool compare_sets( int id, const char* tag_name = 0 )
     if (!ok)
       return false;
   }
-  
-    
+
     // Compare set parent/child links using global id
-  
+
   ok = true;
   const char* words[] = { "children", "parents" };
   std::vector<EntityHandle> adj1, adj2;
@@ -686,7 +686,6 @@ bool compare_tags( EntityHandle dod[] )
     return false;
   }
 
-
     // Get double tag handle and characterstics
   if (MB_SUCCESS != iface->tag_get_handle( dblname, 1, MB_TYPE_DOUBLE, tag, MB_TAG_DENSE|MB_TAG_STORE ))
     moab_error( "tag_get_handle(dblname)" );
@@ -708,7 +707,6 @@ bool compare_tags( EntityHandle dod[] )
     return false;
   }
  
-
     // Get handle tag handle and characterstics
   if (MB_SUCCESS != iface->tag_get_handle( handlename, 3, MB_TYPE_HANDLE, tag, MB_TAG_SPARSE|MB_TAG_STORE ))
     moab_error( "tag_get_handle(handlename)" );
@@ -760,8 +758,6 @@ bool compare_tags( EntityHandle dod[] )
   
   return true;
 }
- 
-  
 
 bool compare()
 {
@@ -861,6 +857,6 @@ void moab_error( const char* str )
   fprintf( stderr, "%s() failed.\n", str );
   if (MB_SUCCESS == iface->get_last_error( msg ))
     fprintf( stderr, "%s\n", msg.c_str() );
+  delete iface;
   exit( 1 );
 }
-  

diff --git a/test/io/VtkTest.cpp b/test/io/VtkTest.cpp
index 100674c..d6208a2 100644
--- a/test/io/VtkTest.cpp
+++ b/test/io/VtkTest.cpp
@@ -108,7 +108,7 @@ DECLARE_TEST(unstructured_field)
 
 int main( int argc, char* argv[] )
 {
-  int *test_indices = (int*)malloc( sizeof(int) * num_tests );
+  int *test_indices = (int*)malloc(sizeof(int) * num_tests);
   int test_count;
     // if no arguments, do all tests
   if (argc == 1) {
@@ -126,8 +126,7 @@ int main( int argc, char* argv[] )
   }
   
   int fail_count = 0;
-  for (int i = 0; i < test_count; ++i)
-  {
+  for (int i = 0; i < test_count; ++i) {
     test_data& test = test_array[test_indices[i]];
     printf("Testing %s...\n", test.name );
     if (!(test.result = test.test()))
@@ -137,23 +136,23 @@ int main( int argc, char* argv[] )
   printf("\n\n");
   if (fail_count) {
     printf("FAILED TESTS:\n");
-    for (int i = 0; i < test_count; ++i)
-    {
+    for (int i = 0; i < test_count; ++i) {
       test_data& test = test_array[test_indices[i]];
       if (!test.result)
         printf("\t%s\n", test.name);
     }
   }
-    
-  
+
   if (test_count == 0)
     printf("0 VTK tests run\n");
   else if (fail_count == 0)
     printf("%d tests passed\n", test_count );
   else
-    printf("%d of %d tests failed\n", fail_count, test_count );
+    printf("%d of %d tests failed\n", fail_count, test_count);
   printf("\n");
-  
+
+  free(test_indices);
+
   return fail_count;
 }
 
@@ -179,7 +178,6 @@ static inline bool is_error( ErrorCode b )
 bool read_file( Interface* iface, const char* file );
 bool write_and_read( Interface* iface1, Interface* iface2 );
 
-
 bool test_read_write_element( const double* coords, unsigned num_coords,
                               const int* vtk_conn, const int* moab_conn,
                               unsigned num_conn,
@@ -203,8 +201,7 @@ bool test_edge2()
       
   return test_read_write_element( coords, 5, conn, conn, 10, 5, 3, MBEDGE );
 }
-  
-  
+
 bool test_edge3()
 {
   const double coords[] =
@@ -243,7 +240,6 @@ bool test_tri3()
   return test_read_write_element( coords, 5, conn, conn, 12, 4, 5, MBTRI );
 }
 
-
 bool test_tri6()
 {
   const double coords[] = 
@@ -429,7 +425,6 @@ bool test_tet10()
   return test_read_write_element( coords, 14, conn, conn, 20, 2, 24, MBTET );
 }
 
-
 const double grid_2x2x2[] =
   { 0, 0, 0,
     1, 0, 0,
@@ -904,7 +899,6 @@ bool test_vector_attrib_double()
   return test_vector_attrib("double", MB_TYPE_DOUBLE);
 }
 
-
 bool test_tensor_attrib_uchar()
 {
   return test_tensor_attrib("unsigned_char", MB_TYPE_INTEGER);
@@ -955,9 +949,6 @@ bool test_tensor_attrib_double()
   return test_tensor_attrib("double", MB_TYPE_DOUBLE);
 }
 
-
-
-
 bool read_file( Interface* iface, const char* file )
 {
   char fname[] = "tmp_file.vtk";
@@ -1086,7 +1077,6 @@ bool match_vertices_and_elements( Interface* iface,
   return true;
 }
 
-
 bool check_elements( Interface* iface,
                      EntityType moab_type, unsigned num_elem, unsigned vert_per_elem,
                      const double* coords, unsigned num_vert, 
@@ -1099,8 +1089,6 @@ bool check_elements( Interface* iface,
   CHECK(rval);
   return true;
 }
-      
-                     
 
 bool test_read_write_element( const double* coords, unsigned num_verts,
                               const int* vtk_conn, const int* moab_conn,
@@ -1295,7 +1283,6 @@ bool check_tag_values( Interface* iface,
   return true;
 }
 
-
 bool check_tag_values( Interface* iface, DataType type, int vals_per_ent )
 {
   EntityHandle vert_handles[6], elem_handles[2];
@@ -1369,7 +1356,7 @@ bool test_tensor_attrib( const char* vtk_type, DataType mb_type )
   return check_tag_data( file, mb_type, 9 );
 } 
 
-bool test_subset( )
+bool test_subset()
 {
   Core moab_inst;
   Interface& moab = moab_inst;

diff --git a/test/kd_tree_time.cpp b/test/kd_tree_time.cpp
index 10af975..af0e33d 100644
--- a/test/kd_tree_time.cpp
+++ b/test/kd_tree_time.cpp
@@ -8,49 +8,49 @@
 
 using namespace moab;
 
-void usage( const char* argv0 )
+void usage(const char* argv0)
 {
   fprintf(stderr, "usage: %s [-t] [-d <result_file>] <tree_file><point_file> [<count>]\n", argv0);
   exit(1);
 }
 
-void print_file_stats( Interface& moab )
+void print_file_stats(Interface& moab)
 {
   ErrorCode rval;
   int num_tri;
   Range sets;
   unsigned long set_mem, set_am, tag_mem, tag_am;
-  
-  rval = moab.get_number_entities_by_type( 0, MBTRI, num_tri );
+
+  rval = moab.get_number_entities_by_type(0, MBTRI, num_tri);
   if (MB_SUCCESS != rval)
     num_tri = -1;
-  rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );
+  rval = moab.get_entities_by_type(0, MBENTITYSET, sets);
   if (MB_SUCCESS != rval)
     sets.clear();
-  
-  moab.estimated_memory_use( sets, 0, 0, &set_mem, &set_am, 0, 0, 0, 0, &tag_mem, &tag_am );
-  printf( "Triangles:   %d\n", num_tri );
-  printf( "Sets:        %lu\n", (unsigned long)sets.size() );
-  printf( "Set storage: %lu (%lu)\n", set_mem, set_am );
-  printf( "Tag storage: %lu (%lu)\n", tag_mem, tag_am );
+
+  moab.estimated_memory_use(sets, 0, 0, &set_mem, &set_am, 0, 0, 0, 0, &tag_mem, &tag_am);
+  printf("Triangles:   %d\n", num_tri);
+  printf("Sets:        %lu\n", (unsigned long)sets.size());
+  printf("Set storage: %lu (%lu)\n", set_mem, set_am);
+  printf("Tag storage: %lu (%lu)\n", tag_mem, tag_am);
 }
 
-int main( int argc, char* argv[] ) 
+int main(int argc, char* argv[])
 {
   double* values;
   unsigned long length;
   FILE *file, *rfile = 0;
   unsigned long count = 0;
   clock_t t;
-  
+
   const char* tree_file = 0;
   const char* point_file = 0;
   const char* result_file = 0;
   bool query_triangles = false;
-  
+
   if (argc < 3 || argc > 7)
     usage(argv[0]);
-  
+
   for (int i = 1; i < argc; ++i) {
     if (!strcmp("-t", argv[i]))
       query_triangles = true;
@@ -66,87 +66,93 @@ int main( int argc, char* argv[] )
       point_file = argv[i];
     else {
       char* endptr;
-      count = strtol( argv[i], &endptr, 0 );
+      count = strtol(argv[i], &endptr, 0);
       if (*endptr || count < 1)
         usage(argv[0]);
     }
   }
-  
-  file = fopen( point_file, "rb" );
+
+  file = fopen(point_file, "rb");
   if (!file) {
     perror(point_file);
     return 2;
   }
-  fseek( file, 0, SEEK_END );
-  length = ftell(file) / (3*sizeof(double));
-  fseek( file, 0, SEEK_SET );
-  values = new double[3*length];
-  if (length != fread( values, 3*sizeof(double), length, file )) {
-    fprintf( stderr, "Error reading %lu points from file \"%s\"\n", length, argv[2] );
+  fseek(file, 0, SEEK_END);
+  length = ftell(file) / (3 * sizeof(double));
+  fseek(file, 0, SEEK_SET);
+  values = new double[3 * length];
+  if (length != fread(values, 3 * sizeof(double), length, file)) {
+    fprintf(stderr, "Error reading %lu points from file \"%s\"\n", length, argv[2]);
+    delete[] values;
     return 2;
   }
-  fclose( file );
-  
+  fclose(file);
+
   if (result_file) {
-    rfile = fopen( result_file, "w" );
+    rfile = fopen(result_file, "w");
     if (!rfile) {
       perror(result_file);
+      delete[] values;
       return 2;
     }
   }
-  
+
   if (!count)
     count = length;
- 
-  printf("Loading tree..."); fflush( stdout );
+
+  printf("Loading tree...");
+  fflush(stdout);
   t = clock();
   Core moab;
-  ErrorCode rval = moab.load_mesh( tree_file, 0, 0 );
+  ErrorCode rval = moab.load_mesh(tree_file, 0, 0);
   if (MB_SUCCESS != rval) {
-    fprintf(stderr,"Failed to read file: %s\n", tree_file );
+    fprintf(stderr,"Failed to read file: %s\n", tree_file);
+    delete[] values;
     return 2;
   }
-  printf("%0.2f seconds\n", (clock()-t)/(double)CLOCKS_PER_SEC); fflush( stdout );
-  
+  printf("%0.2f seconds\n", (clock() - t) / (double)CLOCKS_PER_SEC);
+  fflush(stdout);
+
   Range range;
   AdaptiveKDTree tool(&moab);
   tool.find_all_trees(range);
   if (range.size() != 1) {
-    fprintf(stderr,"%s : found %d kd-trees\n", argv[1], (int)range.size() );
+    fprintf(stderr,"%s : found %d kd-trees\n", argv[1], (int)range.size());
+    delete[] values;
     return 3;
   }
   EntityHandle root = range.front();
 
-  print_file_stats( moab );
-  
-  printf("Running point queries..."); fflush( stdout );
+  print_file_stats(moab);
+
+  printf("Running point queries...");
+  fflush(stdout);
   t = clock();
   EntityHandle leaf;
   double pt[3];
   for (unsigned long i = 0; i < count; ++i) {
     const double* coords = values + 3 * (i % length);
     if (query_triangles)
-      rval = tool.closest_triangle( root, coords, pt, leaf );
+      rval = tool.closest_triangle(root, coords, pt, leaf);
     else
       rval = tool.point_search(coords, leaf, 0.0, NULL, &root);
     if (MB_SUCCESS != rval) {
       fprintf(stderr, "Failure (ErrorCode == %d) for point %d (%f, %f, %f)\n",
-        (int)rval, (int)(count % length), coords[0], coords[1], coords[2] );
+        (int)rval, (int)(count % length), coords[0], coords[1], coords[2]);
     }
     else if (rfile) {
       if (query_triangles)
-        fprintf( rfile, "%f %f %f %f %f %f %lu\n", 
+        fprintf(rfile, "%f %f %f %f %f %f %lu\n",
           coords[0], coords[1], coords[2],
-          pt[0], pt[1], pt[2], (unsigned long)leaf );
+          pt[0], pt[1], pt[2], (unsigned long)leaf);
       else
-        fprintf( rfile, "%f %f %f %lu\n", 
-          coords[0], coords[1], coords[2], (unsigned long)leaf );
+        fprintf(rfile, "%f %f %f %lu\n",
+          coords[0], coords[1], coords[2], (unsigned long)leaf);
     }
   }
-  printf("%0.2f seconds\n", (clock()-t)/(double)CLOCKS_PER_SEC); fflush( stdout );
+  printf("%0.2f seconds\n", (clock() - t) / (double)CLOCKS_PER_SEC);
+  fflush(stdout);
   delete[] values;
 
   return 0;
 }
-
-  

diff --git a/test/parallel/scdtest.cpp b/test/parallel/scdtest.cpp
index 5fe6f36..3202621 100644
--- a/test/parallel/scdtest.cpp
+++ b/test/parallel/scdtest.cpp
@@ -47,37 +47,37 @@ int main(int argc, char *argv[])
   MPI_Init(&argc, &argv);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   MPI_Comm_size(MPI_COMM_WORLD, &size);
-  if(size != 4 && size != 2) {
+  if (size != 4 && size != 2) {
     cerr << "Run this with 2 or 4 processes\n";
     exit(1);
   }
-  
+
   mbint = new Core();
-  mbpc  = new ParallelComm(mbint, MPI_COMM_WORLD);
+  mbpc = new ParallelComm(mbint, MPI_COMM_WORLD);
 
   set_local_domain_bounds();
   create_hexes_and_verts();
   resolve_and_exchange();
 
+  delete mbpc; // ParallelComm instance should be deleted before MOAB instance is deleted
+  delete mbint;
+
   MPI_Finalize();
   return 0;
 }
 
-
 void set_local_domain_bounds() 
 {
   switch (size) {
     case 2:
-        switch(rank) {
+        switch (rank) {
           case 0:
-              is = 0; ie = NI/2;
+              is = 0; ie = NI / 2;
               js = 0; je = NJ;
               ks = 0; ke = NK;
               break;
-
-
           case 1:
-              is = NI/2; ie = NI;
+              is = NI / 2; ie = NI;
               js = 0; je = NJ;
               ks = 0; ke = NK;
               break;
@@ -85,25 +85,25 @@ void set_local_domain_bounds()
         break;
         
     case 4:
-        switch(rank) {
+        switch (rank) {
           case 0:
-              is = 0; ie = NI/2;
-              js = 0; je = NJ/2;
+              is = 0; ie = NI / 2;
+              js = 0; je = NJ / 2;
               ks = 0; ke = NK;
               break;
           case 1:
-              is = NI/2; ie = NI;
-              js = 0; je = NJ/2;
+              is = NI / 2; ie = NI;
+              js = 0; je = NJ / 2;
               ks = 0; ke = NK;
               break;
           case 2:
-              is = 0; ie = NI/2;
-              js = NJ/2; je = NJ;
+              is = 0; ie = NI / 2;
+              js = NJ / 2; je = NJ;
               ks = 0; ke = NK;
               break;
           case 3:
-              is = NI/2; ie = NI;
-              js = NJ/2; je = NJ;
+              is = NI / 2; ie = NI;
+              js = NJ / 2; je = NJ;
               ks = 0; ke = NK;
               break;
         }
@@ -115,12 +115,11 @@ void set_local_domain_bounds()
   }
 }
 
-
 void create_hexes_and_verts()
 {
   Core *mbcore = dynamic_cast<Core*>(mbint);
   HomCoord coord_min(0,0,0);
-  HomCoord coord_max(ie-is, je-js, ke-ks);
+  HomCoord coord_max(ie - is, je - js, ke - ks);
   EntitySequence* vertex_seq = NULL;
   EntitySequence* cell_seq = NULL;
   EntityHandle vs, cs;
@@ -139,32 +138,31 @@ void create_hexes_and_verts()
   Tag global_id_tag;
   error(mbint->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, global_id_tag));
   EntityHandle handle = vs;
-  int i,j,k;
+  int i, j, k;
 
   ErrorCode err;
 
-  for(k = ks; k < ke + 1; k++)
-    for(j = js; j < je + 1; j++)
-      for(i = is; i < ie + 1; i++) {
-        gid = 1 + i + j*(NI+1) + k*(NI+1)*(NJ+1);
+  for (k = ks; k < ke + 1; k++)
+    for (j = js; j < je + 1; j++)
+      for (i = is; i < ie + 1; i++) {
+        gid = 1 + i + j*(NI + 1) + k*(NI + 1)*(NJ + 1);
         err = mbint->tag_set_data(global_id_tag, &handle, 1, &gid);
-        if(err != MB_SUCCESS) {
+        if (err != MB_SUCCESS) {
           exit(1);
         }
         handle++;
       }
 
   handle = cs;
-  for(k = ks; k < ke; k++)
-    for(j = js; j < je; j++)
-      for(i = is; i < ie; i++) {
+  for (k = ks; k < ke; k++)
+    for (j = js; j < je; j++)
+      for (i = is; i < ie; i++) {
         gid = 1 + i + j*NI + k*NI*NJ;
         error(mbint->tag_set_data(global_id_tag, &handle, 1, &gid));
-	handle++;
+        handle++;
       }
 }
 
-
 void resolve_and_exchange()
 {
   EntityHandle entity_set;
@@ -198,7 +196,7 @@ void resolve_and_exchange()
 
 void error(ErrorCode err)
 {
-  if(err != MB_SUCCESS) {
+  if (err != MB_SUCCESS) {
     cerr << "Error: MOAB function failed\n";
     assert(0);
   }

diff --git a/tools/mbzoltan/MBZoltan.cpp b/tools/mbzoltan/MBZoltan.cpp
index d07ffcf..1ec6757 100644
--- a/tools/mbzoltan/MBZoltan.cpp
+++ b/tools/mbzoltan/MBZoltan.cpp
@@ -65,34 +65,39 @@ static int *Parts=NULL;
 
 const bool debug = false;
 
-MBZoltan::MBZoltan( Interface *impl , 
-
+MBZoltan::MBZoltan( Interface *impl,
                     const bool use_coords,
-                    int argc, 
+                    int argc,
                     char **argv
 #ifdef CGM
                     , GeometryQueryTool *gqt
-#endif                   
-) 
-                   : mbImpl(impl), 
-
-                     myZZ(NULL), 
-                     newMoab(false), 
+#endif
+)
+                   : mbImpl(impl),
+                     myZZ(NULL),
+                     newMoab(false),
+                     newComm(false),
                      useCoords(use_coords),
-                     argcArg(argc), 
+                     argcArg(argc),
                      argvArg(argv)
 #ifdef CGM
                    , gti(gqt)
 #endif
 {
   mbpc = ParallelComm::get_pcomm(mbImpl, 0);
-  if (!mbpc)
-    mbpc = new ParallelComm( impl, MPI_COMM_WORLD, 0 );
+  if (!mbpc) {
+    mbpc = new ParallelComm(impl, MPI_COMM_WORLD, 0);
+    newComm = true;
+  }
 }
 
 MBZoltan::~MBZoltan() 
 {
-  if (NULL == myZZ) delete myZZ;
+  if (NULL != myZZ)
+    delete myZZ;
+
+  if (newComm)
+    delete mbpc;
 }
 
 ErrorCode MBZoltan::balance_mesh(const char *zmethod,
@@ -1068,7 +1073,8 @@ ErrorCode MBZoltan::partition_round_robin(const int n_part)
     DLIList<int> shared_procs;
     shared_procs.append(proc);
     TDParallel *td_par = (TDParallel *) entity->get_TD(&TDParallel::is_parallel);
-    if (td_par == NULL) td_par = new TDParallel(entity, NULL, &shared_procs);
+    if (td_par == NULL)
+      td_par = new TDParallel(entity, NULL, &shared_procs);
     loads[proc] += entity->measure();
 
     // assign to volumes, it should be removed in future
@@ -1079,7 +1085,8 @@ ErrorCode MBZoltan::partition_round_robin(const int n_part)
     for (j = 0; j < n_vol; j++) {
       RefEntity *vol = volumes.get_and_step();
       td_par = (TDParallel *) vol->get_TD(&TDParallel::is_parallel);
-      if (td_par == NULL) td_par = new TDParallel(vol, NULL, &shared_procs);
+      if (td_par == NULL)
+        td_par = new TDParallel(vol, NULL, &shared_procs);
     }
 
     // add local surface load
@@ -1117,6 +1124,8 @@ ErrorCode MBZoltan::partition_round_robin(const int n_part)
 
           if (parent_td == NULL) {
             PRINT_ERROR("parent Volume has to be partitioned.");
+            delete[] loads;
+            delete[] ve_loads;
             return MB_FAILURE;
           }
           child_shared_procs.append_unique(parent_td->get_charge_proc());
@@ -1129,6 +1138,8 @@ ErrorCode MBZoltan::partition_round_robin(const int n_part)
             if (entity->entity_type_info() == typeid(RefFace)) { // face
               if (child_shared_procs.size() != 2) {
                 PRINT_ERROR("Error: # of shared processors of interface surface should be 2.");
+                delete[] loads;
+                delete[] ve_loads;
                 return MB_FAILURE;
               }
 

diff --git a/tools/mbzoltan/MBZoltan.hpp b/tools/mbzoltan/MBZoltan.hpp
index e36ec13..269d9ae 100644
--- a/tools/mbzoltan/MBZoltan.hpp
+++ b/tools/mbzoltan/MBZoltan.hpp
@@ -171,6 +171,8 @@ using namespace moab;
     Range partSets;
   
     bool newMoab;
+
+    bool newComm;
   
     bool useCoords;

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list