Explorar o código

adapt the hello world to its actual descriptions in the documentation

Cédric Augonnet %!s(int64=16) %!d(string=hai) anos
pai
achega
7eabf0d01a
Modificáronse 2 ficheiros con 22 adicións e 15 borrados
  1. 7 5
      doc/starpu.texi
  2. 15 10
      examples/basic-examples/hello-world.c

+ 7 - 5
doc/starpu.texi

@@ -210,7 +210,7 @@ LIBS+=$$(pkg-config --libs libstarpu)
 
 @section Hello World
 
-In this section, we show a simple 
+In this section, we show how to implement a simple program that submits a task to StarPU.
 
 @subsection Required Headers
 
@@ -251,9 +251,10 @@ structure) does not count as a buffer since it is not managed by our data
 management library. 
 
 @c TODO need a crossref to the proper description of "where" see bla for more ...
-We create a codelet which may only execute on the CPUs. The ''@code{.where}''
+We create a codelet which may only be executed on the CPUs. The ''@code{.where}''
 field is a bitmask that defines where the codelet may be executed. Here, the
-@code{CORE} value means that only CPUs can execute this codelet.
+@code{CORE} value means that only CPUs can execute this codelet
+(@xref{Codelets and Tasks} for more details on that field).
 When a CPU core executes a codelet, it calls the @code{.core_func} function,
 which @emph{must} have the following prototype:
 
@@ -287,7 +288,7 @@ int main(int argc, char **argv)
 
     task->cl = &cl;
     
-    float array[2] = {1.0f, -1.0f};
+    float array[2] = @{1.0f, -1.0f@};
     task->cl_arg = &array;
     task->cl_arg_size = 2*sizeof(float);
 
@@ -308,5 +309,6 @@ int main(int argc, char **argv)
 @end cartouche
 @end example
 
-
+@c the task is executed on the device/accelerator but the callback is always
+@c executed on the CPUs
 @bye

+ 15 - 10
examples/basic-examples/hello-world.c

@@ -22,26 +22,31 @@ void callback_func(void *callback_arg)
 	printf("Callback function got argument %x\n", callback_arg);
 }
 
-void core_func(starpu_data_interface_t *buffers, __attribute__ ((unused)) void *_args)
+void cpu_func(starpu_data_interface_t *buffers, void *func_arg)
 {
-	printf("Hello world\n");
+	float *array = func_arg;
+
+	printf("Hello world (array = {%f, %f} )\n", array[0], array[1]);
 }
 
+starpu_codelet cl =
+{
+	.where = CORE,
+	.core_func = cpu_func,
+	.nbuffers = 0
+};
+
 int main(int argc, char **argv)
 {
 	/* initialize StarPU */
 	starpu_init(NULL);
-
-	starpu_codelet cl =
-	{
-		.where = CORE,
-		.core_func = core_func,
-		.nbuffers = 0
-	};
-
 	struct starpu_task *task = starpu_task_create();
 
 	task->cl = &cl;
+
+	float array[2] = {1.0f, -1.0f};
+	task->cl_arg = &array;
+	task->cl_arg_size = 2*sizeof(float);
 		
 	task->callback_func = callback_func;
 	task->callback_arg = 0x42;