tag-wait-api.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 <pthread.h>
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <starpu.h>
  20. static void *dummy_func(void *arg __attribute__ ((unused)))
  21. {
  22. return NULL;
  23. }
  24. static starpu_codelet dummy_codelet =
  25. {
  26. .where = ANY,
  27. .core_func = dummy_func,
  28. .cublas_func = dummy_func,
  29. .model = NULL,
  30. .nbuffers = 0
  31. };
  32. static void callback(void *tag)
  33. {
  34. // fflush(stderr);
  35. // fprintf(stderr, "Callback for tag %p\n", tag);
  36. // fflush(stderr);
  37. }
  38. static struct starpu_task *create_dummy_task(starpu_tag_t tag)
  39. {
  40. struct starpu_task *task = starpu_task_create();
  41. task->cl = &dummy_codelet;
  42. task->cl_arg = NULL;
  43. task->callback_func = callback;
  44. task->callback_arg = tag;
  45. task->use_tag = 1;
  46. task->tag_id = tag;
  47. task->cleanup = 0;
  48. return task;
  49. }
  50. #define tagA 0x42
  51. #define tagB 0x12300
  52. #define tagC 0x32
  53. #define tagD 0x52
  54. #define tagE 0x19999
  55. #define tagF 0x2312
  56. #define tagG 0x1985
  57. #define tagH 0x32234
  58. #define tagI 0x5234
  59. #define tagJ 0x199
  60. #define tagK 0x231234
  61. #define tagL 0x2345
  62. int main(int argc, char **argv)
  63. {
  64. starpu_init(NULL);
  65. fprintf(stderr, "{ A } -> { B }\n");
  66. fflush(stderr);
  67. struct starpu_task *taskA, *taskB;
  68. taskA = create_dummy_task(tagA);
  69. taskB = create_dummy_task(tagB);
  70. /* B depends on A */
  71. starpu_tag_declare_deps(tagB, 1, tagA);
  72. starpu_submit_task(taskB);
  73. starpu_submit_task(taskA);
  74. starpu_tag_wait(tagB);
  75. fflush(stderr);
  76. fprintf(stderr, "{ C, D, E, F } -> { G }\n");
  77. fflush(stderr);
  78. struct starpu_task *taskC, *taskD, *taskE, *taskF, *taskG;
  79. taskC = create_dummy_task(tagC);
  80. taskD = create_dummy_task(tagD);
  81. taskE = create_dummy_task(tagE);
  82. taskF = create_dummy_task(tagF);
  83. taskG = create_dummy_task(tagG);
  84. /* NB: we could have used starpu_tag_declare_deps_array instead */
  85. starpu_tag_declare_deps(tagG, 4, tagC, tagD, tagE, tagF);
  86. starpu_submit_task(taskC);
  87. starpu_submit_task(taskD);
  88. starpu_submit_task(taskG);
  89. starpu_submit_task(taskE);
  90. starpu_submit_task(taskF);
  91. starpu_tag_wait(tagG);
  92. fflush(stderr);
  93. fprintf(stderr, "{ H, I } -> { J, K, L }\n");
  94. fflush(stderr);
  95. struct starpu_task *taskH, *taskI, *taskJ, *taskK, *taskL;
  96. taskH = create_dummy_task(tagH);
  97. taskI = create_dummy_task(tagI);
  98. taskJ = create_dummy_task(tagJ);
  99. taskK = create_dummy_task(tagK);
  100. taskL = create_dummy_task(tagL);
  101. starpu_tag_declare_deps(tagJ, 2, tagH, tagI);
  102. starpu_tag_declare_deps(tagK, 2, tagH, tagI);
  103. starpu_tag_declare_deps(tagL, 2, tagH, tagI);
  104. starpu_tag_t tagJKL[3] = {tagJ, tagK, tagL};
  105. starpu_submit_task(taskH);
  106. starpu_submit_task(taskI);
  107. starpu_submit_task(taskJ);
  108. starpu_submit_task(taskK);
  109. starpu_submit_task(taskL);
  110. starpu_tag_wait_array(3, tagJKL);
  111. fprintf(stderr, "shutdown StarPU\n");
  112. starpu_shutdown();
  113. return 0;
  114. }