task_end_dep.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2018-2021 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.nmpi_ms = 0;
  64. ret = starpu_init(&conf);
  65. if (STARPU_UNLIKELY(ret == -ENODEV))
  66. {
  67. return 77;
  68. }
  69. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  70. if (starpu_cpu_worker_get_count() < 1)
  71. {
  72. FPRINTF(stderr, "This application requires at least 1 cpu worker\n");
  73. starpu_shutdown();
  74. return 77;
  75. }
  76. starpu_variable_data_register(&value_handle, STARPU_MAIN_RAM, (uintptr_t)&value, sizeof(value));
  77. task = starpu_task_build(&cl,
  78. STARPU_RW, value_handle,
  79. 0);
  80. STARPU_ASSERT(task);
  81. task->detach = 0;
  82. task2 = starpu_task_build(&cl2,
  83. STARPU_RW, value_handle,
  84. 0);
  85. STARPU_ASSERT(task2);
  86. task2->detach = 0;
  87. task2->destroy = 0;
  88. ret = starpu_task_submit(task2);
  89. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  90. ret = starpu_task_wait(task2);
  91. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  92. starpu_task_declare_end_deps(task, 1, task2);
  93. starpu_task_destroy(task2);
  94. ret = starpu_task_submit(task);
  95. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  96. ret = starpu_task_wait(task);
  97. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  98. starpu_data_unregister(value_handle);
  99. STARPU_ASSERT(value == 2*2*INIT);
  100. starpu_shutdown();
  101. FPRINTF(stderr, "Value = %d\n", value);
  102. return ret;
  103. }