Browse Source

mpi/examples: update coding style

Nathalie Furmento 13 years ago
parent
commit
92faaeadee

+ 46 - 23
mpi/examples/cholesky/mpi_cholesky.c

@@ -58,7 +58,8 @@ static struct starpu_codelet cl22 =
 };
 
 /* 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 y, int nb_nodes)
+{
         return (x+y) % nb_nodes;
 }
 
@@ -79,16 +80,20 @@ static void dw_cholesky(float ***matA, unsigned size, unsigned ld, unsigned nblo
         data_handles = malloc(nblocks*sizeof(starpu_data_handle_t *));
         for(x=0 ; x<nblocks ; x++) data_handles[x] = malloc(nblocks*sizeof(starpu_data_handle_t));
 
-        for(x = 0; x < nblocks ;  x++) {
-                for (y = 0; y < nblocks; y++) {
+        for(x = 0; x < nblocks ;  x++)
+	{
+                for (y = 0; y < nblocks; y++)
+		{
                         int mpi_rank = my_distrib(x, y, nodes);
-                        if (mpi_rank == rank) {
+                        if (mpi_rank == rank)
+			{
                                 //fprintf(stderr, "[%d] Owning data[%d][%d]\n", rank, x, y);
                                 starpu_matrix_data_register(&data_handles[x][y], 0, (uintptr_t)matA[x][y],
                                                             ld, size/nblocks, size/nblocks, sizeof(float));
                         }
 			/* TODO: make better test to only registering what is needed */
-                        else {
+                        else
+			{
                                 /* I don't own that index, but will need it for my computations */
                                 //fprintf(stderr, "[%d] Neighbour of data[%d][%d]\n", rank, x, y);
                                 starpu_matrix_data_register(&data_handles[x][y], -1, (uintptr_t)NULL,
@@ -144,8 +149,10 @@ static void dw_cholesky(float ***matA, unsigned size, unsigned ld, unsigned nblo
 
         starpu_task_wait_for_all();
 
-        for(x = 0; x < nblocks ;  x++) {
-                for (y = 0; y < nblocks; y++) {
+        for(x = 0; x < nblocks ;  x++)
+	{
+                for (y = 0; y < nblocks; y++)
+		{
                         if (data_handles[x][y])
                                 starpu_data_unregister(data_handles[x][y]);
                 }
@@ -209,7 +216,8 @@ int main(int argc, char **argv)
 	}
 
 
-        if (display) {
+        if (display)
+	{
                 printf("[%d] Input :\n", rank);
 
 		for(y=0 ; y<nblocks ; y++)
@@ -221,10 +229,12 @@ int main(int argc, char **argv)
 				{
 					for (i = 0; i < BLOCKSIZE; i++)
 					{
-						if (i <= j) {
+						if (i <= j)
+						{
 							printf("%2.2f\t", bmat[y][x][j +i*BLOCKSIZE]);
 						}
-						else {
+						else
+						{
 							printf(".\t");
 						}
 					}
@@ -238,7 +248,8 @@ int main(int argc, char **argv)
 
 	starpu_mpi_shutdown();
 
-        if (display) {
+        if (display)
+	{
                 printf("[%d] Results :\n", rank);
 		for(y=0 ; y<nblocks ; y++)
 		{
@@ -249,10 +260,12 @@ int main(int argc, char **argv)
 				{
 					for (i = 0; i < BLOCKSIZE; i++)
 					{
-						if (i <= j) {
+						if (i <= j)
+						{
 							printf("%2.2f\t", bmat[y][x][j +i*BLOCKSIZE]);
 						}
-						else {
+						else
+						{
 							printf(".\t");
 						}
 					}
@@ -263,10 +276,14 @@ int main(int argc, char **argv)
 	}
 
 	float *rmat = malloc(size*size*sizeof(float));
-        for(x=0 ; x<nblocks ; x++) {
-                for(y=0 ; y<nblocks ; y++) {
-                        for (i = 0; i < BLOCKSIZE; i++) {
-                                for (j = 0; j < BLOCKSIZE; j++) {
+        for(x=0 ; x<nblocks ; x++)
+	{
+                for(y=0 ; y<nblocks ; y++)
+		{
+                        for (i = 0; i < BLOCKSIZE; i++)
+			{
+                                for (j = 0; j < BLOCKSIZE; j++)
+				{
                                         rmat[j+(y*BLOCKSIZE)+(i+(x*BLOCKSIZE))*size] = bmat[x][y][j +i*BLOCKSIZE];
                                 }
                         }
@@ -278,7 +295,8 @@ int main(int argc, char **argv)
 	{
 		for (i = 0; i < size; i++)
 		{
-			if (i > j) {
+			if (i > j)
+			{
 				rmat[j+i*size] = 0.0f; // debug
 			}
 		}
@@ -290,15 +308,18 @@ int main(int argc, char **argv)
 				rmat, size, 0.0f, test_mat, size);
 
 	fprintf(stderr, "[%d] comparing results ...\n", rank);
-        if (display) {
+        if (display)
+	{
                 for (j = 0; j < size; j++)
 		{
                         for (i = 0; i < size; i++)
 			{
-                                if (i <= j) {
+                                if (i <= j)
+				{
                                         printf("%2.2f\t", test_mat[j +i*size]);
                                 }
-                                else {
+                                else
+				{
                                         printf(".\t");
                                 }
                         }
@@ -312,7 +333,8 @@ int main(int argc, char **argv)
                 for (y = 0; y < nblocks; y++)
 		{
                         int mpi_rank = my_distrib(x, y, nodes);
-                        if (mpi_rank == rank) {
+                        if (mpi_rank == rank)
+			{
                                 for (i = (size/nblocks)*x ; i < (size/nblocks)*x+(size/nblocks); i++)
                                 {
                                         for (j = (size/nblocks)*y ; j < (size/nblocks)*y+(size/nblocks); j++)
@@ -321,7 +343,8 @@ int main(int argc, char **argv)
                                                 {
                                                         float orig = (1.0f/(1.0f+i+j)) + ((i == j)?1.0f*size:0.0f);
                                                         float err = abs(test_mat[j +i*size] - orig);
-                                                        if (err > 0.00001) {
+                                                        if (err > 0.00001)
+							{
                                                                 fprintf(stderr, "[%d] Error[%d, %d] --> %2.2f != %2.2f (err %2.2f)\n", rank, i, j, test_mat[j +i*size], orig, err);
 								correctness = 0;
 								break;

+ 14 - 7
mpi/examples/cholesky/mpi_cholesky.h

@@ -51,31 +51,38 @@ void chol_cublas_codelet_update_u22(void *descr[], void *_args);
 static void __attribute__((unused)) parse_args(int argc, char **argv)
 {
 	int i;
-	for (i = 1; i < argc; i++) {
-		if (strcmp(argv[i], "-size") == 0) {
+	for (i = 1; i < argc; i++)
+	{
+		if (strcmp(argv[i], "-size") == 0)
+		{
 		        char *argptr;
 			size = strtol(argv[++i], &argptr, 10);
 		}
 
-		if (strcmp(argv[i], "-nblocks") == 0) {
+		if (strcmp(argv[i], "-nblocks") == 0)
+		{
 		        char *argptr;
 			nblocks = strtol(argv[++i], &argptr, 10);
 		}
 
-		if (strcmp(argv[i], "-nbigblocks") == 0) {
+		if (strcmp(argv[i], "-nbigblocks") == 0)
+		{
 		        char *argptr;
 			nbigblocks = strtol(argv[++i], &argptr, 10);
 		}
 
-		if (strcmp(argv[i], "-no-prio") == 0) {
+		if (strcmp(argv[i], "-no-prio") == 0)
+		{
 			noprio = 1;
 		}
 
-		if (strcmp(argv[i], "-display") == 0) {
+		if (strcmp(argv[i], "-display") == 0)
+		{
 			display = 1;
 		}
 
-		if (strcmp(argv[i], "-h") == 0) {
+		if (strcmp(argv[i], "-h") == 0)
+		{
 			printf("usage : %s [-display] [-size size] [-nblocks nblocks]\n", argv[0]);
 		}
 	}

+ 18 - 9
mpi/examples/cholesky/mpi_cholesky_distributed.c

@@ -58,7 +58,8 @@ static struct starpu_codelet cl22 =
 };
 
 /* 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 y, int nb_nodes)
+{
         return (x+y) % nb_nodes;
 }
 
@@ -82,16 +83,20 @@ static void dw_cholesky(float ***matA, unsigned size, unsigned ld, unsigned nblo
 	starpu_mpi_barrier(MPI_COMM_WORLD);
 	gettimeofday(&start, NULL);
 
-        for(x = 0; x < nblocks ;  x++) {
-                for (y = 0; y < nblocks; y++) {
+        for(x = 0; x < nblocks ;  x++)
+	{
+                for (y = 0; y < nblocks; y++)
+		{
                         int mpi_rank = my_distrib(x, y, nodes);
-                        if (mpi_rank == rank) {
+                        if (mpi_rank == rank)
+			{
                                 //fprintf(stderr, "[%d] Owning data[%d][%d]\n", rank, x, y);
                                 starpu_matrix_data_register(&data_handles[x][y], 0, (uintptr_t)matA[x][y],
                                                             ld, size/nblocks, size/nblocks, sizeof(float));
                         }
 			/* TODO: make better test to only registering what is needed */
-                        else {
+                        else
+			{
                                 /* I don't own that index, but will need it for my computations */
                                 //fprintf(stderr, "[%d] Neighbour of data[%d][%d]\n", rank, x, y);
                                 starpu_matrix_data_register(&data_handles[x][y], -1, (uintptr_t)NULL,
@@ -144,8 +149,10 @@ static void dw_cholesky(float ***matA, unsigned size, unsigned ld, unsigned nblo
 
         starpu_task_wait_for_all();
 
-        for(x = 0; x < nblocks ;  x++) {
-                for (y = 0; y < nblocks; y++) {
+        for(x = 0; x < nblocks ;  x++)
+	{
+                for (y = 0; y < nblocks; y++)
+		{
                         if (data_handles[x][y])
                                 starpu_data_unregister(data_handles[x][y]);
                 }
@@ -197,7 +204,8 @@ int main(int argc, char **argv)
                 for(y=0 ; y<nblocks ; y++)
 		{
                         int mpi_rank = my_distrib(x, y, nodes);
-                        if (mpi_rank == rank) {
+                        if (mpi_rank == rank)
+			{
 				starpu_malloc((void **)&bmat[x][y], BLOCKSIZE*BLOCKSIZE*sizeof(float));
 				for (i = 0; i < BLOCKSIZE; i++)
 				{
@@ -220,7 +228,8 @@ int main(int argc, char **argv)
                 for(y=0 ; y<nblocks ; y++)
 		{
                         int mpi_rank = my_distrib(x, y, nodes);
-                        if (mpi_rank == rank) {
+                        if (mpi_rank == rank)
+			{
 				starpu_free((void *)bmat[x][y]);
 			}
 		}

+ 21 - 17
mpi/examples/cholesky/mpi_cholesky_kernels.c

@@ -29,7 +29,7 @@
 #endif
 
 /*
- *   U22 
+ *   U22
  */
 
 static inline void chol_common_cpu_codelet_update_u22(void *descr[], int s, __attribute__((unused)) void *_args)
@@ -51,15 +51,16 @@ static inline void chol_common_cpu_codelet_update_u22(void *descr[], int s, __at
 	cublasStatus st;
 #endif
 
-	switch (s) {
+	switch (s)
+	{
 		case 0:
-			SGEMM("N", "T", dy, dx, dz, -1.0f, left, ld21, 
+			SGEMM("N", "T", dy, dx, dz, -1.0f, left, ld21,
 				right, ld12, 1.0f, center, ld22);
 			break;
 #ifdef STARPU_USE_CUDA
 		case 1:
-			cublasSgemm('n', 't', dy, dx, dz, 
-					-1.0f, left, ld21, right, ld12, 
+			cublasSgemm('n', 't', dy, dx, dz,
+					-1.0f, left, ld21, right, ld12,
 					 1.0f, center, ld22);
 			st = cublasGetError();
 			STARPU_ASSERT(!st);
@@ -86,7 +87,7 @@ void chol_cublas_codelet_update_u22(void *descr[], void *_args)
 }
 #endif// STARPU_USE_CUDA
 
-/* 
+/*
  * U21
  */
 
@@ -105,7 +106,8 @@ static inline void chol_common_codelet_update_u21(void *descr[], int s, __attrib
 	unsigned nx21 = STARPU_MATRIX_GET_NY(descr[1]);
 	unsigned ny21 = STARPU_MATRIX_GET_NX(descr[1]);
 
-	switch (s) {
+	switch (s)
+	{
 		case 0:
 			STRSM("R", "L", "T", "N", nx21, ny21, 1.0f, sub11, ld11, sub21, ld21);
 			break;
@@ -131,25 +133,26 @@ void chol_cublas_codelet_update_u21(void *descr[], void *_args)
 {
 	chol_common_codelet_update_u21(descr, 1, _args);
 }
-#endif 
+#endif
 
 /*
  *	U11
  */
 
-static inline void chol_common_codelet_update_u11(void *descr[], int s, __attribute__((unused)) void *_args) 
+static inline void chol_common_codelet_update_u11(void *descr[], int s, __attribute__((unused)) void *_args)
 {
 //	printf("11\n");
 	float *sub11;
 
-	sub11 = (float *)STARPU_MATRIX_GET_PTR(descr[0]); 
+	sub11 = (float *)STARPU_MATRIX_GET_PTR(descr[0]);
 
 	unsigned nx = STARPU_MATRIX_GET_NY(descr[0]);
 	unsigned ld = STARPU_MATRIX_GET_LD(descr[0]);
 
 	unsigned z;
 
-	switch (s) {
+	switch (s)
+	{
 		case 0:
 
 			/*
@@ -165,10 +168,10 @@ static inline void chol_common_codelet_update_u11(void *descr[], int s, __attrib
 				sub11[z+z*ld] = lambda11;
 
 				STARPU_ASSERT(lambda11 != 0.0f);
-		
+
 				SSCAL(nx - z - 1, 1.0f/lambda11, &sub11[(z+1)+z*ld], 1);
-		
-				SSYR("L", nx - z - 1, -1.0f, 
+
+				SSYR("L", nx - z - 1, -1.0f,
 							&sub11[(z+1)+z*ld], 1,
 							&sub11[(z+1)+(z+1)*ld], ld);
 			}
@@ -180,7 +183,8 @@ static inline void chol_common_codelet_update_u11(void *descr[], int s, __attrib
 				int ret;
 				int info;
 				ret = magma_spotrf_gpu('L', nx, sub11, ld, &info);
-				if (ret != MAGMA_SUCCESS) {
+				if (ret != MAGMA_SUCCESS)
+				{
 					fprintf(stderr, "Error in Magma: %d\n", ret);
 					STARPU_ABORT();
 				}
@@ -195,7 +199,7 @@ static inline void chol_common_codelet_update_u11(void *descr[], int s, __attrib
 				cudaStreamSynchronize(0);
 
 				STARPU_ASSERT(lambda11 != 0.0f);
-				
+
 				lambda11 = sqrt(lambda11);
 
 				cublasSetVector(1, sizeof(float), &lambda11, sizeof(float), &sub11[z+z*ld], sizeof(float));
@@ -206,7 +210,7 @@ static inline void chol_common_codelet_update_u11(void *descr[], int s, __attrib
 							&sub11[(z+1)+z*ld], 1,
 							&sub11[(z+1)+(z+1)*ld], ld);
 			}
-		
+
 			cudaThreadSynchronize();
 #endif
 			break;

+ 7 - 4
mpi/examples/cholesky/mpi_cholesky_models.c

@@ -18,20 +18,23 @@
 #include "mpi_cholesky_models.h"
 
 /*
- *	Number of flops of Gemm 
+ *	Number of flops of Gemm
  */
 
-struct starpu_perfmodel chol_model_11 = {
+struct starpu_perfmodel chol_model_11 =
+{
 	.type = STARPU_HISTORY_BASED,
 	.symbol = "chol_model_11"
 };
 
-struct starpu_perfmodel chol_model_21 = {
+struct starpu_perfmodel chol_model_21 =
+{
 	.type = STARPU_HISTORY_BASED,
 	.symbol = "chol_model_21"
 };
 
-struct starpu_perfmodel chol_model_22 = {
+struct starpu_perfmodel chol_model_22 =
+{
 	.type = STARPU_HISTORY_BASED,
 	.symbol = "chol_model_22"
 };

+ 2 - 1
mpi/examples/scatter_gather/mpi_scatter_gather.c

@@ -17,7 +17,8 @@
 #include <starpu_mpi.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 y, int nb_nodes)
+{
         return (x+y) % nb_nodes;
 }
 

+ 36 - 18
mpi/examples/stencil/stencil5.c

@@ -29,7 +29,8 @@ void stencil5_cpu(void *descr[], __attribute__ ((unused)) void *_args)
         *xy = (*xy + *xm1y + *xp1y + *xym1 + *xyp1) / 5;
 }
 
-struct starpu_codelet stencil5_cl = {
+struct starpu_codelet stencil5_cl =
+{
 	.where = STARPU_CPU,
 	.cpu_func = stencil5_cpu,
         .nbuffers = 5
@@ -43,7 +44,8 @@ int display = 0;
 int niter = NITER_DEF;
 
 /* 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 y, int nb_nodes)
+{
 	/* Block distrib */
 	return ((int)(x / sqrt(nb_nodes) + (y / sqrt(nb_nodes)) * sqrt(nb_nodes))) % nb_nodes;
 }
@@ -52,12 +54,15 @@ int my_distrib(int x, int y, int nb_nodes) {
 static void parse_args(int argc, char **argv)
 {
 	int i;
-	for (i = 1; i < argc; i++) {
-		if (strcmp(argv[i], "-iter") == 0) {
+	for (i = 1; i < argc; i++)
+	{
+		if (strcmp(argv[i], "-iter") == 0)
+		{
 			char *argptr;
 			niter = strtol(argv[++i], &argptr, 10);
 		}
-		if (strcmp(argv[i], "-display") == 0) {
+		if (strcmp(argv[i], "-display") == 0)
+		{
 			display = 1;
 		}
 	}
@@ -74,8 +79,10 @@ int main(int argc, char **argv)
 	starpu_mpi_initialize_extended(&my_rank, &size);
         parse_args(argc, argv);
 
-        for(x = 0; x < X; x++) {
-                for (y = 0; y < Y; y++) {
+        for(x = 0; x < X; x++)
+	{
+                for (y = 0; y < Y; y++)
+		{
                         matrix[x][y] = (my_rank+1)*10 + value;
                         value++;
                         mean += matrix[x][y];
@@ -83,20 +90,25 @@ int main(int argc, char **argv)
         }
         mean /= value;
 
-        for(x = 0; x < X; x++) {
-                for (y = 0; y < Y; y++) {
+        for(x = 0; x < X; x++)
+	{
+                for (y = 0; y < Y; y++)
+		{
                         int mpi_rank = my_distrib(x, y, size);
-                        if (mpi_rank == my_rank) {
+                        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], 0, (uintptr_t)&(matrix[x][y]), sizeof(unsigned));
                         }
 			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)) {
+			      || 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));
                         }
-                        else {
+                        else
+			{
                                 /* I know it's useless to allocate anything for this */
                                 data_handles[x][y] = NULL;
                         }
@@ -108,9 +120,12 @@ int main(int argc, char **argv)
                 }
         }
 
-        for(loop=0 ; loop<niter; loop++) {
-                for (x = 1; x < X-1; x++) {
-                        for (y = 1; y < Y-1; y++) {
+        for(loop=0 ; loop<niter; loop++)
+	{
+                for (x = 1; x < X-1; x++)
+		{
+                        for (y = 1; y < Y-1; y++)
+			{
                                 starpu_mpi_insert_task(MPI_COMM_WORLD, &stencil5_cl, STARPU_RW, data_handles[x][y],
                                                        STARPU_R, data_handles[x-1][y], STARPU_R, data_handles[x+1][y],
                                                        STARPU_R, data_handles[x][y-1], STARPU_R, data_handles[x][y+1],
@@ -124,11 +139,14 @@ int main(int argc, char **argv)
 	starpu_mpi_shutdown();
 	starpu_shutdown();
 
-        if (display) {
+        if (display)
+	{
                 fprintf(stdout, "[%d] mean=%d\n", my_rank, mean);
-                for(x = 0; x < X; x++) {
+                for(x = 0; x < X; x++)
+		{
                         fprintf(stdout, "[%d] ", my_rank);
-                        for (y = 0; y < Y; y++) {
+                        for (y = 0; y < Y; y++)
+			{
                                 fprintf(stdout, "%3d ", matrix[x][y]);
                         }
                         fprintf(stdout, "\n");