task_end_dep.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2018 CNRS
  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. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  18. void cpu_codelet2(void *descr[], void *args)
  19. {
  20. (void)descr;
  21. (void)args;
  22. }
  23. struct starpu_codelet cl2 =
  24. {
  25. .cpu_funcs = {cpu_codelet2},
  26. .cpu_funcs_name = {"cpu_codelet2"},
  27. .name = "codelet2"
  28. };
  29. void cpu_codelet(void *descr[], void *args)
  30. {
  31. (void)args;
  32. int *val = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  33. struct starpu_task *task;
  34. task = starpu_task_get_current();
  35. starpu_task_end_dep_add(task, 1);
  36. starpu_task_insert(&cl2,
  37. STARPU_CALLBACK_WITH_ARG, starpu_task_end_dep_release, task,
  38. 0);
  39. *val *= 2;
  40. }
  41. struct starpu_codelet cl =
  42. {
  43. .cpu_funcs = {cpu_codelet},
  44. .cpu_funcs_name = {"cpu_codelet"},
  45. .nbuffers = 1,
  46. .modes = {STARPU_RW},
  47. .name = "codelet"
  48. };
  49. int main(void)
  50. {
  51. int value=12;
  52. int ret;
  53. starpu_data_handle_t value_handle;
  54. ret = starpu_init(NULL);
  55. if (STARPU_UNLIKELY(ret == -ENODEV))
  56. {
  57. return 77;
  58. }
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  60. if (starpu_cpu_worker_get_count() < 1)
  61. {
  62. FPRINTF(stderr, "This application requires at least 1 cpu worker\n");
  63. starpu_shutdown();
  64. return 77;
  65. }
  66. starpu_variable_data_register(&value_handle, STARPU_MAIN_RAM, (uintptr_t)&value, sizeof(value));
  67. ret = starpu_task_insert(&cl,
  68. STARPU_RW, value_handle,
  69. 0);
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  71. starpu_data_unregister(value_handle);
  72. starpu_shutdown();
  73. FPRINTF(stderr, "Value = %d\n", value);
  74. return ret;
  75. }