get_current_task.c 2.3 KB

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