浏览代码

examples/filters/fplan_notautomatic.c: fix program
- the tasks working on the subdata are executed throught the
prologue callback, with a nowhere codelet, to make sure StarPU is
not trying to fetch data
- the merge application task is waiting for the the termination of
the unpartitionning task

Nathalie Furmento 6 年之前
父节点
当前提交
04ae11ba9a
共有 1 个文件被更改,包括 45 次插入30 次删除
  1. 45 30
      examples/filters/fplan_notautomatic.c

+ 45 - 30
examples/filters/fplan_notautomatic.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2018                                     CNRS
+ * Copyright (C) 2018, 2019                               CNRS
  * Copyright (C) 2018                                     Université de Bordeaux
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -44,27 +44,27 @@ void task_cpu(void *descr[], void *args)
 	FPRINTF(stderr, "%s\n", message);
 }
 
-void split_cpu(void *descr[], void *args)
+void split_callback(void *arg)
 {
-	(void)descr;
-	//	starpu_data_handle_t data_handle = starpu_data_lookup((void*)STARPU_VECTOR_GET_PTR(descr[0]));
-
+	(arg);
+	struct starpu_task *task = starpu_task_get_current();
 	starpu_data_handle_t value_handle, sub_handles[PARTS];
-	starpu_codelet_unpack_args(args, &value_handle, &sub_handles);
 
-	FPRINTF(stderr, "Partition for handle %p into handles %p %p and %p\n", value_handle, sub_handles[0], sub_handles[1], sub_handles[2]);
+	starpu_codelet_unpack_args(task->cl_arg, &value_handle, &sub_handles);
+
+	FPRINTF(stderr, "[callback] Partition for handle %p into handles %p %p and %p\n", value_handle, sub_handles[0], sub_handles[1], sub_handles[2]);
 
 	starpu_data_partition_submit_sequential_consistency(value_handle, PARTS, sub_handles, 0);
 }
 
-void supertask_cpu(void *descr[], void *args)
+void supertask_callback(void *arg)
 {
-	(void)descr;
-	//	starpu_data_handle_t data_handle = starpu_data_lookup((void*)STARPU_VECTOR_GET_PTR(descr[0]));
+	(arg);
 	starpu_data_handle_t sub_handles[PARTS];
 	int add;
+	struct starpu_task *task = starpu_task_get_current();
 
-	starpu_codelet_unpack_args(args, &sub_handles, &add);
+	starpu_codelet_unpack_args(task->cl_arg, &sub_handles, &add);
 
 	FPRINTF(stderr, "Submitting tasks on %d subdata (add %d)\n", PARTS, add);
 
@@ -79,20 +79,25 @@ void supertask_cpu(void *descr[], void *args)
 	}
 }
 
-void merge_cpu(void *descr[], void *args)
+void release(void *arg)
+{
+	struct starpu_task *task = (struct starpu_task *)arg;
+	starpu_task_end_dep_release(task);
+}
+
+void merge_callback(void *arg)
 {
-	(void)descr;
-	//	starpu_data_handle_t value_handle = starpu_data_lookup((void*)STARPU_VECTOR_GET_PTR(descr[0]));
+	(void)arg;
+	struct starpu_task *task = starpu_task_get_current();
 
 	starpu_data_handle_t value_handle, sub_handles[PARTS];
-	starpu_codelet_unpack_args(args, &value_handle, &sub_handles);
+	starpu_codelet_unpack_args(task->cl_arg, &value_handle, &sub_handles);
 
 	FPRINTF(stderr, "Unpartition for handle %p from handles %p %p and %p\n", value_handle, sub_handles[0], sub_handles[1], sub_handles[2]);
 
-	starpu_data_unpartition_submit_sequential_consistency(value_handle, PARTS, sub_handles, STARPU_MAIN_RAM, 0);
+	starpu_data_unpartition_submit_sequential_consistency_with_callback(value_handle, PARTS, sub_handles, STARPU_MAIN_RAM, 0, release, task);
 }
 
-
 // Codelets
 struct starpu_codelet task_codelet =
 {
@@ -104,7 +109,7 @@ struct starpu_codelet task_codelet =
 
 struct starpu_codelet supertask_codelet =
 {
-	.cpu_funcs = {supertask_cpu},
+	.where= STARPU_NOWHERE,
 	.nbuffers = 1,
 	.modes = {STARPU_RW},
 	.name = "supertask_codelet"
@@ -112,7 +117,7 @@ struct starpu_codelet supertask_codelet =
 
 struct starpu_codelet split_codelet =
 {
-	.cpu_funcs = {split_cpu},
+	.where= STARPU_NOWHERE,
 	.nbuffers = 1,
 	.modes = {STARPU_RW},
 	.name = "split_codelet"
@@ -120,7 +125,7 @@ struct starpu_codelet split_codelet =
 
 struct starpu_codelet merge_codelet =
 {
-	.cpu_funcs = {merge_cpu},
+	.where= STARPU_NOWHERE,
 	.nbuffers = 1,
 	.modes = {STARPU_RW},
 	.name = "merge_codelet"
@@ -131,7 +136,8 @@ int main(void)
 	int ret, i;
 	int values[NX];
 	int check[NX];
-	int add=1;
+	int add1=1;
+	int add2=2;
 	starpu_data_handle_t value_handle;
 	starpu_data_handle_t sub_handles[PARTS];
 
@@ -155,7 +161,7 @@ int main(void)
 
 	values[NX-1] = 2;
 	for(i=NX-2 ; i>= 0 ; i--) values[i] = values[i+1] * 2;
-	for(i=0 ; i<NX ; i++) check[i] = values[i] + (4 * add);
+	for(i=0 ; i<NX ; i++) check[i] = values[i] + (2 * add1) + (2 * add2);
 
 	starpu_vector_data_register(&value_handle, STARPU_MAIN_RAM, (uintptr_t)&values[0], NX, sizeof(values[0]));
 	starpu_data_partition_plan(value_handle, &f, sub_handles);
@@ -167,7 +173,7 @@ int main(void)
 
 	// insert a task on the whole data
 	ret = starpu_task_insert(&task_codelet, STARPU_RW, value_handle,
-				 STARPU_VALUE, &add, sizeof(add),
+				 STARPU_VALUE, &add1, sizeof(add1),
 				 STARPU_NAME, "task_1", 0);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
 
@@ -175,33 +181,42 @@ int main(void)
 	ret = starpu_task_insert(&split_codelet, STARPU_RW, value_handle,
 				 STARPU_VALUE, &value_handle, sizeof(starpu_data_handle_t),
 				 STARPU_VALUE, sub_handles, PARTS*sizeof(starpu_data_handle_t),
-				 STARPU_NAME, "split", 0);
+				 STARPU_NAME, "split",
+				 STARPU_PROLOGUE_CALLBACK, split_callback,
+				 0);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
 
 	// insert a task that will work on the subdata
 	ret = starpu_task_insert(&supertask_codelet, STARPU_RW, value_handle,
 				 STARPU_VALUE, sub_handles, PARTS*sizeof(starpu_data_handle_t),
-				 STARPU_VALUE, &add, sizeof(add),
-				 STARPU_NAME, "supertask_1", 0);
+				 STARPU_VALUE, &add1, sizeof(add1),
+				 STARPU_NAME, "supertask_1",
+				 STARPU_PROLOGUE_CALLBACK, supertask_callback,
+				 0);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
 
 	// insert another task that will work on the subdata
 	ret = starpu_task_insert(&supertask_codelet, STARPU_RW, value_handle,
 				 STARPU_VALUE, sub_handles, PARTS*sizeof(starpu_data_handle_t),
-				 STARPU_VALUE, &add, sizeof(add),
-				 STARPU_NAME, "supertask_2", 0);
+				 STARPU_VALUE, &add2, sizeof(add2),
+				 STARPU_NAME, "supertask_2",
+				 STARPU_PROLOGUE_CALLBACK, supertask_callback,
+				 0);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
 
 	// insert a task to merge the data
 	ret = starpu_task_insert(&merge_codelet, STARPU_RW, value_handle,
 				 STARPU_VALUE, &value_handle, sizeof(starpu_data_handle_t),
 				 STARPU_VALUE, sub_handles, PARTS*sizeof(starpu_data_handle_t),
-				 STARPU_NAME, "merge", 0);
+				 STARPU_NAME, "merge",
+				 STARPU_PROLOGUE_CALLBACK, merge_callback,
+				 STARPU_TASK_END_DEP, 1,
+				 0);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
 
 	// insert a task that will work on the whole data
 	ret = starpu_task_insert(&task_codelet, STARPU_RW, value_handle,
-				 STARPU_VALUE, &add, sizeof(add),
+				 STARPU_VALUE, &add2, sizeof(add2),
 				 STARPU_NAME, "task_2", 0);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");