task_with_multiple_time_the_same_handle.c 2.6 KB

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