insert_task_owner.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Inria
  4. * Copyright (C) 2011-2017 CNRS
  5. * Copyright (C) 2013-2015,2017,2018 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu_mpi.h>
  19. #include <math.h>
  20. #include "helper.h"
  21. void func_cpu(void *descr[], void *_args)
  22. {
  23. int node;
  24. int rank;
  25. (void)descr;
  26. starpu_codelet_unpack_args(_args, &node);
  27. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  28. FPRINTF_MPI(stderr, "Expected node: %d - Actual node: %d\n", node, rank);
  29. assert(node == rank);
  30. }
  31. struct starpu_codelet mycodelet_r_w =
  32. {
  33. .cpu_funcs = {func_cpu},
  34. .nbuffers = 2,
  35. .modes = {STARPU_R, STARPU_W},
  36. .model = &starpu_perfmodel_nop,
  37. };
  38. struct starpu_codelet mycodelet_rw_r =
  39. {
  40. .cpu_funcs = {func_cpu},
  41. .nbuffers = 2,
  42. .modes = {STARPU_RW, STARPU_R},
  43. .model = &starpu_perfmodel_nop,
  44. };
  45. struct starpu_codelet mycodelet_rw_rw =
  46. {
  47. .cpu_funcs = {func_cpu},
  48. .nbuffers = 2,
  49. .modes = {STARPU_RW, STARPU_RW},
  50. .model = &starpu_perfmodel_nop,
  51. };
  52. struct starpu_codelet mycodelet_w_r =
  53. {
  54. .cpu_funcs = {func_cpu},
  55. .nbuffers = 2,
  56. .modes = {STARPU_W, STARPU_R},
  57. .model = &starpu_perfmodel_nop,
  58. };
  59. struct starpu_codelet mycodelet_r_r =
  60. {
  61. .cpu_funcs = {func_cpu},
  62. .nbuffers = 2,
  63. .modes = {STARPU_R, STARPU_R},
  64. .model = &starpu_perfmodel_nop,
  65. };
  66. int main(int argc, char **argv)
  67. {
  68. int ret, rank, size, err, node;
  69. long x0=32;
  70. int x1=23;
  71. starpu_data_handle_t data_handlesx0 = NULL;
  72. starpu_data_handle_t data_handlesx1 = NULL;
  73. ret = starpu_mpi_init_conf(&argc, &argv, 1, MPI_COMM_WORLD, NULL);
  74. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  75. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  76. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  77. if (starpu_cpu_worker_get_count() == 0)
  78. {
  79. if (rank == 0)
  80. FPRINTF(stderr, "We need at least 1 CPU worker.\n");
  81. starpu_mpi_shutdown();
  82. return STARPU_TEST_SKIPPED;
  83. }
  84. if (rank != 0 && rank != 1)
  85. goto end;
  86. if (rank == 0)
  87. {
  88. starpu_variable_data_register(&data_handlesx0, STARPU_MAIN_RAM, (uintptr_t)&x0, sizeof(x0));
  89. starpu_mpi_data_register(data_handlesx0, 0, rank);
  90. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(x1));
  91. starpu_mpi_data_register(data_handlesx1, 1, 1);
  92. }
  93. else if (rank == 1)
  94. {
  95. starpu_variable_data_register(&data_handlesx1, STARPU_MAIN_RAM, (uintptr_t)&x1, sizeof(x1));
  96. starpu_mpi_data_register(data_handlesx1, 1, rank);
  97. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(x0));
  98. starpu_mpi_data_register(data_handlesx0, 0, 0);
  99. }
  100. node = starpu_mpi_data_get_rank(data_handlesx1);
  101. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_w,
  102. STARPU_VALUE, &node, sizeof(node),
  103. STARPU_R, data_handlesx0, STARPU_W, data_handlesx1,
  104. 0);
  105. assert(err == 0);
  106. node = starpu_mpi_data_get_rank(data_handlesx0);
  107. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_r,
  108. STARPU_VALUE, &node, sizeof(node),
  109. STARPU_RW, data_handlesx0, STARPU_R, data_handlesx1,
  110. 0);
  111. assert(err == 0);
  112. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  113. STARPU_VALUE, &node, sizeof(node),
  114. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  115. 0);
  116. assert(err == 0);
  117. node = 1;
  118. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  119. STARPU_VALUE, &node, sizeof(node),
  120. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  121. 0);
  122. assert(err == 0);
  123. node = 0;
  124. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  125. STARPU_VALUE, &node, sizeof(node),
  126. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  127. 0);
  128. assert(err == 0);
  129. node = 0;
  130. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_r,
  131. STARPU_VALUE, &node, sizeof(node),
  132. STARPU_R, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  133. 0);
  134. assert(err == 0);
  135. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  136. going to overwrite the node even though the data model clearly specifies
  137. which node is going to execute the codelet */
  138. node = 0;
  139. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_w,
  140. STARPU_VALUE, &node, sizeof(node),
  141. STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  142. 0);
  143. assert(err == 0);
  144. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  145. going to overwrite the node even though the data model clearly specifies
  146. which node is going to execute the codelet */
  147. node = 0;
  148. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_w_r,
  149. STARPU_VALUE, &node, sizeof(node),
  150. STARPU_W, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  151. 0);
  152. assert(err == 0);
  153. FPRINTF_MPI(stderr, "Waiting ...\n");
  154. starpu_task_wait_for_all();
  155. starpu_data_unregister(data_handlesx0);
  156. starpu_data_unregister(data_handlesx1);
  157. end:
  158. starpu_mpi_shutdown();
  159. return 0;
  160. }