starpu_task_wait.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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. #include <stdio.h>
  17. #include <unistd.h>
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Test waiting for a task
  22. */
  23. #ifdef STARPU_QUICK_CHECK
  24. static unsigned ntasks = 64;
  25. #else
  26. static unsigned ntasks = 65536;
  27. #endif
  28. void dummy_func(void *descr[], void *arg)
  29. {
  30. (void)descr;
  31. (void)arg;
  32. }
  33. static struct starpu_codelet dummy_codelet =
  34. {
  35. .cpu_funcs = {dummy_func},
  36. .cuda_funcs = {dummy_func},
  37. .opencl_funcs = {dummy_func},
  38. .cpu_funcs_name = {"dummy_func"},
  39. .model = NULL,
  40. .nbuffers = 0
  41. };
  42. static void usage(char **argv)
  43. {
  44. FPRINTF(stderr, "%s [-i ntasks] [-h]\n", argv[0]);
  45. exit(-1);
  46. }
  47. static void parse_args(int argc, char **argv)
  48. {
  49. int c;
  50. while ((c = getopt(argc, argv, "i:t:h")) != -1)
  51. switch(c)
  52. {
  53. case 'i':
  54. ntasks = atoi(optarg);
  55. break;
  56. case 'h':
  57. usage(argv);
  58. break;
  59. }
  60. }
  61. int main(int argc, char **argv)
  62. {
  63. double timing;
  64. double start;
  65. double end;
  66. int ret;
  67. parse_args(argc, argv);
  68. #ifdef STARPU_HAVE_VALGRIND_H
  69. if(RUNNING_ON_VALGRIND) ntasks = 5;
  70. #endif
  71. ret = starpu_initialize(NULL, &argc, &argv);
  72. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  73. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  74. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  75. start = starpu_timing_now();
  76. unsigned i;
  77. for (i = 0; i < ntasks; i++)
  78. {
  79. struct starpu_task *task = starpu_task_create();
  80. task->cl = &dummy_codelet;
  81. task->cl_arg = NULL;
  82. task->callback_func = NULL;
  83. task->callback_arg = NULL;
  84. task->detach = 0;
  85. task->destroy = 0;
  86. ret = starpu_task_submit(task);
  87. if (ret == -ENODEV) goto enodev;
  88. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  89. ret = starpu_task_wait(task);
  90. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  91. starpu_task_destroy(task);
  92. }
  93. end = starpu_timing_now();
  94. timing = end - start;
  95. FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
  96. FPRINTF(stderr, "Per task: %f usecs\n", timing/ntasks);
  97. starpu_shutdown();
  98. return EXIT_SUCCESS;
  99. enodev:
  100. fprintf(stderr, "WARNING: No one can execute this task\n");
  101. /* yes, we do not perform the computation but we did detect that no one
  102. * could perform the kernel, so this is not an error from StarPU */
  103. starpu_shutdown();
  104. return STARPU_TEST_SKIPPED;
  105. }