Browse Source

Fix bugs: MPI_Comm is now freed after Comm_split

Dhairya Malhotra 10 years ago
parent
commit
7258f5ab2d
2 changed files with 12 additions and 1 deletions
  1. 6 0
      include/mpi_tree.txx
  2. 6 1
      include/parUtils.txx

+ 6 - 0
include/mpi_tree.txx

@@ -730,6 +730,9 @@ inline int lineariseList(std::vector<MortonId> & list, MPI_Comm comm) {
     }
   }//not empty procs only
 
+  // Free new_comm
+  MPI_Comm_free(&new_comm);
+
   return 1;
 }//end fn.
 
@@ -913,6 +916,9 @@ inline int balanceOctree (std::vector<MortonId > &in, std::vector<MortonId > &ou
     if(new_size<size){
       par::partitionW<MortonId>(out, NULL , comm);
     }
+
+    // Free new_comm
+    MPI_Comm_free(&new_comm);
   }
 
   //////////////////////////////////////////////////////////////////////////////////////////////////

+ 6 - 1
include/parUtils.txx

@@ -395,6 +395,8 @@ namespace par{
       Vector<T> rbuff    ;
       Vector<T> rbuff_ext;
 
+      bool free_comm=false; // Flag to free comm.
+
       // Binary split and merge in each iteration.
       while(npes>1 && totSize>0){ // O(log p) iterations.
 
@@ -499,11 +501,14 @@ namespace par{
         {// Split comm.  O( log(p) ) ??
           MPI_Comm scomm;
           MPI_Comm_split(comm, myrank<=split_id, myrank, &scomm );
-          comm=scomm;
+          if(free_comm) MPI_Comm_free(&comm);
+          comm=scomm; free_comm=true;
+
           npes  =(myrank<=split_id? split_id+1: npes  -split_id-1);
           myrank=(myrank<=split_id? myrank    : myrank-split_id-1);
         }
       }
+      if(free_comm) MPI_Comm_free(&comm);
 
       SortedElem.Resize(nelem);
       memcpy(&SortedElem[0], &arr[0], nelem*sizeof(T));