Browse Source

mpi: free allocated memory

Nathalie Furmento 12 years ago
parent
commit
2abca8e8fd
2 changed files with 19 additions and 10 deletions
  1. 17 6
      mpi/examples/complex/mpi_complex.c
  2. 2 4
      mpi/tests/insert_task_cache.c

+ 17 - 6
mpi/examples/complex/mpi_complex.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2012  Centre National de la Recherche Scientifique
+ * Copyright (C) 2012, 2013  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -37,6 +37,10 @@ int main(int argc, char **argv)
 	int ret;
 	int compare;
 
+	starpu_data_handle_t handle;
+	starpu_data_handle_t handle2;
+	starpu_data_handle_t foo_handle;
+
 	ret = starpu_init(NULL);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 	ret = starpu_mpi_init(&argc, &argv, 1);
@@ -55,11 +59,9 @@ int main(int argc, char **argv)
 		{
 			double real[2] = {4.0, 2.0};
 			double imaginary[2] = {7.0, 9.0};
-			starpu_data_handle_t handle;
 
 			double real2[2] = {14.0, 12.0};
 			double imaginary2[2] = {17.0, 19.0};
-			starpu_data_handle_t handle2;
 
 			int *compare_ptr = &compare;
 
@@ -76,7 +78,6 @@ int main(int argc, char **argv)
 			{
 				// We send a dummy variable only to check communication with predefined datatypes
 				int foo=12;
-				starpu_data_handle_t foo_handle;
 				starpu_variable_data_register(&foo_handle, 0, (uintptr_t)&foo, sizeof(foo));
 				starpu_mpi_isend_detached(foo_handle, 1, 40, MPI_COMM_WORLD, NULL, NULL);
 				starpu_insert_task(&foo_display, STARPU_R, foo_handle, 0);
@@ -86,7 +87,6 @@ int main(int argc, char **argv)
 		{
 			double real[2] = {0.0, 0.0};
 			double imaginary[2] = {0.0, 0.0};
-			starpu_data_handle_t handle;
 
 			starpu_complex_data_register(&handle, 0, real, imaginary, 2);
 			starpu_mpi_irecv_detached(handle, 0, 10, MPI_COMM_WORLD, NULL, NULL);
@@ -96,7 +96,6 @@ int main(int argc, char **argv)
 			{
 				// We send a dummy variable only to check communication with predefined datatypes
 				int foo=12;
-				starpu_data_handle_t foo_handle;
 				starpu_variable_data_register(&foo_handle, -1, (uintptr_t)NULL, sizeof(foo));
 				starpu_mpi_irecv_detached(foo_handle, 0, 40, MPI_COMM_WORLD, NULL, NULL);
 				starpu_insert_task(&foo_display, STARPU_R, foo_handle, 0);
@@ -104,7 +103,19 @@ int main(int argc, char **argv)
 
 		}
 	}
+
 	starpu_task_wait_for_all();
+
+	if (rank == 0)
+	{
+		starpu_data_unregister(handle2);
+	}
+	if (rank == 0 || rank == 1)
+	{
+		starpu_data_unregister(handle2);
+		starpu_data_unregister(foo_handle);
+	}
+
 	starpu_mpi_shutdown();
 	starpu_shutdown();
 

+ 2 - 4
mpi/tests/insert_task_cache.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2011, 2012  Centre National de la Recherche Scientifique
+ * Copyright (C) 2011, 2012, 2013  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -52,9 +52,8 @@ void test_cache(int rank, int size, int enabled, size_t *comm_amount)
 	int ret;
 	unsigned v[2][N];
 	starpu_data_handle_t data_handles[2];
-	char *string;
+	char string[50];
 
-	string = malloc(50);
 	sprintf(string, "STARPU_MPI_CACHE=%d", enabled);
 	putenv(string);
 
@@ -103,7 +102,6 @@ void test_cache(int rank, int size, int enabled, size_t *comm_amount)
 	starpu_mpi_comm_amounts_retrieve(comm_amount);
 	starpu_mpi_shutdown();
 	starpu_shutdown();
-	free(string);
 }
 
 int main(int argc, char **argv)