task_end_dep.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2018 Université de Bordeaux
  4. * Copyright (C) 2018, 2019 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. /* This checks that adding an end dependency for an already-terminated task
  18. * works */
  19. #include <starpu.h>
  20. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  21. #define INIT 12
  22. void cpu_codelet2(void *descr[], void *args)
  23. {
  24. int *val = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  25. (void)args;
  26. STARPU_ASSERT(*val == INIT);
  27. starpu_sleep(0.1);
  28. STARPU_ASSERT(*val == INIT);
  29. *val *= 2;
  30. }
  31. struct starpu_codelet cl2 =
  32. {
  33. .cpu_funcs = {cpu_codelet2},
  34. .cpu_funcs_name = {"cpu_codelet2"},
  35. .nbuffers = 1,
  36. .modes = {STARPU_RW},
  37. .name = "codelet2"
  38. };
  39. void cpu_codelet(void *descr[], void *args)
  40. {
  41. (void)args;
  42. int *val = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  43. STARPU_ASSERT(*val == 2*INIT);
  44. starpu_sleep(0.1);
  45. STARPU_ASSERT(*val == 2*INIT);
  46. *val *= 2;
  47. }
  48. struct starpu_codelet cl =
  49. {
  50. .cpu_funcs = {cpu_codelet},
  51. .cpu_funcs_name = {"cpu_codelet"},
  52. .nbuffers = 1,
  53. .modes = {STARPU_RW},
  54. .name = "codelet"
  55. };
  56. int main(void)
  57. {
  58. int value=INIT;
  59. int ret;
  60. starpu_data_handle_t value_handle;
  61. struct starpu_conf conf;
  62. struct starpu_task *task, *task2;
  63. starpu_conf_init(&conf);
  64. conf.nmic = 0;
  65. conf.nmpi_ms = 0;
  66. ret = starpu_init(&conf);
  67. if (STARPU_UNLIKELY(ret == -ENODEV))
  68. {
  69. return 77;
  70. }
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  72. if (starpu_cpu_worker_get_count() < 1)
  73. {
  74. FPRINTF(stderr, "This application requires at least 1 cpu worker\n");
  75. starpu_shutdown();
  76. return 77;
  77. }
  78. starpu_variable_data_register(&value_handle, STARPU_MAIN_RAM, (uintptr_t)&value, sizeof(value));
  79. task = starpu_task_build(&cl,
  80. STARPU_RW, value_handle,
  81. 0);
  82. STARPU_ASSERT(task);
  83. task->detach = 0;
  84. task2 = starpu_task_build(&cl2,
  85. STARPU_RW, value_handle,
  86. 0);
  87. STARPU_ASSERT(task2);
  88. task2->detach = 0;
  89. task2->destroy = 0;
  90. ret = starpu_task_submit(task2);
  91. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  92. ret = starpu_task_wait(task2);
  93. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  94. starpu_task_declare_end_deps(task, 1, task2);
  95. starpu_task_destroy(task2);
  96. ret = starpu_task_submit(task);
  97. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  98. ret = starpu_task_wait(task);
  99. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  100. starpu_data_unregister(value_handle);
  101. STARPU_ASSERT(value == 2*2*INIT);
  102. starpu_shutdown();
  103. FPRINTF(stderr, "Value = %d\n", value);
  104. return ret;
  105. }