empty_task_chain.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 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. ret = starpu_task_submit(tasks[i]);
  39. if (ret == -ENODEV) goto enodev;
  40. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  41. }
  42. if (i == (N-1))
  43. tasks[i]->detach = 0;
  44. }
  45. ret = starpu_task_submit(tasks[0]);
  46. if (ret == -ENODEV) goto enodev;
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  48. ret = starpu_task_wait(tasks[N-1]);
  49. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  50. starpu_shutdown();
  51. free(tasks);
  52. return EXIT_SUCCESS;
  53. enodev:
  54. fprintf(stderr, "WARNING: No one can execute this task\n");
  55. /* yes, we do not perform the computation but we did detect that no one
  56. * could perform the kernel, so this is not an error from StarPU */
  57. starpu_shutdown();
  58. return STARPU_TEST_SKIPPED;
  59. }