Browse Source

doc/tutorial: add a hello world version tuned for Microsoft Visual Studio

Nathalie Furmento 11 years ago
parent
commit
b5e1dbed9f
2 changed files with 78 additions and 0 deletions
  1. 1 0
      doc/Makefile.am
  2. 77 0
      doc/tutorial/hello_world_msvc.c

+ 1 - 0
doc/Makefile.am

@@ -15,6 +15,7 @@ endif
 
 EXTRA_DIST =    tutorial/hello_world.c \
 		tutorial/hello_world_plugin.c \
+		tutorial/hello_world_msvc.c \
 		tutorial/Makefile \
 		tutorial/README \
 		tutorial/vector_scal.c \

+ 77 - 0
doc/tutorial/hello_world_msvc.c

@@ -0,0 +1,77 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2010-2011  Université de Bordeaux 1
+ * Copyright (C) 2010-2011, 2013  Centre National de la Recherche Scientifique
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu.h>
+
+struct params
+{
+	int i;
+	float f;
+};
+
+void cpu_func(void *buffers[], void *cl_arg)
+{
+	struct params *params = cl_arg;
+
+	printf("Hello world (params = {%i, %f} )\n", params->i, params->f);
+}
+
+void callback_func(void *callback_arg)
+{
+	printf("Callback function (arg %x)\n", callback_arg);
+}
+
+int main(int argc, char **argv)
+{
+	int ret;
+	struct starpu_codelet cl;
+	struct starpu_task *task;
+	struct params params;
+
+	starpu_codelet_init(&cl);
+	cl.cpu_funcs[0] = cpu_func;
+	cl.cpu_funcs[1] = NULL;
+	cl.nbuffers = 0;
+
+	/* initialize StarPU */
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+
+	task = starpu_task_create();
+
+	task->cl = &cl; /* Pointer to the codelet defined above */
+
+	params.i = 1;
+	params.f = 2.0f;
+	task->cl_arg = &params;
+	task->cl_arg_size = sizeof(params);
+
+	task->callback_func = callback_func;
+	task->callback_arg = (void*) (uintptr_t) 0x42;
+
+	/* starpu_task_submit will be a blocking call */
+	task->synchronous = 1;
+
+	/* submit the task to StarPU */
+	ret = starpu_task_submit(task);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
+
+	/* terminate StarPU */
+	starpu_shutdown();
+
+	return 0;
+}