insert_task_owner.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 CNRS
  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[], STARPU_ATTRIBUTE_UNUSED void *_args)
  20. {
  21. int node;
  22. int rank;
  23. starpu_codelet_unpack_args(_args, &node);
  24. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  25. FPRINTF_MPI(stderr, "Expected node: %d - Actual node: %d\n", node, rank);
  26. assert(node == rank);
  27. }
  28. /* Dummy cost function for simgrid */
  29. static double cost_function(struct starpu_task *task STARPU_ATTRIBUTE_UNUSED, unsigned nimpl STARPU_ATTRIBUTE_UNUSED)
  30. {
  31. return 0.000001;
  32. }
  33. static struct starpu_perfmodel dumb_model =
  34. {
  35. .type = STARPU_COMMON,
  36. .cost_function = cost_function
  37. };
  38. struct starpu_codelet mycodelet_r_w =
  39. {
  40. .cpu_funcs = {func_cpu},
  41. .nbuffers = 2,
  42. .modes = {STARPU_R, STARPU_W},
  43. .model = &dumb_model
  44. };
  45. struct starpu_codelet mycodelet_rw_r =
  46. {
  47. .cpu_funcs = {func_cpu},
  48. .nbuffers = 2,
  49. .modes = {STARPU_RW, STARPU_R},
  50. .model = &dumb_model
  51. };
  52. struct starpu_codelet mycodelet_rw_rw =
  53. {
  54. .cpu_funcs = {func_cpu},
  55. .nbuffers = 2,
  56. .modes = {STARPU_RW, STARPU_RW},
  57. .model = &dumb_model
  58. };
  59. struct starpu_codelet mycodelet_w_r =
  60. {
  61. .cpu_funcs = {func_cpu},
  62. .nbuffers = 2,
  63. .modes = {STARPU_W, STARPU_R},
  64. .model = &dumb_model
  65. };
  66. struct starpu_codelet mycodelet_r_r =
  67. {
  68. .cpu_funcs = {func_cpu},
  69. .nbuffers = 2,
  70. .modes = {STARPU_R, STARPU_R},
  71. .model = &dumb_model
  72. };
  73. int main(int argc, char **argv)
  74. {
  75. int ret, rank, size, err, node;
  76. long x0=32;
  77. int x1=23;
  78. starpu_data_handle_t data_handlesx0;
  79. starpu_data_handle_t data_handlesx1;
  80. ret = starpu_init(NULL);
  81. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  82. ret = starpu_mpi_init(&argc, &argv, 1);
  83. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  84. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  85. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  86. if (starpu_cpu_worker_get_count() == 0)
  87. {
  88. if (rank == 0)
  89. FPRINTF(stderr, "We need at least 1 CPU worker.\n");
  90. starpu_mpi_shutdown();
  91. starpu_shutdown();
  92. return STARPU_TEST_SKIPPED;
  93. }
  94. if (rank != 0 && rank != 1) goto end;
  95. if (rank == 0)
  96. {
  97. starpu_variable_data_register(&data_handlesx0, STARPU_MAIN_RAM, (uintptr_t)&x0, sizeof(x0));
  98. starpu_mpi_data_register(data_handlesx0, 0, rank);
  99. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(x1));
  100. starpu_mpi_data_register(data_handlesx1, 1, 1);
  101. }
  102. else if (rank == 1)
  103. {
  104. starpu_variable_data_register(&data_handlesx1, STARPU_MAIN_RAM, (uintptr_t)&x1, sizeof(x1));
  105. starpu_mpi_data_register(data_handlesx1, 1, rank);
  106. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(x0));
  107. starpu_mpi_data_register(data_handlesx0, 0, 0);
  108. }
  109. node = starpu_mpi_data_get_rank(data_handlesx1);
  110. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_w,
  111. STARPU_VALUE, &node, sizeof(node),
  112. STARPU_R, data_handlesx0, STARPU_W, data_handlesx1,
  113. 0);
  114. assert(err == 0);
  115. node = starpu_mpi_data_get_rank(data_handlesx0);
  116. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_r,
  117. STARPU_VALUE, &node, sizeof(node),
  118. STARPU_RW, data_handlesx0, STARPU_R, data_handlesx1,
  119. 0);
  120. assert(err == 0);
  121. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  122. STARPU_VALUE, &node, sizeof(node),
  123. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  124. 0);
  125. assert(err == 0);
  126. node = 1;
  127. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  128. STARPU_VALUE, &node, sizeof(node),
  129. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  130. 0);
  131. assert(err == 0);
  132. node = 0;
  133. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  134. STARPU_VALUE, &node, sizeof(node),
  135. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  136. 0);
  137. assert(err == 0);
  138. node = 0;
  139. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_r,
  140. STARPU_VALUE, &node, sizeof(node),
  141. STARPU_R, data_handlesx0, STARPU_R, 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_r_w,
  149. STARPU_VALUE, &node, sizeof(node),
  150. STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  151. 0);
  152. assert(err == 0);
  153. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  154. going to overwrite the node even though the data model clearly specifies
  155. which node is going to execute the codelet */
  156. node = 0;
  157. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_w_r,
  158. STARPU_VALUE, &node, sizeof(node),
  159. STARPU_W, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  160. 0);
  161. assert(err == 0);
  162. FPRINTF_MPI(stderr, "Waiting ...\n");
  163. starpu_task_wait_for_all();
  164. starpu_data_unregister(data_handlesx0);
  165. starpu_data_unregister(data_handlesx1);
  166. end:
  167. starpu_mpi_shutdown();
  168. starpu_shutdown();
  169. return 0;
  170. }