瀏覽代碼

complex data interface: the comparison codelet returns the result to the caller

Nathalie Furmento 12 年之前
父節點
當前提交
96b1403508
共有 3 個文件被更改,包括 37 次插入23 次删除
  1. 26 17
      examples/interface/complex.c
  2. 6 4
      examples/interface/complex_codelet.h
  3. 5 2
      mpi/examples/complex/mpi_complex.c

+ 26 - 17
examples/interface/complex.c

@@ -18,6 +18,8 @@
 #include "complex_interface.h"
 #include "complex_codelet.h"
 
+#define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
+
 static int can_execute(unsigned workerid, struct starpu_task *task, unsigned nimpl)
 {
        if (starpu_worker_get_type(workerid) == STARPU_OPENCL_WORKER)
@@ -75,6 +77,9 @@ int main(int argc, char **argv)
 	double copy_real = 78.0;
 	double copy_imaginary = 78.0;
 
+	int compare;
+	int *compare_ptr = &compare;
+
 	ret = starpu_init(NULL);
 	if (ret == -ENODEV) return 77;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
@@ -88,54 +93,58 @@ int main(int argc, char **argv)
 	starpu_complex_data_register(&handle2, 0, &copy_real, &copy_imaginary, 1);
 
 	ret = starpu_insert_task(&cl_display, STARPU_R, handle1, 0);
-	if (ret == -ENODEV) goto enodev;
+	if (ret == -ENODEV) goto end;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
 
 	ret = starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
-	if (ret == -ENODEV) goto enodev;
+	if (ret == -ENODEV) goto end;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
 
 	ret = starpu_insert_task(&cl_compare,
 				 STARPU_R, handle1,
 				 STARPU_R, handle2,
+				 STARPU_VALUE, &compare_ptr, sizeof(compare_ptr),
 				 0);
-	if (ret == -ENODEV) goto enodev;
+	if (ret == -ENODEV) goto end;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
+	starpu_task_wait_for_all();
+	if (compare != 0)
+	{
+	     FPRINTF(stderr, "Complex numbers should NOT be similar\n");
+	     goto end;
+	}
 
 	ret = starpu_insert_task(&cl_copy,
 				 STARPU_R, handle1,
 				 STARPU_W, handle2,
 				 0);
-	if (ret == -ENODEV) goto enodev;
+	if (ret == -ENODEV) goto end;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
 
 	ret = starpu_insert_task(&cl_display, STARPU_R, handle1, 0);
-	if (ret == -ENODEV) goto enodev;
+	if (ret == -ENODEV) goto end;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
 
 	ret = starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
-	if (ret == -ENODEV) goto enodev;
+	if (ret == -ENODEV) goto end;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
 
 	ret = starpu_insert_task(&cl_compare,
 				 STARPU_R, handle1,
 				 STARPU_R, handle2,
+				 STARPU_VALUE, &compare_ptr, sizeof(compare_ptr),
 				 0);
-	if (ret == -ENODEV) goto enodev;
+	if (ret == -ENODEV) goto end;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
 
-#warning get the comparison result and return it as the application return code
-
 	starpu_task_wait_for_all();
 
-#ifdef STARPU_USE_OPENCL
-        ret = starpu_opencl_unload_opencl(&opencl_program);
-        STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
-#endif
-	starpu_shutdown();
-	return 0;
+	if (compare != 1)
+	{
+	     FPRINTF(stderr, "Complex numbers should be similar\n");
+	}
 
-enodev:
+end:
 #ifdef STARPU_USE_OPENCL
         ret = starpu_opencl_unload_opencl(&opencl_program);
         STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
@@ -143,5 +152,5 @@ enodev:
 	starpu_data_unregister(handle1);
 	starpu_data_unregister(handle2);
 	starpu_shutdown();
-	return 77;
+	if (ret == -ENODEV) return 77; else return !compare;
 }

+ 6 - 4
examples/interface/complex_codelet.h

@@ -20,7 +20,7 @@
 #ifndef __COMPLEX_CODELET_H
 #define __COMPLEX_CODELET_H
 
-void compare_complex_codelet(void *descr[], __attribute__ ((unused)) void *_args)
+void compare_complex_codelet(void *descr[], void *_args)
 {
 	int nx1 = STARPU_COMPLEX_GET_NX(descr[0]);
 	double *real1 = STARPU_COMPLEX_GET_REAL(descr[0]);
@@ -30,7 +30,10 @@ void compare_complex_codelet(void *descr[], __attribute__ ((unused)) void *_args
 	double *real2 = STARPU_COMPLEX_GET_REAL(descr[1]);
 	double *imaginary2 = STARPU_COMPLEX_GET_IMAGINARY(descr[1]);
 
-	int compare = (nx1 == nx2);
+	int *compare;
+
+	starpu_codelet_unpack_args(_args, &compare);
+	*compare = (nx1 == nx2);
 	if (nx1 == nx2)
 	{
 		int i;
@@ -38,12 +41,11 @@ void compare_complex_codelet(void *descr[], __attribute__ ((unused)) void *_args
 		{
 			if (real1[i] != real2[i] || imaginary1[i] != imaginary2[i])
 			{
-				compare = 0;
+				*compare = 0;
 				break;
 			}
 		}
 	}
-	fprintf(stderr, "Complex numbers are%s similar\n", compare==0 ? " NOT" : "");
 }
 
 struct starpu_codelet cl_compare =

+ 5 - 2
mpi/examples/complex/mpi_complex.c

@@ -22,6 +22,7 @@ int main(int argc, char **argv)
 {
 	int rank, nodes;
 	int ret;
+	int compare;
 
 	ret = starpu_init(NULL);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
@@ -52,6 +53,8 @@ int main(int argc, char **argv)
 			int foo=12;
 			starpu_data_handle_t foo_handle;
 
+			int *compare_ptr = &compare;
+
 			starpu_complex_data_register(&handle, 0, real, imaginary, 2);
 			starpu_insert_task(&cl_display, STARPU_R, handle, 0);
 			starpu_mpi_send(handle, 1, 10, MPI_COMM_WORLD);
@@ -62,7 +65,7 @@ int main(int argc, char **argv)
 			starpu_complex_data_register(&handle2, -1, real2, imaginary2, 2);
 			starpu_mpi_recv(handle2, 1, 11, MPI_COMM_WORLD, &status);
 			starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
-			starpu_insert_task(&cl_compare, STARPU_R, handle, STARPU_R, handle2, 0);
+			starpu_insert_task(&cl_compare, STARPU_R, handle, STARPU_R, handle2, STARPU_VALUE, &compare_ptr, sizeof(compare_ptr), 0);
 		}
 		else if (rank == 1)
 		{
@@ -90,5 +93,5 @@ int main(int argc, char **argv)
 	starpu_mpi_shutdown();
 	starpu_shutdown();
 
-	return ret;
+	if (rank == 0) return !compare; else return ret;
 }