wait_all_regenerable_tasks.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <stdio.h>
  18. #include <unistd.h>
  19. #include <pthread.h>
  20. #include <starpu.h>
  21. static unsigned ntasks = 1024;
  22. static void callback(void *arg)
  23. {
  24. struct starpu_task *task = starpu_get_current_task();
  25. unsigned *cnt = arg;
  26. (*cnt)++;
  27. if (*cnt == ntasks)
  28. task->regenerate = 0;
  29. }
  30. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  31. {
  32. }
  33. static starpu_codelet dummy_codelet =
  34. {
  35. .where = STARPU_CPU|STARPU_CUDA,
  36. .cpu_func = dummy_func,
  37. .cuda_func = dummy_func,
  38. .model = NULL,
  39. .nbuffers = 0
  40. };
  41. static void parse_args(int argc, char **argv)
  42. {
  43. int c;
  44. while ((c = getopt(argc, argv, "i:")) != -1)
  45. switch(c) {
  46. case 'i':
  47. ntasks = atoi(optarg);
  48. break;
  49. }
  50. }
  51. #define K 128
  52. int main(int argc, char **argv)
  53. {
  54. double timing;
  55. struct timeval start;
  56. struct timeval end;
  57. parse_args(argc, argv);
  58. starpu_init(NULL);
  59. struct starpu_task task[K];
  60. unsigned cnt[K];;
  61. int i;
  62. for (i = 0; i < K; i++)
  63. {
  64. starpu_task_init(&task[i]);
  65. cnt[i] = 0;
  66. task[i].cl = &dummy_codelet;
  67. task[i].regenerate = 1;
  68. task[i].detach = 1;
  69. task[i].callback_func = callback;
  70. task[i].callback_arg = &cnt[i];
  71. }
  72. fprintf(stderr, "#tasks : %d x %d tasks\n", K, ntasks);
  73. gettimeofday(&start, NULL);
  74. for (i = 0; i < K; i++)
  75. starpu_task_submit(&task[i]);
  76. starpu_task_wait_for_all();
  77. gettimeofday(&end, NULL);
  78. /* Check that all the tasks have been properly executed */
  79. unsigned total_cnt = 0;
  80. for (i = 0; i < K; i++)
  81. total_cnt += cnt[i];
  82. STARPU_ASSERT(total_cnt == K*ntasks);
  83. timing = (double)((end.tv_sec - start.tv_sec)*1000000
  84. + (end.tv_usec - start.tv_usec));
  85. fprintf(stderr, "Total: %lf secs\n", timing/1000000);
  86. fprintf(stderr, "Per task: %lf usecs\n", timing/(K*ntasks));
  87. starpu_shutdown();
  88. return 0;
  89. }