hello_world.c 1.9 KB

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