insert_task_owner.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013, 2014, 2015 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 (rank != 0 && rank != 1) goto end;
  87. if (rank == 0)
  88. {
  89. starpu_variable_data_register(&data_handlesx0, STARPU_MAIN_RAM, (uintptr_t)&x0, sizeof(x0));
  90. starpu_mpi_data_register(data_handlesx0, 0, rank);
  91. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(x1));
  92. starpu_mpi_data_register(data_handlesx1, 1, 1);
  93. }
  94. else if (rank == 1)
  95. {
  96. starpu_variable_data_register(&data_handlesx1, STARPU_MAIN_RAM, (uintptr_t)&x1, sizeof(x1));
  97. starpu_mpi_data_register(data_handlesx1, 1, rank);
  98. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(x0));
  99. starpu_mpi_data_register(data_handlesx0, 0, 0);
  100. }
  101. node = starpu_mpi_data_get_rank(data_handlesx1);
  102. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_w,
  103. STARPU_VALUE, &node, sizeof(node),
  104. STARPU_R, data_handlesx0, STARPU_W, data_handlesx1,
  105. 0);
  106. assert(err == 0);
  107. node = starpu_mpi_data_get_rank(data_handlesx0);
  108. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_r,
  109. STARPU_VALUE, &node, sizeof(node),
  110. STARPU_RW, data_handlesx0, STARPU_R, data_handlesx1,
  111. 0);
  112. assert(err == 0);
  113. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  114. STARPU_VALUE, &node, sizeof(node),
  115. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  116. 0);
  117. assert(err == 0);
  118. node = 1;
  119. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  120. STARPU_VALUE, &node, sizeof(node),
  121. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  122. 0);
  123. assert(err == 0);
  124. node = 0;
  125. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  126. STARPU_VALUE, &node, sizeof(node),
  127. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  128. 0);
  129. assert(err == 0);
  130. node = 0;
  131. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_r,
  132. STARPU_VALUE, &node, sizeof(node),
  133. STARPU_R, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  134. 0);
  135. assert(err == 0);
  136. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  137. going to overwrite the node even though the data model clearly specifies
  138. which node is going to execute the codelet */
  139. node = 0;
  140. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_w,
  141. STARPU_VALUE, &node, sizeof(node),
  142. STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  143. 0);
  144. assert(err == 0);
  145. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  146. going to overwrite the node even though the data model clearly specifies
  147. which node is going to execute the codelet */
  148. node = 0;
  149. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_w_r,
  150. STARPU_VALUE, &node, sizeof(node),
  151. STARPU_W, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  152. 0);
  153. assert(err == 0);
  154. FPRINTF_MPI(stderr, "Waiting ...\n");
  155. starpu_task_wait_for_all();
  156. starpu_data_unregister(data_handlesx0);
  157. starpu_data_unregister(data_handlesx1);
  158. end:
  159. starpu_mpi_shutdown();
  160. starpu_shutdown();
  161. return 0;
  162. }