get_current_task.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. static unsigned ntasks = 65536;
  22. static void check_task_func(void *descr[], void *arg)
  23. {
  24. /* We check that the returned task is valid from the codelet */
  25. struct starpu_task *task = arg;
  26. STARPU_ASSERT(task == starpu_get_current_task());
  27. }
  28. static void check_task_callback(void *arg)
  29. {
  30. /* We check that the returned task is valid from the callback */
  31. struct starpu_task *task = arg;
  32. STARPU_ASSERT(task == starpu_get_current_task());
  33. }
  34. static struct starpu_codelet_t dummy_cl = {
  35. .where = STARPU_CUDA|STARPU_CPU,
  36. .cuda_func = check_task_func,
  37. .cpu_func = check_task_func,
  38. .model = NULL,
  39. .nbuffers = 0
  40. };
  41. int main(int argc, char **argv)
  42. {
  43. // double timing;
  44. // struct timeval start;
  45. // struct timeval end;
  46. starpu_init(NULL);
  47. fprintf(stderr, "#tasks : %d\n", ntasks);
  48. int i;
  49. for (i = 0; i < ntasks; i++)
  50. {
  51. struct starpu_task *task = starpu_task_create();
  52. /* We check if the function is valid from the codelet or from
  53. * the callback */
  54. task->cl = &dummy_cl;
  55. task->cl_arg = task;
  56. task->callback_func = check_task_callback;
  57. task->callback_arg = task;
  58. int ret = starpu_task_submit(task);
  59. STARPU_ASSERT(!ret);
  60. }
  61. starpu_task_wait_for_all();
  62. fprintf(stderr, "#empty tasks : %d\n", ntasks);
  63. /* We repeat the same experiment with null codelets */
  64. for (i = 0; i < ntasks; i++)
  65. {
  66. struct starpu_task *task = starpu_task_create();
  67. task->cl = NULL;
  68. /* We check if the function is valid from the callback */
  69. task->callback_func = check_task_callback;
  70. task->callback_arg = task;
  71. int ret = starpu_task_submit(task);
  72. STARPU_ASSERT(!ret);
  73. }
  74. starpu_task_wait_for_all();
  75. starpu_shutdown();
  76. return 0;
  77. }