callback.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2020-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. #include "../helper.h"
  18. void codelet_callback_func(void *arg)
  19. {
  20. if (arg)
  21. {
  22. int *x = (int *)arg;
  23. FPRINTF(stderr, "calling callback codelet arg %d\n", *x);
  24. }
  25. else
  26. FPRINTF(stderr, "calling callback codelet arg %p\n", arg);
  27. }
  28. void task_callback_func(void *arg)
  29. {
  30. FPRINTF(stderr, "\ncalling callback task arg %p\n", arg);
  31. if (starpu_task_get_current()->cl->callback_func)
  32. starpu_task_get_current()->cl->callback_func(arg);
  33. }
  34. struct starpu_codelet mycodelet =
  35. {
  36. .where = STARPU_NOWHERE,
  37. .callback_func = codelet_callback_func
  38. };
  39. struct starpu_codelet mycodelet2 =
  40. {
  41. .where = STARPU_NOWHERE,
  42. };
  43. int main(void)
  44. {
  45. int ret;
  46. int value=12;
  47. int value2=24;
  48. ret = starpu_init(NULL);
  49. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  51. ret = starpu_task_insert(&mycodelet,
  52. 0);
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  54. ret = starpu_task_insert(&mycodelet,
  55. STARPU_CALLBACK_ARG_NFREE, &value,
  56. 0);
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  58. ret = starpu_task_insert(&mycodelet,
  59. STARPU_CALLBACK, &task_callback_func,
  60. 0);
  61. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  62. ret = starpu_task_insert(&mycodelet,
  63. STARPU_CALLBACK, &task_callback_func,
  64. STARPU_CALLBACK_ARG_NFREE, &value2,
  65. 0);
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  67. ret = starpu_task_insert(&mycodelet2,
  68. 0);
  69. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  70. ret = starpu_task_insert(&mycodelet2,
  71. STARPU_CALLBACK, &task_callback_func,
  72. STARPU_CALLBACK_ARG_NFREE, &value,
  73. 0);
  74. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  75. starpu_shutdown();
  76. return 0;
  77. starpu_shutdown();
  78. fprintf(stderr, "WARNING: No one can execute this task\n");
  79. /* yes, we do not perform the computation but we did detect that no one
  80. * could perform the kernel, so this is not an error from StarPU */
  81. return STARPU_TEST_SKIPPED;
  82. }