starpu_create_sync_task.c 2.5 KB

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