pause_resume.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. * Try starpu_pause/resume
  22. */
  23. #ifdef STARPU_QUICK_CHECK
  24. static unsigned ntasks = 64;
  25. #elif !defined(STARPU_LONG_CHECK)
  26. static unsigned ntasks = 1000;
  27. #else
  28. static unsigned ntasks = 50000;
  29. #endif
  30. void dummy_func(void *descr[], void *arg)
  31. {
  32. (void)descr;
  33. (void)arg;
  34. }
  35. static struct starpu_codelet dummy_codelet =
  36. {
  37. .cpu_funcs = {dummy_func},
  38. .cpu_funcs_name = {"dummy_func"},
  39. .cuda_funcs = {dummy_func},
  40. .opencl_funcs = {dummy_func},
  41. .model = NULL,
  42. .nbuffers = 0
  43. };
  44. int main(void)
  45. {
  46. double timing;
  47. double start;
  48. double end;
  49. int ret;
  50. #ifdef STARPU_HAVE_VALGRIND_H
  51. if(RUNNING_ON_VALGRIND) ntasks = 5;
  52. #endif
  53. ret = starpu_init(NULL);
  54. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  55. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  56. /* Check that we can submit tasks to a "paused" StarPU and then have
  57. * it run normally.
  58. */
  59. starpu_pause();
  60. unsigned i;
  61. for (i = 0; i < ntasks; i++)
  62. {
  63. ret = starpu_task_insert(&dummy_codelet, 0);
  64. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  65. }
  66. start = starpu_timing_now();
  67. starpu_resume();
  68. starpu_task_wait_for_all();
  69. end = starpu_timing_now();
  70. timing = end - start;
  71. FPRINTF(stderr, "Without interruptions:\n\tTotal: %f secs\n", timing/1000000);
  72. FPRINTF(stderr, "\tPer task: %f usecs\n", timing/ntasks);
  73. /* Do the same thing, but with a lot of interuptions to see if there
  74. * is any overhead associated with the pause/resume calls.
  75. */
  76. starpu_pause();
  77. for (i = 0; i < ntasks; i++)
  78. {
  79. ret = starpu_task_insert(&dummy_codelet, 0);
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  81. }
  82. starpu_resume();
  83. start = starpu_timing_now();
  84. for (i = 0; i < 100; i++)
  85. {
  86. starpu_pause();
  87. starpu_resume();
  88. }
  89. starpu_task_wait_for_all();
  90. end = starpu_timing_now();
  91. timing = end - start;
  92. FPRINTF(stderr, "With 100 interruptions:\n\tTotal: %f secs\n", timing/1000000);
  93. FPRINTF(stderr, "\tPer task: %f usecs\n", timing/ntasks);
  94. /* Finally, check that the nesting of pause/resume calls works. */
  95. starpu_pause();
  96. starpu_pause();
  97. starpu_resume();
  98. starpu_resume();
  99. starpu_shutdown();
  100. return EXIT_SUCCESS;
  101. }