pause_resume.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011, 2013-2014 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <starpu.h>
  20. #include "../helper.h"
  21. #ifdef STARPU_QUICK_CHECK
  22. static unsigned ntasks = 64;
  23. #else
  24. static unsigned ntasks = 200000;
  25. #endif
  26. static void dummy_func(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg STARPU_ATTRIBUTE_UNUSED)
  27. {
  28. }
  29. static struct starpu_codelet dummy_codelet =
  30. {
  31. .cpu_funcs = {dummy_func, NULL},
  32. .cuda_funcs = {dummy_func, NULL},
  33. .opencl_funcs = {dummy_func, NULL},
  34. .model = NULL,
  35. .nbuffers = 0
  36. };
  37. int main(int argc, char **argv)
  38. {
  39. double timing;
  40. double start;
  41. double end;
  42. int ret;
  43. #ifdef STARPU_HAVE_VALGRIND_H
  44. if(RUNNING_ON_VALGRIND) ntasks = 5;
  45. #endif
  46. ret = starpu_init(NULL);
  47. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  48. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  49. /* Check that we can submit tasks to a "paused" StarPU and then have
  50. * it run normally.
  51. */
  52. starpu_pause();
  53. unsigned i;
  54. for (i = 0; i < ntasks; i++)
  55. {
  56. ret = starpu_insert_task(&dummy_codelet, 0);
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  58. }
  59. start = starpu_timing_now();
  60. starpu_resume();
  61. starpu_task_wait_for_all();
  62. end = starpu_timing_now();
  63. timing = end - start;
  64. FPRINTF(stderr, "Without interruptions:\n\tTotal: %f secs\n", timing/1000000);
  65. FPRINTF(stderr, "\tPer task: %f usecs\n", timing/ntasks);
  66. /* Do the same thing, but with a lot of interuptions to see if there
  67. * is any overhead associated with the pause/resume calls.
  68. */
  69. starpu_pause();
  70. for (i = 0; i < ntasks; i++) {
  71. ret = starpu_insert_task(&dummy_codelet, 0);
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  73. }
  74. starpu_resume();
  75. start = starpu_timing_now();
  76. for (i = 0; i < 100; i++) {
  77. starpu_pause();
  78. starpu_resume();
  79. }
  80. starpu_task_wait_for_all();
  81. end = starpu_timing_now();
  82. timing = end - start;
  83. FPRINTF(stderr, "With 100 interruptions:\n\tTotal: %f secs\n", timing/1000000);
  84. FPRINTF(stderr, "\tPer task: %f usecs\n", timing/ntasks);
  85. /* Finally, check that the nesting of pause/resume calls works. */
  86. starpu_pause();
  87. starpu_pause();
  88. starpu_resume();
  89. starpu_resume();
  90. starpu_shutdown();
  91. return EXIT_SUCCESS;
  92. }