task_with_multiple_time_the_same_handle.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. static 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. static 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, NULL},
  34. .nbuffers = 2,
  35. .modes={STARPU_RW,STARPU_R}
  36. };
  37. static struct starpu_codelet sum3_cl =
  38. {
  39. .cpu_funcs = {sum3_cpu, NULL},
  40. .nbuffers = 3,
  41. .modes={STARPU_R,STARPU_R,STARPU_RW}
  42. };
  43. int main(int argc, char * argv[])
  44. {
  45. starpu_data_handle_t handle;
  46. int ret = 0;
  47. double value=1.0;
  48. int i;
  49. ret=starpu_init(NULL);
  50. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  51. starpu_variable_data_register(&handle,0,(uintptr_t)&value,sizeof(double));
  52. for (i=0; i<2; i++)
  53. {
  54. starpu_insert_task(&sum_cl,
  55. STARPU_RW, handle,
  56. STARPU_R, handle,
  57. 0);
  58. starpu_insert_task(&sum3_cl,
  59. STARPU_R, handle,
  60. STARPU_R, handle,
  61. STARPU_RW, handle,
  62. 0);
  63. }
  64. starpu_task_wait_for_all();
  65. starpu_data_unregister(handle);
  66. if (value != 36)
  67. {
  68. FPRINTF(stderr, "value is %f instead of %f\n", value, 36);
  69. ret = EXIT_FAILURE;
  70. }
  71. starpu_shutdown();
  72. return ret;
  73. }