empty_task.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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) 2009-2011,2013,2014,2016 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. * Measure the cost of a task with a NULL codelet
  24. */
  25. #ifdef STARPU_QUICK_CHECK
  26. static unsigned ntasks = 64;
  27. #else
  28. static unsigned ntasks = 65536;
  29. #endif
  30. static void usage(char **argv)
  31. {
  32. FPRINTF(stderr, "%s [-i ntasks] [-h]\n", argv[0]);
  33. exit(-1);
  34. }
  35. static void parse_args(int argc, char **argv)
  36. {
  37. int c;
  38. while ((c = getopt(argc, argv, "i:t:h")) != -1)
  39. switch(c)
  40. {
  41. case 'i':
  42. ntasks = atoi(optarg);
  43. break;
  44. case 'h':
  45. usage(argv);
  46. break;
  47. }
  48. }
  49. int main(int argc, char **argv)
  50. {
  51. int ret;
  52. double timing;
  53. double start;
  54. double end;
  55. parse_args(argc, argv);
  56. ret = starpu_initialize(NULL, &argc, &argv);
  57. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  59. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  60. start = starpu_timing_now();
  61. unsigned i;
  62. for (i = 0; i < ntasks; i++)
  63. {
  64. struct starpu_task *task = starpu_task_create();
  65. task->cl = NULL;
  66. task->detach = 0;
  67. task->destroy = 1;
  68. ret = starpu_task_submit(task);
  69. if (ret == -ENODEV) goto enodev;
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  71. ret = starpu_task_wait(task);
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  73. }
  74. end = starpu_timing_now();
  75. timing = end - start;
  76. FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
  77. FPRINTF(stderr, "Per task: %f usecs\n", timing/ntasks);
  78. starpu_shutdown();
  79. return EXIT_SUCCESS;
  80. enodev:
  81. fprintf(stderr, "WARNING: No one can execute this task\n");
  82. /* yes, we do not perform the computation but we did detect that no one
  83. * could perform the kernel, so this is not an error from StarPU */
  84. starpu_shutdown();
  85. return STARPU_TEST_SKIPPED;
  86. }