get_current_task.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 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 <stdio.h>
  19. #include <unistd.h>
  20. #include <starpu.h>
  21. #define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
  22. static unsigned ntasks = 65536;
  23. static void check_task_func(void *descr[], void *arg)
  24. {
  25. /* We check that the returned task is valid from the codelet */
  26. struct starpu_task *task = (struct starpu_task *) arg;
  27. STARPU_ASSERT(task == starpu_get_current_task());
  28. }
  29. static void check_task_callback(void *arg)
  30. {
  31. /* We check that the returned task is valid from the callback */
  32. struct starpu_task *task = (struct starpu_task *) arg;
  33. STARPU_ASSERT(task == starpu_get_current_task());
  34. }
  35. static struct starpu_codelet_t dummy_cl = {
  36. .where = STARPU_CUDA|STARPU_CPU,
  37. .cuda_func = check_task_func,
  38. .cpu_func = check_task_func,
  39. .model = NULL,
  40. .nbuffers = 0
  41. };
  42. int main(int argc, char **argv)
  43. {
  44. // double timing;
  45. // struct timeval start;
  46. // struct timeval end;
  47. starpu_init(NULL);
  48. #ifdef STARPU_SLOW_MACHINE
  49. ntasks /= 10;
  50. #endif
  51. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  52. int i;
  53. for (i = 0; i < ntasks; i++)
  54. {
  55. struct starpu_task *task = starpu_task_create();
  56. /* We check if the function is valid from the codelet or from
  57. * the callback */
  58. task->cl = &dummy_cl;
  59. task->cl_arg = task;
  60. task->callback_func = check_task_callback;
  61. task->callback_arg = task;
  62. int ret = starpu_task_submit(task);
  63. STARPU_ASSERT(!ret);
  64. }
  65. starpu_task_wait_for_all();
  66. FPRINTF(stderr, "#empty tasks : %u\n", ntasks);
  67. /* We repeat the same experiment with null codelets */
  68. for (i = 0; i < ntasks; i++)
  69. {
  70. struct starpu_task *task = starpu_task_create();
  71. task->cl = NULL;
  72. /* We check if the function is valid from the callback */
  73. task->callback_func = check_task_callback;
  74. task->callback_arg = task;
  75. int ret = starpu_task_submit(task);
  76. STARPU_ASSERT(!ret);
  77. }
  78. starpu_task_wait_for_all();
  79. starpu_shutdown();
  80. return 0;
  81. }