Browse Source

tests/datawizard/commute2.c: clean code

Nathalie Furmento 10 years ago
parent
commit
554da4c51e
1 changed files with 20 additions and 22 deletions
  1. 20 22
      tests/datawizard/commute2.c

+ 20 - 22
tests/datawizard/commute2.c

@@ -15,13 +15,12 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
 
+#include <config.h>
 #include <starpu.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
-#ifdef STARPU_USE_CUDA
-#include <starpu_cuda.h>
-#endif
+#include "../helper.h"
 #include "../helper.h"
 
 static unsigned cnt;
@@ -42,36 +41,37 @@ static void cpu_memcpy(void *descr[], void *cl_arg)
 		STARPU_ASSERT(STARPU_ATOMIC_ADD(&cnt,1) != 1);
 }
 
-
-static struct starpu_codelet my_cl = {
+static struct starpu_codelet my_cl =
+{
 	.where =  STARPU_CPU,
-	.cpu_funcs = {cpu_memcpy, NULL}, 
+	.cpu_funcs = {cpu_memcpy, NULL},
 	.nbuffers = STARPU_VARIABLE_NBUFFERS
 };
 
-int 
-main()
+int main()
 {
 	double *res, *a;
 	unsigned n=100000, i;
 	starpu_data_handle_t res_handle, a_handle;
 	unsigned nb_tasks = 10, worker;
+	int ret;
 
-	if (starpu_init(NULL)) 
-		exit(EXIT_FAILURE);
+	ret = starpu_init(NULL);
+	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
 	starpu_malloc((void**)&res, n*sizeof(double));
 	starpu_malloc((void**)&a,   n*sizeof(double));
 
 	for(i=0; i < n; i++)
 		res[i] = a[i] = 1.0;
-		
+
 	starpu_vector_data_register(&res_handle, 0, (uintptr_t)res, (uint32_t)n, sizeof(double));
 	starpu_vector_data_register(&a_handle,   0, (uintptr_t)a,   (uint32_t)n, sizeof(double));
 
 	starpu_data_acquire(a_handle, STARPU_RW);
-
-	for (i = 0; i < nb_tasks; i++) {
+	for (i = 0; i < nb_tasks; i++)
+	{
 		struct starpu_task *task = starpu_task_create();
 		task->cl=&my_cl;
 		task->nbuffers = i == 0 ? 2 : 1;
@@ -81,15 +81,14 @@ main()
 			task->modes[0]   = STARPU_RW;
 		else
 			task->modes[0]   = STARPU_RW | STARPU_COMMUTE;
-		
+
 		task->handles[1] = a_handle;
 		task->modes[1]   = STARPU_R;
 		task->cl_arg = (void*)(uintptr_t)i;
-		
-		if (starpu_task_submit(task)) {
-			fprintf(stderr,"taks submmition failed!");
-			exit(EXIT_FAILURE);
-		}
+
+		ret = starpu_task_submit(task);
+		if (ret == -ENODEV) goto enodev;
+		STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
 	}
 
 	/* let commute tasks potentially happen */
@@ -98,6 +97,7 @@ main()
 
 	starpu_task_wait_for_all ();
 
+enodev:
 	starpu_data_unregister(res_handle);
 	starpu_data_unregister(a_handle);
 
@@ -105,7 +105,5 @@ main()
 	starpu_free(a);
 
 	starpu_shutdown();
-	return EXIT_SUCCESS;
+	return ret == -ENODEV ? STARPU_TEST_SKIPPED : EXIT_SUCCESS;
 }
-
-