Browse Source

mpi: rewrite applications

Nathalie Furmento 10 years ago
parent
commit
bd64def1aa

+ 42 - 24
mpi/examples/stencil/stencil5.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2011, 2013              Université Bordeaux
- * Copyright (C) 2011, 2012, 2013, 2014  Centre National de la Recherche Scientifique
+ * Copyright (C) 2011, 2012, 2013, 2014, 2015  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
@@ -19,17 +19,22 @@
 #include <math.h>
 
 #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
+#define FPRINTF_MPI(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) { \
+    						int _disp_rank; MPI_Comm_rank(MPI_COMM_WORLD, &_disp_rank);       \
+                                                fprintf(ofile, "[%d][starpu_mpi][%s] " fmt , _disp_rank, __starpu_func__ ,## __VA_ARGS__); \
+                                                fflush(ofile); }} while(0);
 
 void stencil5_cpu(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
 {
-	unsigned *xy = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[0]);
-	unsigned *xm1y = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[1]);
-	unsigned *xp1y = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[2]);
-	unsigned *xym1 = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[3]);
-	unsigned *xyp1 = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[4]);
+	float *xy = (float *)STARPU_VARIABLE_GET_PTR(descr[0]);
+	float *xm1y = (float *)STARPU_VARIABLE_GET_PTR(descr[1]);
+	float *xp1y = (float *)STARPU_VARIABLE_GET_PTR(descr[2]);
+	float *xym1 = (float *)STARPU_VARIABLE_GET_PTR(descr[3]);
+	float *xyp1 = (float *)STARPU_VARIABLE_GET_PTR(descr[4]);
 
-	//FPRINTF(stdout, "VALUES: %d %d %d %d %d\n", *xy, *xm1y, *xp1y, *xym1, *xyp1);
+//	fprintf(stdout, "VALUES: %2.2f %2.2f %2.2f %2.2f %2.2f\n", *xy, *xm1y, *xp1y, *xym1, *xyp1);
 	*xy = (*xy + *xm1y + *xp1y + *xym1 + *xyp1) / 5;
+//	fprintf(stdout, "VALUES: %2.2f %2.2f %2.2f %2.2f %2.2f\n", *xy, *xm1y, *xp1y, *xym1, *xyp1);
 }
 
 struct starpu_codelet stencil5_cl =
@@ -40,9 +45,9 @@ struct starpu_codelet stencil5_cl =
 };
 
 #ifdef STARPU_QUICK_CHECK
-#  define NITER_DEF	5
-#  define X         	3
-#  define Y         	3
+#  define NITER_DEF	100
+#  define X         	5
+#  define Y         	5
 #else
 #  define NITER_DEF	500
 #  define X         	20
@@ -65,7 +70,6 @@ int my_distrib2(int x, int y, int nb_nodes)
 	return (my_distrib(x, y, nb_nodes) + 1) % nb_nodes;
 }
 
-
 static void parse_args(int argc, char **argv)
 {
 	int i;
@@ -86,8 +90,8 @@ static void parse_args(int argc, char **argv)
 int main(int argc, char **argv)
 {
 	int my_rank, size, x, y, loop;
-	int value=0, mean=0;
-	unsigned matrix[X][Y];
+	float mean=0;
+	float matrix[X][Y];
 	starpu_data_handle_t data_handles[X][Y];
 
 	int ret = starpu_init(NULL);
@@ -99,16 +103,30 @@ int main(int argc, char **argv)
 	parse_args(argc, argv);
 
 	/* Initial data values */
+	starpu_srand48((long int)time(NULL));
 	for(x = 0; x < X; x++)
 	{
 		for (y = 0; y < Y; y++)
 		{
-			matrix[x][y] = (my_rank+1)*10 + value;
-			value++;
+			matrix[x][y] = (float)starpu_drand48();
 			mean += matrix[x][y];
 		}
 	}
-	mean /= value;
+	mean /= (X*Y);
+
+	if (display)
+	{
+		FPRINTF_MPI(stdout, "mean=%2.2f\n", mean);
+		for(x = 0; x < X; x++)
+		{
+			fprintf(stdout, "[%d] ", my_rank);
+			for (y = 0; y < Y; y++)
+			{
+				fprintf(stdout, "%2.2f ", matrix[x][y]);
+			}
+			fprintf(stdout, "\n");
+		}
+	}
 
 	/* Initial distribution */
 	for(x = 0; x < X; x++)
@@ -119,14 +137,14 @@ int main(int argc, char **argv)
 			if (mpi_rank == my_rank)
 			{
 				//FPRINTF(stderr, "[%d] Owning data[%d][%d]\n", my_rank, x, y);
-				starpu_variable_data_register(&data_handles[x][y], STARPU_MAIN_RAM, (uintptr_t)&(matrix[x][y]), sizeof(unsigned));
+				starpu_variable_data_register(&data_handles[x][y], 0, (uintptr_t)&(matrix[x][y]), sizeof(float));
 			}
 			else if (my_rank == my_distrib(x+1, y, size) || my_rank == my_distrib(x-1, y, size)
 				 || my_rank == my_distrib(x, y+1, size) || my_rank == my_distrib(x, y-1, size))
 			{
 				/* I don't own that index, but will need it for my computations */
 				//FPRINTF(stderr, "[%d] Neighbour of data[%d][%d]\n", my_rank, x, y);
-				starpu_variable_data_register(&data_handles[x][y], -1, (uintptr_t)NULL, sizeof(unsigned));
+				starpu_variable_data_register(&data_handles[x][y], -1, (uintptr_t)NULL, sizeof(float));
 			}
 			else
 			{
@@ -170,15 +188,15 @@ int main(int argc, char **argv)
 				 || my_rank == my_distrib2(x, y+1, size) || my_rank == my_distrib2(x, y-1, size)))
 			{
 				/* Register newly-needed data */
-				starpu_variable_data_register(&data_handles[x][y], -1, (uintptr_t)NULL, sizeof(unsigned));
+				starpu_variable_data_register(&data_handles[x][y], -1, (uintptr_t)NULL, sizeof(float));
 				starpu_mpi_data_register(data_handles[x][y], (y*X)+x, mpi_rank);
 			}
-			if (data_handles[x][y] && mpi_rank != starpu_data_get_rank(data_handles[x][y]))
+			if (data_handles[x][y] && mpi_rank != starpu_mpi_data_get_rank(data_handles[x][y]))
 			{
 				/* Migrate the data */
 				starpu_mpi_get_data_on_node_detached(MPI_COMM_WORLD, data_handles[x][y], mpi_rank, NULL, NULL);
 				/* And register new rank of the matrix */
-				starpu_data_set_rank(data_handles[x][y], mpi_rank);
+				starpu_mpi_data_set_rank(data_handles[x][y], mpi_rank);
 			}
 		}
 	}
@@ -211,7 +229,7 @@ int main(int argc, char **argv)
 				/* Get back data to original place where the user-provided buffer is. */
 				starpu_mpi_get_data_on_node_detached(MPI_COMM_WORLD, data_handles[x][y], mpi_rank, NULL, NULL);
 				/* Register original rank of the matrix (although useless) */
-				starpu_data_set_rank(data_handles[x][y], mpi_rank);
+				starpu_mpi_data_set_rank(data_handles[x][y], mpi_rank);
 				/* And unregister it */
 				starpu_data_unregister(data_handles[x][y]);
 			}
@@ -223,13 +241,13 @@ int main(int argc, char **argv)
 
 	if (display)
 	{
-		FPRINTF(stdout, "[%d] mean=%d\n", my_rank, mean);
+		FPRINTF(stdout, "[%d] mean=%2.2f\n", my_rank, mean);
 		for(x = 0; x < X; x++)
 		{
 			FPRINTF(stdout, "[%d] ", my_rank);
 			for (y = 0; y < Y; y++)
 			{
-				FPRINTF(stdout, "%3u ", matrix[x][y]);
+				FPRINTF(stdout, "%2.2f ", matrix[x][y]);
 			}
 			FPRINTF(stdout, "\n");
 		}

+ 17 - 5
mpi/tests/insert_task_compute.c

@@ -17,12 +17,15 @@
 #include <starpu_mpi.h>
 #include "helper.h"
 
-void func_cpu(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
+void func_cpu(void *descr[], void *_args)
 {
+	int rank;
 	int *x = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
 	int *y = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
 
-	FPRINTF(stdout, "VALUES: %u %u\n", *x, *y);
+	starpu_codelet_unpack_args(_args, &rank);
+
+	FPRINTF(stdout, "[%d] VALUES: %u %u\n", rank, *x, *y);
 	*x = *x * *y;
 }
 
@@ -58,7 +61,10 @@ int test(int rank, int node, int *before, int *after, int task_insert, int data_
 		x[i] = before[rank*2+i];
 		if (rank <= 1)
 			FPRINTF_MPI(stderr, "before computation x[%d] = %d\n", i, x[i]);
-		starpu_variable_data_register(&data_handles[i], STARPU_MAIN_RAM, (uintptr_t)&x[i], sizeof(int));
+		if (rank == i)
+			starpu_variable_data_register(&data_handles[i], 0, (uintptr_t)&x[i], sizeof(int));
+		else
+			starpu_variable_data_register(&data_handles[i], -1, (uintptr_t)NULL, sizeof(int));
 		starpu_mpi_data_register(data_handles[i], i, i);
 		descrs[i].handle = data_handles[i];
 	}
@@ -76,6 +82,7 @@ int test(int rank, int node, int *before, int *after, int task_insert, int data_
 				{
 					task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet,
 								     STARPU_RW, data_handles[0], STARPU_R, data_handles[1],
+								     STARPU_VALUE, &rank, sizeof(rank),
 								     STARPU_EXECUTE_ON_NODE, node, 0);
 					break;
 				}
@@ -83,6 +90,7 @@ int test(int rank, int node, int *before, int *after, int task_insert, int data_
 				{
 					task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet,
 								     STARPU_DATA_ARRAY, data_handles, 2,
+								     STARPU_VALUE, &rank, sizeof(rank),
 								     STARPU_EXECUTE_ON_NODE, node, 0);
 					break;
 				}
@@ -90,6 +98,7 @@ int test(int rank, int node, int *before, int *after, int task_insert, int data_
 				{
 					task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet,
 								     STARPU_DATA_MODE_ARRAY, descrs, 2,
+								     STARPU_VALUE, &rank, sizeof(rank),
 								     STARPU_EXECUTE_ON_NODE, node, 0);
 					break;
 				}
@@ -137,6 +146,7 @@ int test(int rank, int node, int *before, int *after, int task_insert, int data_
 				{
 					ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
 								     STARPU_RW, data_handles[0], STARPU_R, data_handles[1],
+								     STARPU_VALUE, &rank, sizeof(rank),
 								     STARPU_EXECUTE_ON_NODE, node, 0);
 					break;
 				}
@@ -144,6 +154,7 @@ int test(int rank, int node, int *before, int *after, int task_insert, int data_
 				{
 					ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
 								     STARPU_DATA_ARRAY, data_handles, 2,
+								     STARPU_VALUE, &rank, sizeof(rank),
 								     STARPU_EXECUTE_ON_NODE, node, 0);
 					break;
 				}
@@ -151,6 +162,7 @@ int test(int rank, int node, int *before, int *after, int task_insert, int data_
 				{
 					ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
 								     STARPU_DATA_MODE_ARRAY, descrs, 2,
+								     STARPU_VALUE, &rank, sizeof(rank),
 								     STARPU_EXECUTE_ON_NODE, node, 0);
 					break;
 				}
@@ -165,7 +177,7 @@ int test(int rank, int node, int *before, int *after, int task_insert, int data_
 enodev:
 	for(i=0; i<2; i++)
 	{
-		starpu_data_unregister_no_coherency(data_handles[i]);
+		starpu_data_unregister(data_handles[i]);
 	}
 
 	ok = 1;
@@ -191,7 +203,7 @@ int main(int argc, char **argv)
 	int rank;
 	int ret;
 	int before[4] = {10, 20, 11, 22};
-	int after_node[2][4] = {{220, 22, 11, 22}, {220, 20, 220, 22}};
+	int after_node[2][4] = {{220, 20, 11, 22}, {220, 20, 11, 22}};
 	int node, insert_task, data_array;
 
 	MPI_Init(&argc, &argv);

+ 2 - 2
mpi/tests/insert_task_owner.c

@@ -97,14 +97,14 @@ int main(int argc, char **argv)
 		starpu_mpi_data_register(data_handlesx0, 0, 0);
 	}
 
-	node = starpu_data_get_rank(data_handlesx1);
+	node = starpu_mpi_data_get_rank(data_handlesx1);
 	err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_w,
 				     STARPU_VALUE, &node, sizeof(node),
 				     STARPU_R, data_handlesx0, STARPU_W, data_handlesx1,
 				     0);
 	assert(err == 0);
 
-	node = starpu_data_get_rank(data_handlesx0);
+	node = starpu_mpi_data_get_rank(data_handlesx0);
 	err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_r,
 				     STARPU_VALUE, &node, sizeof(node),
 				     STARPU_RW, data_handlesx0, STARPU_R, data_handlesx1,

+ 74 - 127
mpi/tests/mpi_scatter_gather.c

@@ -18,32 +18,23 @@
 #include "helper.h"
 
 /* Returns the MPI node number where data indexes index is */
-int my_distrib(int x, int y, int nb_nodes)
+int my_distrib(int x, int nb_nodes)
 {
-	return (x+y) % nb_nodes;
+	return x % nb_nodes;
 }
 
 void cpu_codelet(void *descr[], void *_args)
 {
-	float *block;
-	unsigned nx = STARPU_MATRIX_GET_NY(descr[0]);
-	unsigned ld = STARPU_MATRIX_GET_LD(descr[0]);
-	unsigned i,j;
+	int *vector = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
+	unsigned nx = STARPU_VECTOR_GET_NX(descr[0]);
+	unsigned i;
 	int rank;
-	float factor;
 
-	block = (float *)STARPU_MATRIX_GET_PTR(descr[0]);
 	starpu_codelet_unpack_args(_args, &rank);
-	factor = block[0];
-
-	//FPRINTF_MPI(stderr, "rank %d factor %f\n", rank, factor);
-	for (j = 0; j < nx; j++)
+	for (i = 0; i < nx; i++)
 	{
-		for (i = 0; i < nx; i++)
-		{
-			//FPRINTF_MPI(stderr, "rank %d factor %f --> %f %f\n", rank, factor, block[j+i*ld], block[j+i*ld]*factor);
-			block[j+i*ld] *= factor;
-		}
+		//fprintf(stderr,"rank %d v[%d] = %d\n", rank, i, vector[i]);
+		vector[i] *= rank+2;
 	}
 }
 
@@ -68,18 +59,12 @@ void rcallback(void *arg STARPU_ATTRIBUTE_UNUSED)
 
 int main(int argc, char **argv)
 {
-	int rank, nodes;
-	float ***bmat = NULL;
+	int rank, nodes, ret, x;
+	int *vector = NULL;
 	starpu_data_handle_t *data_handles;
+	int size=10;
 
-	unsigned i,j,x,y;
-
-	unsigned nblocks=4;
-	unsigned block_size=2;
-	unsigned size = nblocks*block_size;
-	unsigned ld = size / nblocks;
-
-	int ret = starpu_init(NULL);
+	ret = starpu_init(NULL);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 	ret = starpu_mpi_init(&argc, &argv, 1);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
@@ -88,95 +73,65 @@ int main(int argc, char **argv)
 
 	if (rank == 0)
 	{
-		/* Allocate the matrix */
-		int block_number=10;
-		bmat = malloc(nblocks * sizeof(float *));
-		for(x=0 ; x<nblocks ; x++)
+		/* Allocate the vector */
+		vector = malloc(size * sizeof(int));
+		for(x=0 ; x<size ; x++)
+			vector[x] = x+10;
+
+		// Print vector
+		FPRINTF_MPI(stderr, " Input vector: ");
+		for(x=0 ; x<size ; x++)
 		{
-			bmat[x] = malloc(nblocks * sizeof(float *));
-			for(y=0 ; y<nblocks ; y++)
-			{
-				float value=0.0;
-				starpu_malloc((void **)&bmat[x][y], block_size*block_size*sizeof(float));
-				for (i = 0; i < block_size; i++)
-				{
-					for (j = 0; j < block_size; j++)
-					{
-						bmat[x][y][j +i*block_size] = block_number + value;
-						value++;
-					}
-				}
-				block_number += 10;
-			}
+			FPRINTF(stderr, "%d\t", vector[x]);
 		}
+		FPRINTF(stderr,"\n");
 	}
 
-#if 0
-	// Print matrix
-	if (rank == 0)
+	/* Allocate data handles and register data to StarPU */
+	data_handles = (starpu_data_handle_t *) calloc(size, sizeof(starpu_data_handle_t));
+	for(x = 0; x < size ; x++)
 	{
-		fprintf(stderr, "Input matrix\n");
-		for(x=0 ; x<nblocks ; x++)
+		int mpi_rank = my_distrib(x, nodes);
+		if (rank == 0)
 		{
-			for(y=0 ; y<nblocks ; y++)
-			{
-				for (j = 0; j < block_size; j++)
-				{
-					for (i = 0; i < block_size; i++)
-					{
-						fprintf(stderr, "%2.2f\t", bmat[x][y][j+i*block_size]);
-					}
-					fprintf(stderr,"\n");
-				}
-				fprintf(stderr,"\n");
-			}
+			starpu_vector_data_register(&data_handles[x], 0, (uintptr_t)&vector[x], 1, sizeof(int));
+		}
+		else if ((mpi_rank == rank))
+		{
+			/* I do not own that index but i will need it for my computations */
+			starpu_vector_data_register(&data_handles[x], -1, (uintptr_t)NULL, 1, sizeof(int));
+		}
+		else
+		{
+			/* I know it's useless to allocate anything for this */
+			data_handles[x] = NULL;
+		}
+		if (data_handles[x])
+		{
+			starpu_mpi_data_register(data_handles[x], x, 0);
 		}
 	}
-#endif
 
-	/* Allocate data handles and register data to StarPU */
-	data_handles = malloc(nblocks*nblocks*sizeof(starpu_data_handle_t *));
-	for(x = 0; x < nblocks ; x++)
+	/* Scatter the matrix among the nodes */
+	for(x = 0; x < size ; x++)
 	{
-		for (y = 0; y < nblocks; y++)
+		if (data_handles[x])
 		{
-			int mpi_rank = my_distrib(x, y, nodes);
-			if (rank == 0)
-			{
-				starpu_matrix_data_register(&data_handles[x+y*nblocks], STARPU_MAIN_RAM, (uintptr_t)bmat[x][y],
-							    ld, size/nblocks, size/nblocks, sizeof(float));
-			}
-			else if ((mpi_rank == rank) || ((rank == mpi_rank+1 || rank == mpi_rank-1)))
-			{
-				/* I own that index, or i will need it for my computations */
-				//fprintf(stderr, "[%d] Owning or neighbor of data[%d][%d]\n", rank, x, y);
-				starpu_matrix_data_register(&data_handles[x+y*nblocks], -1, (uintptr_t)NULL,
-							    ld, size/nblocks, size/nblocks, sizeof(float));
-			}
-			else
-			{
-				/* I know it's useless to allocate anything for this */
-				data_handles[x+y*nblocks] = NULL;
-			}
-			if (data_handles[x+y*nblocks])
-			{
-				starpu_mpi_data_register(data_handles[x+y*nblocks], (y*nblocks)+x, mpi_rank);
-			}
+			int mpi_rank = my_distrib(x, nodes);
+			starpu_mpi_data_set_rank(data_handles[x], mpi_rank);
 		}
 	}
-
-	/* Scatter the matrix among the nodes */
-	starpu_mpi_scatter_detached(data_handles, nblocks*nblocks, 0, MPI_COMM_WORLD, scallback, "scatter", NULL, NULL);
+	starpu_mpi_scatter_detached(data_handles, size, 0, MPI_COMM_WORLD, scallback, "scatter", NULL, NULL);
 
 	/* Calculation */
-	for(x = 0; x < nblocks*nblocks ; x++)
+	for(x = 0; x < size ; x++)
 	{
 		if (data_handles[x])
 		{
-			int owner = starpu_data_get_rank(data_handles[x]);
+			int owner = starpu_mpi_data_get_rank(data_handles[x]);
 			if (owner == rank)
 			{
-				//fprintf(stderr,"[%d] Computing on data[%d]\n", rank, x);
+				FPRINTF_MPI(stderr,"Computing on data[%d]\n", x);
 				starpu_task_insert(&cl,
 						   STARPU_VALUE, &rank, sizeof(rank),
 						   STARPU_RW, data_handles[x],
@@ -186,57 +141,49 @@ int main(int argc, char **argv)
 	}
 
 	/* Gather the matrix on main node */
-	starpu_mpi_gather_detached(data_handles, nblocks*nblocks, 0, MPI_COMM_WORLD, scallback, "gather", rcallback, "gather");
-
-	/* Unregister matrix from StarPU */
-	for(x=0 ; x<nblocks*nblocks ; x++)
+	starpu_mpi_gather_detached(data_handles, size, 0, MPI_COMM_WORLD, scallback, "gather", rcallback, "gather");
+	for(x = 0; x < size ; x++)
 	{
 		if (data_handles[x])
 		{
-			starpu_data_unregister(data_handles[x]);
+			starpu_mpi_data_set_rank(data_handles[x], 0);
 		}
 	}
 
-#if 0
-	// Print matrix
-	if (rank == 0)
+	/* Unregister matrix from StarPU */
+	for(x=0 ; x<size ; x++)
 	{
-		fprintf(stderr, "Output matrix\n");
-		for(x=0 ; x<nblocks ; x++)
+		if (data_handles[x])
 		{
-			for(y=0 ; y<nblocks ; y++)
-			{
-				for (j = 0; j < block_size; j++)
-				{
-					for (i = 0; i < block_size; i++)
-					{
-						fprintf(stderr, "%2.2f\t", bmat[x][y][j+i*block_size]);
-					}
-					fprintf(stderr,"\n");
-				}
-				fprintf(stderr,"\n");
-			}
+			starpu_data_unregister(data_handles[x]);
 		}
 	}
-#endif
 
-	// Free memory
-	free(data_handles);
+	// Print vector
 	if (rank == 0)
 	{
-		for(x=0 ; x<nblocks ; x++)
+		FPRINTF_MPI(stderr, "Output vector: ");
+		for(x=0 ; x<size ; x++)
+		{
+			FPRINTF(stderr, "%d\t", vector[x]);
+		}
+		FPRINTF(stderr,"\n");
+		for(x=0 ; x<size ; x++)
 		{
-			for(y=0 ; y<nblocks ; y++)
+			int mpi_rank = my_distrib(x, nodes);
+			if (vector[x] != (x+10) * (mpi_rank+2))
 			{
-				starpu_free((void *)bmat[x][y]);
+				FPRINTF_MPI(stderr, "Incorrect value for vector[%d]. computed %d != expected %d\n", x, vector[x], (x+10) * (mpi_rank+2));
+				ret = 1;
 			}
-			free(bmat[x]);
 		}
-		free(bmat);
+		free(vector);
 	}
 
+	// Free memory
+	free(data_handles);
 
 	starpu_mpi_shutdown();
 	starpu_shutdown();
-	return 0;
+	return (rank == 0) ? ret : 0;
 }

+ 15 - 28
mpi/tests/user_defined_datatype.c

@@ -106,12 +106,12 @@ int main(int argc, char **argv)
 			{
 				for(i=0 ; i<ELEMENTS; i++)
 				{
-					foo[i] = 8.0;
-					real[i][0] = 0.0;
-					real[i][1] = 0.0;
-					imaginary[i][0] = 0.0;
-					imaginary[i][1] = 0.0;
-					values[i] = 7;
+					foo[i] = -1.0;
+					real[i][0] = -1.0;
+					real[i][1] = -1.0;
+					imaginary[i][0] = -1.0;
+					imaginary[i][1] = -1.0;
+					values[i] = -1;
 				}
 			}
 			if (rank == 1)
@@ -137,13 +137,14 @@ int main(int argc, char **argv)
 			f(handle_complex, ELEMENTS, rank, 2*ELEMENTS);
 			f(handle_values, ELEMENTS, rank, 4*ELEMENTS);
 
+			starpu_task_wait_for_all();
+
 			for(i=0 ; i<ELEMENTS ; i++)
 			{
 				starpu_data_unregister(handle_complex[i]);
 				starpu_data_unregister(handle_values[i]);
 				starpu_data_unregister(handle_vars[i]);
 			}
-			starpu_task_wait_for_all();
 
 			if (rank == 0)
 			{
@@ -151,40 +152,26 @@ int main(int argc, char **argv)
 				{
 					int j;
 					compare = (foo[i] == foo_compare);
-					if (compare == 0)
-					{
-						FPRINTF_MPI(stderr, "ERROR. foo[%d] == %f != %f\n", i, foo[i], foo_compare);
-						goto end;
-					}
+					FPRINTF_MPI(stderr, "%s. foo[%d] = %f %s %f\n", compare==0?"ERROR":"SUCCESS", i, foo[i], compare==0?"!=":"==", foo_compare);
+
 					compare = (values[i] == value_compare);
-					if (compare == 0)
-					{
-						FPRINTF_MPI(stderr, "ERROR. value[%d] == %d != %d\n", i, values[i], value_compare);
-						goto end;
-					}
+					FPRINTF_MPI(stderr, "%s. value[%d] = %d %s %d\n", compare==0?"ERROR":"SUCCESS", i, values[i], compare==0?"!=":"==", value_compare);
+
 					for(j=0 ; j<2 ; j++)
 					{
 						compare = (real[i][j] == real_compare[j]);
-						if (compare == 0)
-						{
-							FPRINTF_MPI(stderr, "ERROR. real[%d][%d] == %f != %f\n", i, j, real[i][j], real_compare[j]);
-							goto end;
-						}
+						FPRINTF_MPI(stderr, "%s. real[%d][%d] = %f %s %f\n", compare==0?"ERROR":"SUCCESS", i, j, real[i][j], compare==0?"!=":"==", real_compare[j]);
 					}
 					for(j=0 ; j<2 ; j++)
 					{
 						compare = (imaginary[i][j] == imaginary_compare[j]);
-						if (compare == 0)
-						{
-							FPRINTF_MPI(stderr, "ERROR. imaginary[%d][%d] == %f != %f\n", i, j, imaginary[i][j], imaginary_compare[j]);
-							goto end;
-						}
+						FPRINTF_MPI(stderr, "%s. imaginary[%d][%d] = %f %s %f\n", compare==0?"ERROR":"SUCCESS", i, j, imaginary[i][j], compare==0?"!=":"==", imaginary_compare[j]);
 					}
 				}
 			}
 		}
 	}
-end:
+
 	starpu_mpi_shutdown();
 	starpu_shutdown();
 

+ 1 - 2
mpi/tests/user_defined_datatype_value.h

@@ -76,8 +76,7 @@ static size_t value_get_size(starpu_data_handle_t handle)
 
 static uint32_t value_footprint(starpu_data_handle_t handle)
 {
-	int *x = starpu_value_get(handle);
-	return starpu_hash_crc32c_be(*x, 0);
+	return starpu_hash_crc32c_be(value_get_size(handle), 0);
 }
 
 static void *value_handle_to_pointer(starpu_data_handle_t handle, unsigned node)