starpu_create_sync_task.c 2.4 KB

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