declare_deps_in_callback.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #define NLOOPS 128
  22. static void callback(void *arg)
  23. {
  24. struct starpu_task *taskA, *taskB;
  25. taskA = starpu_get_current_task();
  26. taskB = arg;
  27. starpu_task_declare_deps_array(taskB, 1, &taskA);
  28. starpu_task_submit(taskB);
  29. }
  30. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  31. {
  32. }
  33. static starpu_codelet dummy_codelet =
  34. {
  35. .where = STARPU_CPU|STARPU_CUDA,
  36. .cpu_func = dummy_func,
  37. .cuda_func = dummy_func,
  38. .model = NULL,
  39. .nbuffers = 0
  40. };
  41. static struct starpu_task *create_dummy_task(void)
  42. {
  43. struct starpu_task *task = starpu_task_create();
  44. task->cl = &dummy_codelet;
  45. task->cl_arg = NULL;
  46. return task;
  47. }
  48. int main(int argc, char **argv)
  49. {
  50. // int ret;
  51. unsigned loop;
  52. starpu_init(NULL);
  53. struct starpu_task *taskA, *taskB;
  54. for (loop = 0; loop < NLOOPS; loop++)
  55. {
  56. taskA = create_dummy_task();
  57. taskB = create_dummy_task();
  58. taskA->callback_func = callback;
  59. taskA->callback_arg = taskB;
  60. starpu_task_submit(taskA);
  61. }
  62. starpu_task_wait_for_all();
  63. starpu_shutdown();
  64. return 0;
  65. }