starpu_create_sync_task.c 2.5 KB

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