starpu_create_sync_task.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  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 <stdio.h>
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. #define NITER 10
  21. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  22. {
  23. }
  24. static struct starpu_codelet dummy_codelet =
  25. {
  26. .cpu_funcs = {dummy_func, NULL},
  27. .cuda_funcs = {dummy_func, NULL},
  28. .opencl_funcs = {dummy_func, NULL},
  29. .nbuffers = 0
  30. };
  31. static int create_dummy_task(starpu_tag_t tag)
  32. {
  33. struct starpu_task *task = starpu_task_create();
  34. task->use_tag = 1;
  35. task->tag_id = tag;
  36. task->cl = &dummy_codelet;
  37. int ret = starpu_task_submit(task);
  38. return ret;
  39. }
  40. int main(int argc, char **argv)
  41. {
  42. int ret;
  43. ret = starpu_init(NULL);
  44. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  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. ret = create_dummy_task(deps[d]);
  59. if (ret == -ENODEV) goto enodev;
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  61. }
  62. starpu_create_sync_task(sync_tag, ndeps, deps, NULL, NULL);
  63. }
  64. /* Wait all the synchronization tasks */
  65. ret = starpu_tag_wait_array(NITER, sync_tags);
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_tag_wait_array");
  67. starpu_shutdown();
  68. return EXIT_SUCCESS;
  69. enodev:
  70. fprintf(stderr, "WARNING: No one can execute this task\n");
  71. /* yes, we do not perform the computation but we did detect that no one
  72. * could perform the kernel, so this is not an error from StarPU */
  73. starpu_shutdown();
  74. return STARPU_TEST_SKIPPED;
  75. }