empty_task.c 2.0 KB

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