codelet_null_callback.c 2.8 KB

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