retry.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013,2015,2017 CNRS
  4. * Copyright (C) 2017 Inria
  5. * Copyright (C) 2019 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. extern void cuda_host_increment(void *descr[], void *_args);
  21. static int retry;
  22. void cpu_increment(void *descr[], void *arg)
  23. {
  24. (void)arg;
  25. unsigned *var = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[0]);
  26. unsigned *var2 = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[1]);
  27. FPRINTF(stderr,"computing\n");
  28. *var2 = *var + 1;
  29. if (retry <= 10)
  30. {
  31. FPRINTF(stderr,"failing\n");
  32. retry++;
  33. /* Fake failure */
  34. starpu_task_failed(starpu_task_get_current());
  35. }
  36. }
  37. static struct starpu_codelet my_codelet =
  38. {
  39. .cpu_funcs = {cpu_increment},
  40. .cpu_funcs_name = {"cpu_increment"},
  41. .modes = { STARPU_R, STARPU_W },
  42. .nbuffers = 2
  43. };
  44. int main(void)
  45. {
  46. int x = 12;
  47. int y = 1;
  48. starpu_data_handle_t h_x, h_y;
  49. int ret, ret1;
  50. ret = starpu_init(NULL);
  51. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  53. starpu_variable_data_register(&h_x, STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  54. starpu_variable_data_register(&h_y, STARPU_MAIN_RAM, (uintptr_t)&y, sizeof(y));
  55. retry = 0;
  56. ret1 = starpu_task_insert(&my_codelet,
  57. STARPU_R, h_x,
  58. STARPU_W, h_y,
  59. 0);
  60. if (ret1 != -ENODEV) STARPU_CHECK_RETURN_VALUE(ret1, "starpu_task_insert");
  61. starpu_task_wait_for_all();
  62. starpu_data_unregister(h_x);
  63. starpu_data_unregister(h_y);
  64. starpu_shutdown();
  65. if (x != 12)
  66. ret = 1;
  67. FPRINTF(stderr, "Value x = %d (expected 12)\n", x);
  68. if (ret1 != -ENODEV)
  69. {
  70. if (y != 13)
  71. ret = 1;
  72. FPRINTF(stderr, "Value y = %d (expected 13)\n", y);
  73. }
  74. STARPU_RETURN(ret);
  75. }