subgraph_repeat_regenerate.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <starpu.h>
  17. static unsigned niter = 16384;
  18. /*
  19. *
  20. * /-->B--\
  21. * | |
  22. * -----> A D---\--->
  23. * ^ | | |
  24. * | \-->C--/ |
  25. * | |
  26. * \--------------/
  27. *
  28. * - {B, C} depend on A
  29. * - D depends on {B, C}
  30. * - A, B, C and D are resubmitted at the end of the loop (or not)
  31. */
  32. static struct starpu_task taskA, taskB, taskC, taskD;
  33. static unsigned loop_cnt = 0;
  34. static unsigned check_cnt = 0;
  35. static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
  36. static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
  37. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  38. {
  39. STARPU_ATOMIC_ADD(&check_cnt, 1);
  40. }
  41. static starpu_codelet dummy_codelet =
  42. {
  43. .where = STARPU_CPU|STARPU_CUDA,
  44. .cpu_func = dummy_func,
  45. .cuda_func = dummy_func,
  46. .model = NULL,
  47. .nbuffers = 0
  48. };
  49. static void callback_task_D(void *arg __attribute__((unused)))
  50. {
  51. loop_cnt++;
  52. if (loop_cnt == niter)
  53. {
  54. /* We are done */
  55. pthread_mutex_lock(&mutex);
  56. pthread_cond_signal(&cond);
  57. pthread_mutex_unlock(&mutex);
  58. }
  59. else {
  60. /* Let's go for another iteration */
  61. starpu_submit_task(&taskA);
  62. }
  63. }
  64. int main(int argc, char **argv)
  65. {
  66. unsigned i;
  67. double timing;
  68. struct timeval start;
  69. struct timeval end;
  70. starpu_init(NULL);
  71. starpu_task_init(&taskA);
  72. taskA.cl = &dummy_codelet;
  73. taskA.cl_arg = &taskA;
  74. taskA.regenerate = 0; /* this task will be explicitely resubmitted if needed */
  75. starpu_task_init(&taskB);
  76. taskB.cl = &dummy_codelet;
  77. taskB.cl_arg = &taskB;
  78. taskB.regenerate = 1;
  79. starpu_task_init(&taskC);
  80. taskC.cl = &dummy_codelet;
  81. taskC.cl_arg = &taskC;
  82. taskC.regenerate = 1;
  83. starpu_task_init(&taskD);
  84. taskD.cl = &dummy_codelet;
  85. taskD.cl_arg = &taskD;
  86. taskD.callback_func = callback_task_D;
  87. taskD.regenerate = 1;
  88. struct starpu_task *depsBC_array[1] = {&taskA};
  89. starpu_task_declare_deps_array(&taskB, 1, depsBC_array);
  90. starpu_task_declare_deps_array(&taskC, 1, depsBC_array);
  91. struct starpu_task *depsD_array[2] = {&taskB, &taskC};
  92. starpu_task_declare_deps_array(&taskD, 2, depsD_array);
  93. starpu_submit_task(&taskA);
  94. starpu_submit_task(&taskB);
  95. starpu_submit_task(&taskC);
  96. starpu_submit_task(&taskD);
  97. /* Wait for the termination of all loops */
  98. pthread_mutex_lock(&mutex);
  99. if (loop_cnt < niter)
  100. pthread_cond_wait(&cond, &mutex);
  101. pthread_mutex_unlock(&mutex);
  102. STARPU_ASSERT(check_cnt == (4*loop_cnt));
  103. starpu_shutdown();
  104. return 0;
  105. }