hello_world.c 1.7 KB

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