empty_task.c 1.8 KB

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