hello_world.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010-2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. struct params
  19. {
  20. int i;
  21. float f;
  22. };
  23. void cpu_func(void *buffers[], void *cl_arg)
  24. {
  25. struct params *params = cl_arg;
  26. printf("Hello world (params = {%i, %f} )\n", params->i, params->f);
  27. }
  28. struct starpu_codelet cl =
  29. {
  30. .where = STARPU_CPU,
  31. .cpu_funcs = {cpu_func, NULL},
  32. .nbuffers = 0
  33. };
  34. void callback_func(void *callback_arg)
  35. {
  36. printf("Callback function (arg %x)\n", callback_arg);
  37. }
  38. int main(int argc, char **argv)
  39. {
  40. /* initialize StarPU */
  41. starpu_init(NULL);
  42. struct starpu_task *task = starpu_task_create();
  43. task->cl = &cl; /* Pointer to the codelet defined above */
  44. struct params params = { 1, 2.0f };
  45. task->cl_arg = &params;
  46. task->cl_arg_size = sizeof(params);
  47. task->callback_func = callback_func;
  48. task->callback_arg = 0x42;
  49. /* starpu_task_submit will be a blocking call */
  50. task->synchronous = 1;
  51. /* submit the task to StarPU */
  52. starpu_task_submit(task);
  53. /* terminate StarPU */
  54. starpu_shutdown();
  55. return 0;
  56. }