insert_task_owner.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012 Centre National de la Recherche Scientifique
  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. #include <starpu_mpi.h>
  17. #include <math.h>
  18. #include "helper.h"
  19. void func_cpu(void *descr[], __attribute__ ((unused)) void *_args)
  20. {
  21. int *x = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. int *y = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  23. *x = *x + 1;
  24. *y = *y + 1;
  25. }
  26. struct starpu_codelet mycodelet_r_w =
  27. {
  28. .where = STARPU_CPU,
  29. .cpu_funcs = {func_cpu, NULL},
  30. .nbuffers = 2,
  31. .modes = {STARPU_R, STARPU_W}
  32. };
  33. struct starpu_codelet mycodelet_rw_r =
  34. {
  35. .where = STARPU_CPU,
  36. .cpu_funcs = {func_cpu, NULL},
  37. .nbuffers = 2,
  38. .modes = {STARPU_RW, STARPU_R}
  39. };
  40. struct starpu_codelet mycodelet_rw_rw =
  41. {
  42. .where = STARPU_CPU,
  43. .cpu_funcs = {func_cpu, NULL},
  44. .nbuffers = 2,
  45. .modes = {STARPU_RW, STARPU_RW}
  46. };
  47. struct starpu_codelet mycodelet_w_r =
  48. {
  49. .where = STARPU_CPU,
  50. .cpu_funcs = {func_cpu, NULL},
  51. .nbuffers = 2,
  52. .modes = {STARPU_W, STARPU_R}
  53. };
  54. #define ACQUIRE_DATA \
  55. if (rank == 0) starpu_data_acquire(data_handlesx0, STARPU_R); \
  56. if (rank == 1) starpu_data_acquire(data_handlesx1, STARPU_R); \
  57. FPRINTF(stderr, "[%d] Values: %d %d\n", rank, x0, x1);
  58. #define RELEASE_DATA \
  59. if (rank == 0) starpu_data_release(data_handlesx0); \
  60. if (rank == 1) starpu_data_release(data_handlesx1); \
  61. #define CHECK_RESULT \
  62. if (rank == 0) assert(x0 == vx0[0] && x1 == vx1[0]); \
  63. if (rank == 1) assert(x0 == vx0[1] && x1 == vx1[1]);
  64. int main(int argc, char **argv)
  65. {
  66. int ret, rank, size, err;
  67. int x0=0, x1=0, vx0[2] = {x0, x0}, vx1[2]={x1,x1};
  68. starpu_data_handle_t data_handlesx0;
  69. starpu_data_handle_t data_handlesx1;
  70. ret = starpu_init(NULL);
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  72. ret = starpu_mpi_initialize_extended(&rank, &size);
  73. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_initialize_extended");
  74. if (size != 2)
  75. {
  76. if (rank == 0) FPRINTF(stderr, "We need exactly 2 processes.\n");
  77. starpu_mpi_shutdown();
  78. starpu_shutdown();
  79. return STARPU_TEST_SKIPPED;
  80. }
  81. if (rank == 0)
  82. {
  83. starpu_variable_data_register(&data_handlesx0, 0, (uintptr_t)&x0, sizeof(x0));
  84. starpu_data_set_rank(data_handlesx0, rank);
  85. starpu_data_set_tag(data_handlesx0, 0);
  86. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(int));
  87. starpu_data_set_rank(data_handlesx1, 1);
  88. starpu_data_set_tag(data_handlesx1, 1);
  89. }
  90. else if (rank == 1)
  91. {
  92. starpu_variable_data_register(&data_handlesx1, 0, (uintptr_t)&x1, sizeof(x1));
  93. starpu_data_set_rank(data_handlesx1, rank);
  94. starpu_data_set_tag(data_handlesx1, 1);
  95. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(int));
  96. starpu_data_set_rank(data_handlesx0, 0);
  97. starpu_data_set_tag(data_handlesx0, 0);
  98. }
  99. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_r_w, STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, 0);
  100. assert(err == 0);
  101. ACQUIRE_DATA;
  102. vx1[1]++;
  103. CHECK_RESULT;
  104. RELEASE_DATA;
  105. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_rw_r, STARPU_RW, data_handlesx0, STARPU_R, data_handlesx1, 0);
  106. assert(err == 0);
  107. ACQUIRE_DATA;
  108. vx0[0] ++;
  109. CHECK_RESULT;
  110. RELEASE_DATA;
  111. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_rw_rw, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, 0);
  112. assert(err == -EINVAL);
  113. ACQUIRE_DATA;
  114. CHECK_RESULT;
  115. RELEASE_DATA;
  116. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_rw_rw, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, 1, 0);
  117. assert(err == 0);
  118. ACQUIRE_DATA;
  119. vx0[0] ++ ; vx1[1] ++;
  120. CHECK_RESULT;
  121. RELEASE_DATA;
  122. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_rw_rw, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, 0, 0);
  123. assert(err == 0);
  124. ACQUIRE_DATA;
  125. vx0[0] ++ ; vx1[1] ++;
  126. CHECK_RESULT;
  127. RELEASE_DATA;
  128. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  129. going to be ignored as the data model clearly specifies
  130. which task is going to execute the codelet */
  131. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_r_w, STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, STARPU_EXECUTE_ON_NODE, 12, 0);
  132. assert(err == 0);
  133. ACQUIRE_DATA;
  134. vx1[1] ++;
  135. CHECK_RESULT;
  136. RELEASE_DATA;
  137. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  138. going to be ignored as the data model clearly specifies
  139. which task is going to execute the codelet */
  140. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_w_r, STARPU_W, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE_ON_NODE, 11, 0);
  141. assert(err == 0);
  142. ACQUIRE_DATA;
  143. vx0[0] ++;
  144. CHECK_RESULT;
  145. RELEASE_DATA;
  146. starpu_task_wait_for_all();
  147. starpu_mpi_shutdown();
  148. starpu_shutdown();
  149. return 0;
  150. }