task_with_multiple_time_the_same_handle.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-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 the same handle several times to the same task
  20. */
  21. void sum_cpu(void * descr[], void *cl_arg)
  22. {
  23. (void)cl_arg;
  24. double * v_dst = (double *) STARPU_VARIABLE_GET_PTR(descr[0]);
  25. double * v_src = (double *) STARPU_VARIABLE_GET_PTR(descr[1]);
  26. *v_dst+=*v_src;
  27. }
  28. void sum3_cpu(void * descr[], void *cl_arg)
  29. {
  30. (void)cl_arg;
  31. double * v_src1 = (double *) STARPU_VARIABLE_GET_PTR(descr[1]);
  32. double * v_src2 = (double *) STARPU_VARIABLE_GET_PTR(descr[1]);
  33. double * v_dst = (double *) STARPU_VARIABLE_GET_PTR(descr[0]);
  34. *v_dst+=*v_src1+*v_src2;
  35. }
  36. static struct starpu_codelet sum_cl =
  37. {
  38. .cpu_funcs = {sum_cpu},
  39. .cpu_funcs_name = {"sum_cpu"},
  40. .nbuffers = 2,
  41. .modes={STARPU_RW,STARPU_R}
  42. };
  43. static struct starpu_codelet sum3_cl =
  44. {
  45. .cpu_funcs = {sum3_cpu},
  46. .cpu_funcs_name = {"sum3_cpu"},
  47. .nbuffers = 3,
  48. .modes={STARPU_R,STARPU_R,STARPU_RW}
  49. };
  50. int main(void)
  51. {
  52. starpu_data_handle_t handle;
  53. int ret = 0;
  54. double value=1.0;
  55. int i;
  56. ret=starpu_init(NULL);
  57. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  58. starpu_variable_data_register(&handle,0,(uintptr_t)&value,sizeof(double));
  59. for (i=0; i<2; i++)
  60. {
  61. ret = starpu_task_insert(&sum_cl,
  62. STARPU_RW, handle,
  63. STARPU_R, handle,
  64. 0);
  65. if (ret == -ENODEV) goto enodev;
  66. ret = starpu_task_insert(&sum3_cl,
  67. STARPU_R, handle,
  68. STARPU_R, handle,
  69. STARPU_RW, handle,
  70. 0);
  71. if (ret == -ENODEV) goto enodev;
  72. }
  73. starpu_task_wait_for_all();
  74. starpu_data_unregister(handle);
  75. if (value != 36)
  76. {
  77. FPRINTF(stderr, "value is %f instead of %f\n", value, 36.);
  78. ret = EXIT_FAILURE;
  79. }
  80. starpu_shutdown();
  81. return ret;
  82. enodev:
  83. starpu_data_unregister(handle);
  84. starpu_shutdown();
  85. return STARPU_TEST_SKIPPED;
  86. }