empty_task.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 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 <sys/time.h>
  18. #include <pthread.h>
  19. #include <stdio.h>
  20. #include <unistd.h>
  21. #include <starpu.h>
  22. static unsigned ntasks = 65536;
  23. static void usage(char **argv)
  24. {
  25. fprintf(stderr, "%s [-i ntasks] [-h]\n", argv[0]);
  26. exit(-1);
  27. }
  28. static void parse_args(int argc, char **argv)
  29. {
  30. int c;
  31. while ((c = getopt(argc, argv, "i:t:h")) != -1)
  32. switch(c) {
  33. case 'i':
  34. ntasks = atoi(optarg);
  35. break;
  36. case 'h':
  37. usage(argv);
  38. break;
  39. }
  40. }
  41. int main(int argc, char **argv)
  42. {
  43. double timing;
  44. struct timeval start;
  45. struct timeval end;
  46. parse_args(argc, argv);
  47. starpu_init(NULL);
  48. fprintf(stderr, "#tasks : %d\n", ntasks);
  49. gettimeofday(&start, NULL);
  50. int i;
  51. for (i = 0; i < ntasks; i++)
  52. {
  53. struct starpu_task *task = starpu_task_create();
  54. task->cl = NULL;
  55. task->detach = 0;
  56. task->destroy = 1;
  57. int ret = starpu_task_submit(task);
  58. STARPU_ASSERT(!ret);
  59. starpu_task_wait(task);
  60. }
  61. gettimeofday(&end, NULL);
  62. timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  63. fprintf(stderr, "Total: %lf secs\n", timing/1000000);
  64. fprintf(stderr, "Per task: %lf usecs\n", timing/ntasks);
  65. starpu_shutdown();
  66. return 0;
  67. }