empty_task_chain.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Inria
  4. * Copyright (C) 2010-2012,2015,2017 CNRS
  5. * Copyright (C) 2010,2013,2014,2016,2018 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Create a chain of tasks with NULL codelet, using manual dependencies
  22. */
  23. #define N 4
  24. int main(int argc, char **argv)
  25. {
  26. int i, ret;
  27. ret = starpu_initialize(NULL, &argc, &argv);
  28. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  29. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  30. struct starpu_task **tasks = (struct starpu_task **) malloc(N*sizeof(struct starpu_task *));
  31. for (i = 0; i < N; i++)
  32. {
  33. tasks[i] = starpu_task_create();
  34. tasks[i]->cl = NULL;
  35. if (i > 0)
  36. {
  37. starpu_task_declare_deps_array(tasks[i], 1, &tasks[i-1]);
  38. }
  39. if (i == (N-1))
  40. tasks[i]->detach = 0;
  41. }
  42. for (i = 1; i < N; i++)
  43. {
  44. ret = starpu_task_submit(tasks[i]);
  45. if (ret == -ENODEV) goto enodev;
  46. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  47. }
  48. ret = starpu_task_submit(tasks[0]);
  49. if (ret == -ENODEV) goto enodev;
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  51. ret = starpu_task_wait(tasks[N-1]);
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  53. starpu_shutdown();
  54. free(tasks);
  55. return EXIT_SUCCESS;
  56. enodev:
  57. fprintf(stderr, "WARNING: No one can execute this task\n");
  58. /* yes, we do not perform the computation but we did detect that no one
  59. * could perform the kernel, so this is not an error from StarPU */
  60. starpu_shutdown();
  61. return STARPU_TEST_SKIPPED;
  62. }