task_with_multiple_time_the_same_handle.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. if (starpu_worker_get_count_by_type(STARPU_CPU_WORKER) == 0) return STARPU_TEST_SKIPPED;
  52. starpu_variable_data_register(&handle,0,(uintptr_t)&value,sizeof(double));
  53. for (i=0; i<2; i++)
  54. {
  55. starpu_task_insert(&sum_cl,
  56. STARPU_RW, handle,
  57. STARPU_R, handle,
  58. 0);
  59. starpu_task_insert(&sum3_cl,
  60. STARPU_R, handle,
  61. STARPU_R, handle,
  62. STARPU_RW, handle,
  63. 0);
  64. }
  65. starpu_task_wait_for_all();
  66. starpu_data_unregister(handle);
  67. if (value != 36)
  68. {
  69. FPRINTF(stderr, "value is %f instead of %f\n", value, 36.);
  70. ret = EXIT_FAILURE;
  71. }
  72. starpu_shutdown();
  73. return ret;
  74. }