瀏覽代碼

mpi_lu: Fix memleaks

Samuel Thibault 4 年之前
父節點
當前提交
5742376769
共有 2 個文件被更改,包括 68 次插入9 次删除
  1. 64 1
      mpi/examples/mpi_lu/plu_example.c
  2. 4 8
      mpi/examples/mpi_lu/pxlu_kernels.c

+ 64 - 1
mpi/examples/mpi_lu/plu_example.c

@@ -438,7 +438,7 @@ int main(int argc, char **argv)
 	int rank;
 	int world_size;
 	int ret;
-	unsigned i, j;
+	unsigned i, j, k;
 
 	/*
 	 *	Initialization
@@ -621,6 +621,69 @@ int main(int argc, char **argv)
 	free(dataA_handles);
 	free(dataA);
 
+#ifdef SINGLE_TMP11
+	starpu_data_unregister(tmp_11_block_handle);
+	starpu_free(tmp_11_block);
+#else
+	for (k = 0; k < nblocks; k++)
+	{
+		if (tmp_11_block_is_needed(rank, nblocks, k))
+		{
+			starpu_data_unregister(tmp_11_block_handles[k]);
+			starpu_free(tmp_11_block[k]);
+		}
+	}
+	free(tmp_11_block_handles);
+	free(tmp_11_block);
+#endif
+
+	for (k = 0; k < nblocks; k++)
+	{
+#ifdef SINGLE_TMP1221
+		if (tmp_12_block_is_needed(rank, nblocks, k))
+		{
+			starpu_data_unregister(tmp_12_block_handles);
+			starpu_free(tmp_12_block[k]);
+		}
+
+		if (tmp_21_block_is_needed(rank, nblocks, k))
+		{
+			starpu_data_unregister(tmp_21_block_handles[k]);
+			starpu_free(tmp_21_block[k]);
+		}
+#else
+	for (i = 0; i < 2; i++)
+	{
+		if (tmp_12_block_is_needed(rank, nblocks, k))
+		{
+			starpu_data_unregister(tmp_12_block_handles[i][k]);
+			starpu_free(tmp_12_block[i][k]);
+		}
+
+		if (tmp_21_block_is_needed(rank, nblocks, k))
+		{
+			starpu_data_unregister(tmp_21_block_handles[i][k]);
+			starpu_free(tmp_21_block[i][k]);
+		}
+	}
+#endif
+	}
+
+#ifdef SINGLE_TMP1221
+	free(tmp_12_block_handles);
+	free(tmp_21_block_handles);
+	free(tmp_12_block);
+	free(tmp_21_block);
+#else
+	for (i = 0; i < 2; i++)
+	{
+		free(tmp_12_block_handles[i]);
+		free(tmp_21_block_handles[i]);
+		free(tmp_12_block[i]);
+		free(tmp_21_block[i]);
+	}
+#endif
+
 	barrier_ret = MPI_Barrier(MPI_COMM_WORLD);
 	STARPU_ASSERT(barrier_ret == MPI_SUCCESS);
 

+ 4 - 8
mpi/examples/mpi_lu/pxlu_kernels.c

@@ -49,8 +49,6 @@ static inline void STARPU_PLU(common_u22)(void *descr[], int s, void *_args)
 	int rank;
 	starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
 	fprintf(stderr, "KERNEL 22 %d - k = %u i = %u j = %u\n", rank, info->k, info->i, info->j);
-#else
-	(void)_args;
 #endif
 
 #ifdef STARPU_USE_CUDA
@@ -87,6 +85,7 @@ static inline void STARPU_PLU(common_u22)(void *descr[], int s, void *_args)
 #ifdef VERBOSE_KERNELS
 	fprintf(stderr, "KERNEL 22 %d - k = %u i = %u j = %u done\n", rank, info->k, info->i, info->j);
 #endif
+	free(_args);
 }
 
 static void STARPU_PLU(cpu_u22)(void *descr[], void *_args)
@@ -165,8 +164,6 @@ static inline void STARPU_PLU(common_u12)(void *descr[], int s, void *_args)
 	//fprintf(stderr, "INPUT 12 U12\n");
 	fprintf(stderr, "INPUT 21 U21\n");
 	STARPU_PLU(display_data_content)(sub12, nx12);
-#else
-	(void)_args;
 #endif
 
 #ifdef STARPU_USE_CUDA
@@ -203,6 +200,7 @@ static inline void STARPU_PLU(common_u12)(void *descr[], int s, void *_args)
 	fprintf(stderr, "OUTPUT 21 U21\n");
 	STARPU_PLU(display_data_content)(sub12, nx12);
 #endif
+	free(_args);
 }
 
 static void STARPU_PLU(cpu_u12)(void *descr[], void *_args)
@@ -279,8 +277,6 @@ static inline void STARPU_PLU(common_u21)(void *descr[], int s, void *_args)
 	//fprintf(stderr, "INPUT 21 U21\n");
 	fprintf(stderr, "INPUT 12 U12\n");
 	STARPU_PLU(display_data_content)(sub21, nx21);
-#else
-	(void)_args;
 #endif
 
 #ifdef STARPU_USE_CUDA
@@ -318,6 +314,7 @@ static inline void STARPU_PLU(common_u21)(void *descr[], int s, void *_args)
 	fprintf(stderr, "OUTPUT 12 U12\n");
 	STARPU_PLU(display_data_content)(sub21, nx21);
 #endif
+	free(_args);
 }
 
 static void STARPU_PLU(cpu_u21)(void *descr[], void *_args)
@@ -389,8 +386,6 @@ static inline void STARPU_PLU(common_u11)(void *descr[], int s, void *_args)
 	int rank;
 	starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
 	fprintf(stderr, "KERNEL 11 %d - k = %u\n", rank, info->k);
-#else
-	(void)_args;
 #endif
 
 	switch (s)
@@ -450,6 +445,7 @@ static inline void STARPU_PLU(common_u11)(void *descr[], int s, void *_args)
 #ifdef VERBOSE_KERNELS
 	fprintf(stderr, "KERNEL 11 %d - k = %u\n", rank, info->k);
 #endif
+	free(_args);
 }
 
 static void STARPU_PLU(cpu_u11)(void *descr[], void *_args)