task_end_dep_add.c 2.5 KB

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