get_current_task.c 2.3 KB

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