subgraph_repeat.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 = 128;
  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 is 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 pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
  35. static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
  36. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  37. {
  38. fprintf(stderr, "PIF\n");
  39. }
  40. static starpu_codelet dummy_codelet =
  41. {
  42. .where = STARPU_CPU|STARPU_CUDA,
  43. .cpu_func = dummy_func,
  44. .cuda_func = dummy_func,
  45. .model = NULL,
  46. .nbuffers = 0
  47. };
  48. static void callback_task_D(void *arg __attribute__((unused)))
  49. {
  50. loop_cnt++;
  51. if (loop_cnt == niter)
  52. {
  53. /* We are done */
  54. pthread_mutex_lock(&mutex);
  55. pthread_cond_signal(&cond);
  56. pthread_mutex_unlock(&mutex);
  57. }
  58. else {
  59. /* Let's go for another iteration */
  60. starpu_submit_task(&taskA);
  61. }
  62. }
  63. int main(int argc, char **argv)
  64. {
  65. unsigned i;
  66. double timing;
  67. struct timeval start;
  68. struct timeval end;
  69. starpu_init(NULL);
  70. starpu_task_init(&taskA);
  71. taskA.cl = &dummy_codelet;
  72. taskA.regenerate = 0; /* this must be submitted again */
  73. starpu_task_init(&taskB);
  74. taskB.cl = &dummy_codelet;
  75. taskB.regenerate = 1;
  76. starpu_task_init(&taskC);
  77. taskC.cl = &dummy_codelet;
  78. taskC.regenerate = 1;
  79. starpu_task_init(&taskD);
  80. taskD.cl = &dummy_codelet;
  81. taskD.regenerate = 1;
  82. taskD.callback_func = callback_task_D;
  83. struct starpu_task *depsBC_array[1] = {&taskA};
  84. starpu_task_declare_deps_array(&taskB, 1, depsBC_array);
  85. starpu_task_declare_deps_array(&taskC, 1, depsBC_array);
  86. struct starpu_task *depsD_array[2] = {&taskB, &taskC};
  87. starpu_task_declare_deps_array(&taskD, 2, depsD_array);
  88. starpu_submit_task(&taskA);
  89. starpu_submit_task(&taskB);
  90. starpu_submit_task(&taskC);
  91. starpu_submit_task(&taskD);
  92. /* Wait for the termination of all loops */
  93. pthread_mutex_lock(&mutex);
  94. if (loop_cnt < niter)
  95. pthread_cond_wait(&cond, &mutex);
  96. pthread_mutex_unlock(&mutex);
  97. starpu_shutdown();
  98. return 0;
  99. }