empty_task_chain.c 2.0 KB

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