static_restartable_using_initializer.c 2.7 KB

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