瀏覽代碼

mpi/examples/matrix_decomposition/: reorganise code

Nathalie Furmento 12 年之前
父節點
當前提交
434bc7e402

+ 2 - 18
mpi/examples/matrix_decomposition/mpi_cholesky.c

@@ -63,8 +63,7 @@ int main(int argc, char **argv)
 
 	float ***bmat;
 	int rank, nodes, ret;
-
-	parse_args(argc, argv);
+	unsigned i,j,x,y;
 
 	ret = starpu_init(NULL);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
@@ -75,23 +74,8 @@ int main(int argc, char **argv)
 	MPI_Comm_size(MPI_COMM_WORLD, &nodes);
 	starpu_helper_cublas_init();
 
-	if (dblockx == -1 || dblocky == -1)
-	{
-		int factor;
-		dblockx = nodes;
-		dblocky = 1;
-		for(factor=sqrt(nodes) ; factor>1 ; factor--)
-		{
-			if (nodes % factor == 0)
-			{
-				dblockx = nodes/factor;
-				dblocky = factor;
-				break;
-			}
-		}
-	}
+	parse_args(argc, argv, nodes);
 
-	unsigned i,j,x,y;
 	bmat = malloc(nblocks * sizeof(float *));
 	for(x=0 ; x<nblocks ; x++)
 	{

+ 2 - 18
mpi/examples/matrix_decomposition/mpi_cholesky_distributed.c

@@ -30,8 +30,7 @@ int main(int argc, char **argv)
 
 	float ***bmat;
 	int rank, nodes, ret;
-
-	parse_args(argc, argv);
+	unsigned i,j,x,y;
 
 	ret = starpu_init(NULL);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
@@ -42,23 +41,8 @@ int main(int argc, char **argv)
 	MPI_Comm_size(MPI_COMM_WORLD, &nodes);
 	starpu_helper_cublas_init();
 
-	if (dblockx == -1 || dblocky == -1)
-	{
-		int factor;
-		dblockx = nodes;
-		dblocky = 1;
-		for(factor=sqrt(nodes) ; factor>1 ; factor--)
-		{
-			if (nodes % factor == 0)
-			{
-				dblockx = nodes/factor;
-				dblocky = factor;
-				break;
-			}
-		}
-	}
+	parse_args(argc, argv, nodes);
 
-	unsigned i,j,x,y;
 	bmat = malloc(nblocks * sizeof(float *));
 	for(x=0 ; x<nblocks ; x++)
 	{

+ 19 - 1
mpi/examples/matrix_decomposition/mpi_cholesky_params.c

@@ -18,6 +18,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <math.h>
 
 unsigned size = 4*1024;
 unsigned nblocks = 16;
@@ -27,7 +28,7 @@ unsigned display = 0;
 unsigned dblockx = -1;
 unsigned dblocky = -1;
 
-void parse_args(int argc, char **argv)
+void parse_args(int argc, char **argv, int nodes)
 {
         int i;
         for (i = 1; i < argc; i++)
@@ -77,6 +78,23 @@ void parse_args(int argc, char **argv)
                         printf("usage : %s [-display] [-size size] [-nblocks nblocks]\n", argv[0]);
                 }
         }
+
         if (nblocks > size) nblocks = size;
+
+	if (dblockx == -1 || dblocky == -1)
+	{
+		int factor;
+		dblockx = nodes;
+		dblocky = 1;
+		for(factor=sqrt(nodes) ; factor>1 ; factor--)
+		{
+			if (nodes % factor == 0)
+			{
+				dblockx = nodes/factor;
+				dblocky = factor;
+				break;
+			}
+		}
+	}
 }
 

+ 1 - 1
mpi/examples/matrix_decomposition/mpi_cholesky_params.h

@@ -28,7 +28,7 @@ extern unsigned display;
 extern unsigned dblockx;
 extern unsigned dblocky;
 
-void parse_args(int argc, char **argv);
+void parse_args(int argc, char **argv, int nodes);
 
 #endif // __MPI_CHOLESKY_PARAMS_H__