get_current_task.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 = 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 = 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. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  49. int i;
  50. for (i = 0; i < ntasks; i++)
  51. {
  52. struct starpu_task *task = starpu_task_create();
  53. /* We check if the function is valid from the codelet or from
  54. * the callback */
  55. task->cl = &dummy_cl;
  56. task->cl_arg = task;
  57. task->callback_func = check_task_callback;
  58. task->callback_arg = task;
  59. int ret = starpu_task_submit(task);
  60. STARPU_ASSERT(!ret);
  61. }
  62. starpu_task_wait_for_all();
  63. FPRINTF(stderr, "#empty tasks : %u\n", ntasks);
  64. /* We repeat the same experiment with null codelets */
  65. for (i = 0; i < ntasks; i++)
  66. {
  67. struct starpu_task *task = starpu_task_create();
  68. task->cl = NULL;
  69. /* We check if the function is valid from the callback */
  70. task->callback_func = check_task_callback;
  71. task->callback_arg = task;
  72. int ret = starpu_task_submit(task);
  73. STARPU_ASSERT(!ret);
  74. }
  75. starpu_task_wait_for_all();
  76. starpu_shutdown();
  77. return 0;
  78. }