codelet_null_callback.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. int expected_x=40;
  20. static
  21. int expected_y=12;
  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 == expected_x, "%d != %d\n", *x, expected_x);
  28. (*x)++;
  29. }
  30. static
  31. void prologue_callback(void *ptr)
  32. {
  33. int *y = (int *)ptr;
  34. FPRINTF(stderr, "y=%d\n", *y);
  35. STARPU_ASSERT_MSG(*y == expected_y, "%d != %d\n", *y, expected_y);
  36. (*y)++;
  37. }
  38. int main(int argc, char **argv)
  39. {
  40. int ret;
  41. int x=40;
  42. int y=12;
  43. ret = starpu_initialize(NULL, &argc, &argv);
  44. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  46. ret = starpu_task_insert(NULL,
  47. STARPU_CALLBACK_WITH_ARG, callback, &x,
  48. 0);
  49. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  50. expected_x ++;
  51. ret = starpu_task_insert(NULL,
  52. STARPU_CALLBACK, callback,
  53. STARPU_CALLBACK_ARG, &x,
  54. 0);
  55. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  56. expected_x ++;
  57. STARPU_ASSERT_MSG(x == expected_x, "x should be equal to %d and not %d\n", expected_x, x);
  58. ret = starpu_task_insert(NULL,
  59. STARPU_PROLOGUE_CALLBACK, prologue_callback,
  60. STARPU_PROLOGUE_CALLBACK_ARG, &y,
  61. 0);
  62. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  63. #warning the following code should work
  64. #if 0
  65. expected_y ++;
  66. ret = starpu_task_insert(NULL,
  67. STARPU_PROLOGUE_CALLBACK_POP, prologue_callback,
  68. STARPU_PROLOGUE_CALLBACK_ARG, &y,
  69. 0);
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  71. #endif
  72. expected_y ++;
  73. STARPU_ASSERT_MSG(y == expected_y, "y should be equal to %d and not %d\n", expected_y, y);
  74. starpu_shutdown();
  75. return EXIT_SUCCESS;
  76. }