task_with_multiple_time_the_same_handle.c 2.3 KB

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