starpu_create_sync_task.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 <stdio.h>
  17. #include <starpu.h>
  18. #define NITER 10
  19. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  20. {
  21. }
  22. static starpu_codelet dummy_codelet =
  23. {
  24. .where = STARPU_CPU|STARPU_CUDA,
  25. .cpu_func = dummy_func,
  26. .cuda_func = dummy_func,
  27. .nbuffers = 0
  28. };
  29. static create_dummy_task(starpu_tag_t tag)
  30. {
  31. struct starpu_task *task = starpu_task_create();
  32. task->use_tag = 1;
  33. task->tag_id = tag;
  34. task->cl = &dummy_codelet;
  35. int ret = starpu_submit_task(task);
  36. if (ret)
  37. {
  38. fprintf(stderr, "Warning, no worker can execute the tasks\n");
  39. /* This is not a bug from StarPU so we return a valid value. */
  40. exit(0);
  41. }
  42. }
  43. int main(int argc, char **argv)
  44. {
  45. starpu_init(NULL);
  46. starpu_tag_t sync_tags[NITER];
  47. unsigned iter;
  48. for (iter = 0; iter < NITER; iter++)
  49. {
  50. starpu_tag_t sync_tag = (starpu_tag_t)iter*100;
  51. sync_tags[iter] = sync_tag;
  52. unsigned ndeps = 10;
  53. starpu_tag_t deps[ndeps];
  54. unsigned d;
  55. for (d = 0; d < ndeps; d++)
  56. {
  57. deps[d] = sync_tag + d + 1;
  58. create_dummy_task(deps[d]);
  59. }
  60. starpu_create_sync_task(sync_tag, ndeps, deps, NULL, NULL);
  61. }
  62. /* Wait all the synchronization tasks */
  63. starpu_tag_wait_array(NITER, sync_tags);
  64. starpu_shutdown();
  65. return 0;
  66. }