codelet_null_callback.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013, 2014 Centre National de la Recherche Scientifique
  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. static
  19. void callback(void *ptr)
  20. {
  21. int *x = (int *)ptr;
  22. FPRINTF(stderr, "x=%d\n", *x);
  23. STARPU_ASSERT_MSG(*x == 40, "%d != %d\n", *x, 40);
  24. (*x)++;
  25. }
  26. static
  27. void callback2(void *ptr)
  28. {
  29. int *x2 = (int *)ptr;
  30. FPRINTF(stderr, "x2=%d\n", *x2);
  31. STARPU_ASSERT_MSG(*x2 == 41, "%d != %d\n", *x2, 41);
  32. (*x2)++;
  33. }
  34. static
  35. void prologue_callback(void *ptr)
  36. {
  37. int *y = (int *)ptr;
  38. FPRINTF(stderr, "y=%d\n", *y);
  39. STARPU_ASSERT_MSG(*y == 12, "%d != %d\n", *y, 12);
  40. (*y)++;
  41. }
  42. static
  43. void prologue_callback_pop(void *ptr)
  44. {
  45. int *z = (int *)ptr;
  46. FPRINTF(stderr, "z=%d\n", *z);
  47. STARPU_ASSERT_MSG(*z == 32, "%d != %d\n", *z, 32);
  48. (*z)++;
  49. }
  50. int main(int argc, char **argv)
  51. {
  52. int ret;
  53. int x=40;
  54. int x2=41;
  55. int y=12;
  56. int z=32;
  57. ret = starpu_initialize(NULL, &argc, &argv);
  58. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  60. ret = starpu_task_insert(NULL,
  61. STARPU_CALLBACK_WITH_ARG, callback, &x,
  62. 0);
  63. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  64. ret = starpu_task_insert(NULL,
  65. STARPU_CALLBACK, callback2,
  66. STARPU_CALLBACK_ARG, &x2,
  67. 0);
  68. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  69. ret = starpu_task_insert(NULL,
  70. STARPU_PROLOGUE_CALLBACK, prologue_callback,
  71. STARPU_PROLOGUE_CALLBACK_ARG, &y,
  72. 0);
  73. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  74. ret = starpu_task_insert(NULL,
  75. STARPU_PROLOGUE_CALLBACK_POP, prologue_callback_pop,
  76. STARPU_PROLOGUE_CALLBACK_POP_ARG, &z,
  77. 0);
  78. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  79. starpu_task_wait_for_all();
  80. STARPU_ASSERT_MSG(x == 41, "x should be equal to %d and not %d\n", 41, x);
  81. STARPU_ASSERT_MSG(x2 == 42, "x2 should be equal to %d and not %d\n", 42, x2);
  82. STARPU_ASSERT_MSG(y == 13, "y should be equal to %d and not %d\n", 13, y);
  83. STARPU_ASSERT_MSG(z == 33, "z should be equal to %d and not %d\n", 33, z);
  84. starpu_shutdown();
  85. return EXIT_SUCCESS;
  86. }