codelet_null_callback.c 2.8 KB

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