hello_world.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. .cpu_funcs = {cpu_func, NULL},
  31. .nbuffers = 0
  32. };
  33. void callback_func(void *callback_arg)
  34. {
  35. printf("Callback function (arg %x)\n", callback_arg);
  36. }
  37. int main(int argc, char **argv)
  38. {
  39. /* initialize StarPU */
  40. starpu_init(NULL);
  41. struct starpu_task *task = starpu_task_create();
  42. task->cl = &cl; /* Pointer to the codelet defined above */
  43. struct params params = { 1, 2.0f };
  44. task->cl_arg = &params;
  45. task->cl_arg_size = sizeof(params);
  46. task->callback_func = callback_func;
  47. task->callback_arg = 0x42;
  48. /* starpu_task_submit will be a blocking call */
  49. task->synchronous = 1;
  50. /* submit the task to StarPU */
  51. starpu_task_submit(task);
  52. /* terminate StarPU */
  53. starpu_shutdown();
  54. return 0;
  55. }