Browse Source

examples/stencil: free allocated memory

Nathalie Furmento 11 years ago
parent
commit
275c9212e1
3 changed files with 13 additions and 0 deletions
  1. 6 0
      examples/stencil/stencil-blocks.c
  2. 6 0
      examples/stencil/stencil.c
  3. 1 0
      examples/stencil/stencil.h

+ 6 - 0
examples/stencil/stencil-blocks.c

@@ -157,6 +157,12 @@ void create_blocks_array(unsigned _sizex, unsigned _sizey, unsigned _sizez, unsi
 	}
 }
 
+void free_blocks_array()
+{
+	free(blocks);
+	free(block_sizes_z);
+}
+
 /*
  *	Initialization of the blocks
  */

+ 6 - 0
examples/stencil/stencil.c

@@ -155,6 +155,10 @@ static void init_problem(int argc, char **argv, int rank, int world_size)
 static void free_problem(int rank)
 {
      	free_memory_on_node(rank);
+	free_blocks_array();
+	free(who_runs_what);
+	free(who_runs_what_index);
+	free(last_tick);
 }
 
 /*
@@ -300,6 +304,7 @@ int main(int argc, char **argv)
 	STARPU_ASSERT(reduce_ret == MPI_SUCCESS);
 
 	memcpy(who_runs_what, who_runs_what_tmp, nbz * who_runs_what_len * sizeof(*who_runs_what));
+	free(who_runs_what_tmp);
 
 	/* XXX we should do a gather instead, here we assume that non initialized values are still 0 */
 	int *who_runs_what_index_tmp = malloc(nbz * sizeof(*who_runs_what_index));
@@ -307,6 +312,7 @@ int main(int argc, char **argv)
 	STARPU_ASSERT(reduce_ret == MPI_SUCCESS);
 
 	memcpy(who_runs_what_index, who_runs_what_index_tmp, nbz * sizeof(*who_runs_what_index));
+	free(who_runs_what_index_tmp);
 #endif
 
 	if (rank == 0)

+ 1 - 0
examples/stencil/stencil.h

@@ -93,6 +93,7 @@ int MPI_TAG1(int z, int iter, int dir);
 #define MIN(a,b)	((a)<(b)?(a):(b))
 
 void create_blocks_array(unsigned sizex, unsigned sizey, unsigned sizez, unsigned nbz);
+void free_blocks_array();
 struct block_description *get_block_description(int z);
 void assign_blocks_to_mpi_nodes(int world_size);
 void allocate_memory_on_node(int rank);