insert_task_owner.c 5.6 KB

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