declare_deps_in_callback.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <pthread.h>
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <starpu.h>
  21. #include "../common/helper.h"
  22. #define NLOOPS 128
  23. static void callback(void *arg)
  24. {
  25. struct starpu_task *taskA, *taskB;
  26. taskA = starpu_get_current_task();
  27. taskB = (struct starpu_task *) arg;
  28. starpu_task_declare_deps_array(taskB, 1, &taskA);
  29. starpu_task_submit(taskB);
  30. }
  31. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  32. {
  33. }
  34. static starpu_codelet dummy_codelet =
  35. {
  36. .where = STARPU_CPU|STARPU_CUDA,
  37. .cpu_func = dummy_func,
  38. .cuda_func = dummy_func,
  39. .model = NULL,
  40. .nbuffers = 0
  41. };
  42. static struct starpu_task *create_dummy_task(void)
  43. {
  44. struct starpu_task *task = starpu_task_create();
  45. task->cl = &dummy_codelet;
  46. task->cl_arg = NULL;
  47. return task;
  48. }
  49. int main(int argc, char **argv)
  50. {
  51. int ret;
  52. unsigned loop;
  53. ret = starpu_init(NULL);
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  55. struct starpu_task *taskA, *taskB;
  56. for (loop = 0; loop < NLOOPS; loop++)
  57. {
  58. taskA = create_dummy_task();
  59. taskB = create_dummy_task();
  60. taskA->callback_func = callback;
  61. taskA->callback_arg = taskB;
  62. ret = starpu_task_submit(taskA);
  63. if (ret == -ENODEV) goto enodev;
  64. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  65. }
  66. ret = starpu_task_wait_for_all();
  67. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  68. starpu_shutdown();
  69. return 0;
  70. enodev:
  71. fprintf(stderr, "WARNING: No one can execute this task\n");
  72. /* yes, we do not perform the computation but we did detect that no one
  73. * could perform the kernel, so this is not an error from StarPU */
  74. starpu_shutdown();
  75. return 77;
  76. }