task_end_dep.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2018-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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. /* This checks that adding an end dependency for an already-terminated task
  17. * works */
  18. #include <starpu.h>
  19. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  20. #define INIT 12
  21. void cpu_codelet2(void *descr[], void *args)
  22. {
  23. int *val = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  24. (void)args;
  25. STARPU_ASSERT(*val == INIT);
  26. starpu_sleep(0.1);
  27. STARPU_ASSERT(*val == INIT);
  28. *val *= 2;
  29. }
  30. struct starpu_codelet cl2 =
  31. {
  32. .cpu_funcs = {cpu_codelet2},
  33. .cpu_funcs_name = {"cpu_codelet2"},
  34. .nbuffers = 1,
  35. .modes = {STARPU_RW},
  36. .name = "codelet2"
  37. };
  38. void cpu_codelet(void *descr[], void *args)
  39. {
  40. (void)args;
  41. int *val = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  42. STARPU_ASSERT(*val == 2*INIT);
  43. starpu_sleep(0.1);
  44. STARPU_ASSERT(*val == 2*INIT);
  45. *val *= 2;
  46. }
  47. struct starpu_codelet cl =
  48. {
  49. .cpu_funcs = {cpu_codelet},
  50. .cpu_funcs_name = {"cpu_codelet"},
  51. .nbuffers = 1,
  52. .modes = {STARPU_RW},
  53. .name = "codelet"
  54. };
  55. int main(void)
  56. {
  57. int value=INIT;
  58. int ret;
  59. starpu_data_handle_t value_handle;
  60. struct starpu_conf conf;
  61. struct starpu_task *task, *task2;
  62. starpu_conf_init(&conf);
  63. conf.nmic = 0;
  64. conf.nmpi_ms = 0;
  65. ret = starpu_init(&conf);
  66. if (STARPU_UNLIKELY(ret == -ENODEV))
  67. {
  68. return 77;
  69. }
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  71. if (starpu_cpu_worker_get_count() < 1)
  72. {
  73. FPRINTF(stderr, "This application requires at least 1 cpu worker\n");
  74. starpu_shutdown();
  75. return 77;
  76. }
  77. starpu_variable_data_register(&value_handle, STARPU_MAIN_RAM, (uintptr_t)&value, sizeof(value));
  78. task = starpu_task_build(&cl,
  79. STARPU_RW, value_handle,
  80. 0);
  81. STARPU_ASSERT(task);
  82. task->detach = 0;
  83. task2 = starpu_task_build(&cl2,
  84. STARPU_RW, value_handle,
  85. 0);
  86. STARPU_ASSERT(task2);
  87. task2->detach = 0;
  88. task2->destroy = 0;
  89. ret = starpu_task_submit(task2);
  90. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  91. ret = starpu_task_wait(task2);
  92. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  93. starpu_task_declare_end_deps(task, 1, task2);
  94. starpu_task_destroy(task2);
  95. ret = starpu_task_submit(task);
  96. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  97. ret = starpu_task_wait(task);
  98. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  99. starpu_data_unregister(value_handle);
  100. STARPU_ASSERT(value == 2*2*INIT);
  101. starpu_shutdown();
  102. FPRINTF(stderr, "Value = %d\n", value);
  103. return ret;
  104. }