starpu_create_sync_task.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU 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. * StarPU 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. #include "../helper.h"
  19. /*
  20. * Test starpu_create_sync_task
  21. */
  22. #define NITER 10
  23. void dummy_func(void *descr[], void *arg)
  24. {
  25. (void)descr;
  26. (void)arg;
  27. }
  28. static struct starpu_codelet dummy_codelet =
  29. {
  30. .cpu_funcs = {dummy_func},
  31. .cuda_funcs = {dummy_func},
  32. .opencl_funcs = {dummy_func},
  33. .cpu_funcs_name = {"dummy_func"},
  34. .nbuffers = 0
  35. };
  36. static int create_dummy_task(starpu_tag_t tag)
  37. {
  38. struct starpu_task *task = starpu_task_create();
  39. task->use_tag = 1;
  40. task->tag_id = tag;
  41. task->cl = &dummy_codelet;
  42. int ret = starpu_task_submit(task);
  43. return ret;
  44. }
  45. int main(int argc, char **argv)
  46. {
  47. int ret;
  48. ret = starpu_initialize(NULL, &argc, &argv);
  49. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  51. starpu_tag_t sync_tags[NITER];
  52. unsigned iter;
  53. for (iter = 0; iter < NITER; iter++)
  54. {
  55. starpu_tag_t sync_tag = (starpu_tag_t)iter*100;
  56. sync_tags[iter] = sync_tag;
  57. unsigned ndeps = 10;
  58. starpu_tag_t deps[ndeps];
  59. unsigned d;
  60. for (d = 0; d < ndeps; d++)
  61. {
  62. deps[d] = sync_tag + d + 1;
  63. ret = create_dummy_task(deps[d]);
  64. if (ret == -ENODEV) goto enodev;
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  66. }
  67. starpu_create_sync_task(sync_tag, ndeps, deps, NULL, NULL);
  68. }
  69. /* Wait all the synchronization tasks */
  70. ret = starpu_tag_wait_array(NITER, sync_tags);
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_tag_wait_array");
  72. starpu_shutdown();
  73. return EXIT_SUCCESS;
  74. enodev:
  75. fprintf(stderr, "WARNING: No one can execute this task\n");
  76. /* yes, we do not perform the computation but we did detect that no one
  77. * could perform the kernel, so this is not an error from StarPU */
  78. starpu_shutdown();
  79. return STARPU_TEST_SKIPPED;
  80. }