empty_task_chain.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU 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. * StarPU 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 <starpu.h>
  17. #include "../helper.h"
  18. /*
  19. * Create a chain of tasks with NULL codelet, using manual dependencies
  20. */
  21. #define N 4
  22. int main(int argc, char **argv)
  23. {
  24. int i, ret;
  25. ret = starpu_initialize(NULL, &argc, &argv);
  26. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  27. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  28. struct starpu_task **tasks = (struct starpu_task **) malloc(N*sizeof(struct starpu_task *));
  29. for (i = 0; i < N; i++)
  30. {
  31. tasks[i] = starpu_task_create();
  32. tasks[i]->cl = NULL;
  33. if (i > 0)
  34. {
  35. starpu_task_declare_deps_array(tasks[i], 1, &tasks[i-1]);
  36. }
  37. if (i == (N-1))
  38. tasks[i]->detach = 0;
  39. }
  40. for (i = 1; i < N; i++)
  41. {
  42. ret = starpu_task_submit(tasks[i]);
  43. if (ret == -ENODEV) goto enodev;
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  45. }
  46. ret = starpu_task_submit(tasks[0]);
  47. if (ret == -ENODEV) goto enodev;
  48. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  49. ret = starpu_task_wait(tasks[N-1]);
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  51. starpu_shutdown();
  52. free(tasks);
  53. return EXIT_SUCCESS;
  54. enodev:
  55. fprintf(stderr, "WARNING: No one can execute this task\n");
  56. /* yes, we do not perform the computation but we did detect that no one
  57. * could perform the kernel, so this is not an error from StarPU */
  58. starpu_shutdown();
  59. return STARPU_TEST_SKIPPED;
  60. }