hello_world_mvsc.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010-2011, 2013 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. void callback_func(void *callback_arg)
  29. {
  30. printf("Callback function (arg %x)\n", callback_arg);
  31. }
  32. int main(int argc, char **argv)
  33. {
  34. int ret;
  35. struct starpu_codelet cl;
  36. struct starpu_task *task;
  37. struct params params;
  38. starpu_codelet_init(&cl);
  39. cl.cpu_funcs[0] = cpu_func;
  40. cl.cpu_funcs[1] = NULL;
  41. cl.nbuffers = 0;
  42. /* initialize StarPU */
  43. ret = starpu_init(NULL);
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  45. task = starpu_task_create();
  46. task->cl = &cl; /* Pointer to the codelet defined above */
  47. params.i = 1;
  48. params.f = 2.0f;
  49. task->cl_arg = &params;
  50. task->cl_arg_size = sizeof(params);
  51. task->callback_func = callback_func;
  52. task->callback_arg = (void*) (uintptr_t) 0x42;
  53. /* starpu_task_submit will be a blocking call */
  54. task->synchronous = 1;
  55. /* submit the task to StarPU */
  56. ret = starpu_task_submit(task);
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  58. /* terminate StarPU */
  59. starpu_shutdown();
  60. return 0;
  61. }