task_with_multiple_time_the_same_handle.c 2.4 KB

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