wait_all_regenerable_tasks.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Inria
  4. * Copyright (C) 2010-2013,2015,2017 CNRS
  5. * Copyright (C) 2010-2011,2013-2014,2016-2017 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <starpu.h>
  21. #include "../helper.h"
  22. /*
  23. * Test that starpu_task_wait_for_all can work with a regenerating task
  24. */
  25. #ifdef STARPU_QUICK_CHECK
  26. static unsigned ntasks = 64;
  27. #else
  28. static unsigned ntasks = 1024;
  29. #endif
  30. static void callback(void *arg)
  31. {
  32. struct starpu_task *task = starpu_task_get_current();
  33. unsigned *cnt = (unsigned *) arg;
  34. (*cnt)++;
  35. if (*cnt == ntasks)
  36. task->regenerate = 0;
  37. }
  38. void dummy_func(void *descr[], void *arg)
  39. {
  40. (void)descr;
  41. (void)arg;
  42. }
  43. static struct starpu_codelet dummy_codelet =
  44. {
  45. .cpu_funcs = {dummy_func},
  46. .cuda_funcs = {dummy_func},
  47. .opencl_funcs = {dummy_func},
  48. .cpu_funcs_name = {"dummy_func"},
  49. .model = NULL,
  50. .nbuffers = 0
  51. };
  52. static void parse_args(int argc, char **argv)
  53. {
  54. int c;
  55. while ((c = getopt(argc, argv, "i:")) != -1)
  56. switch(c)
  57. {
  58. case 'i':
  59. ntasks = atoi(optarg);
  60. break;
  61. }
  62. }
  63. #define K 128
  64. int main(int argc, char **argv)
  65. {
  66. int ret;
  67. double timing;
  68. double start;
  69. double end;
  70. parse_args(argc, argv);
  71. ret = starpu_initialize(NULL, &argc, &argv);
  72. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  73. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  74. struct starpu_task task[K];
  75. unsigned cnt[K];
  76. int i;
  77. for (i = 0; i < K; i++)
  78. {
  79. starpu_task_init(&task[i]);
  80. cnt[i] = 0;
  81. task[i].cl = &dummy_codelet;
  82. task[i].regenerate = 1;
  83. task[i].detach = 1;
  84. task[i].callback_func = callback;
  85. task[i].callback_arg = &cnt[i];
  86. }
  87. FPRINTF(stderr, "#tasks : %d x %u tasks\n", K, ntasks);
  88. start = starpu_timing_now();
  89. for (i = 0; i < K; i++)
  90. {
  91. ret = starpu_task_submit(&task[i]);
  92. if (ret == -ENODEV) goto enodev;
  93. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  94. }
  95. ret = starpu_task_wait_for_all();
  96. for (i = 0; i < K; i++)
  97. starpu_task_clean(&task[i]);
  98. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  99. end = starpu_timing_now();
  100. /* Check that all the tasks have been properly executed */
  101. unsigned total_cnt = 0;
  102. for (i = 0; i < K; i++)
  103. total_cnt += cnt[i];
  104. STARPU_ASSERT(total_cnt == K*ntasks);
  105. timing = end - start;
  106. FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
  107. FPRINTF(stderr, "Per task: %f usecs\n", timing/(K*ntasks));
  108. starpu_shutdown();
  109. return EXIT_SUCCESS;
  110. enodev:
  111. fprintf(stderr, "WARNING: No one can execute this task\n");
  112. /* yes, we do not perform the computation but we did detect that no one
  113. * could perform the kernel, so this is not an error from StarPU */
  114. starpu_shutdown();
  115. return STARPU_TEST_SKIPPED;
  116. }