task_end_dep_add.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2018-2020 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. /* This shows how to defer termination of a task thanks to
  17. * starpu_task_end_dep_add. */
  18. #include <starpu.h>
  19. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  20. #define INIT 12
  21. void cpu_codelet2(void *descr[], void *args)
  22. {
  23. (void)descr;
  24. (void)args;
  25. }
  26. struct starpu_codelet cl2 =
  27. {
  28. .cpu_funcs = {cpu_codelet2},
  29. .cpu_funcs_name = {"cpu_codelet2"},
  30. .name = "codelet2"
  31. };
  32. void cpu_codelet(void *descr[], void *args)
  33. {
  34. (void)args;
  35. int *val = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  36. struct starpu_task *task;
  37. task = starpu_task_get_current();
  38. starpu_task_end_dep_add(task, 1);
  39. starpu_task_insert(&cl2,
  40. STARPU_CALLBACK_WITH_ARG_NFREE, starpu_task_end_dep_release, task,
  41. 0);
  42. STARPU_ASSERT(*val == INIT);
  43. *val *= 2;
  44. }
  45. struct starpu_codelet cl =
  46. {
  47. .cpu_funcs = {cpu_codelet},
  48. .cpu_funcs_name = {"cpu_codelet"},
  49. .nbuffers = 1,
  50. .modes = {STARPU_RW},
  51. .name = "codelet"
  52. };
  53. int main(void)
  54. {
  55. int value=INIT;
  56. int ret;
  57. starpu_data_handle_t value_handle;
  58. struct starpu_conf conf;
  59. starpu_conf_init(&conf);
  60. conf.nmic = 0;
  61. conf.nmpi_ms = 0;
  62. ret = starpu_init(&conf);
  63. if (STARPU_UNLIKELY(ret == -ENODEV))
  64. {
  65. return 77;
  66. }
  67. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  68. if (starpu_cpu_worker_get_count() < 1)
  69. {
  70. FPRINTF(stderr, "This application requires at least 1 cpu worker\n");
  71. starpu_shutdown();
  72. return 77;
  73. }
  74. starpu_variable_data_register(&value_handle, STARPU_MAIN_RAM, (uintptr_t)&value, sizeof(value));
  75. ret = starpu_task_insert(&cl,
  76. STARPU_RW, value_handle,
  77. 0);
  78. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  79. starpu_data_unregister(value_handle);
  80. STARPU_ASSERT(value == 2*INIT);
  81. starpu_shutdown();
  82. FPRINTF(stderr, "Value = %d\n", value);
  83. return ret;
  84. }