insert_task_owner.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013, 2014 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[], STARPU_ATTRIBUTE_UNUSED void *_args)
  20. {
  21. int node;
  22. int rank;
  23. starpu_codelet_unpack_args(_args, &node);
  24. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  25. FPRINTF(stderr, "Expected node: %d - Actual node: %d\n", node, rank);
  26. assert(node == rank);
  27. }
  28. struct starpu_codelet mycodelet_r_w =
  29. {
  30. .cpu_funcs = {func_cpu, NULL},
  31. .nbuffers = 2,
  32. .modes = {STARPU_R, STARPU_W}
  33. };
  34. struct starpu_codelet mycodelet_rw_r =
  35. {
  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. .cpu_funcs = {func_cpu, NULL},
  43. .nbuffers = 2,
  44. .modes = {STARPU_RW, STARPU_RW}
  45. };
  46. struct starpu_codelet mycodelet_w_r =
  47. {
  48. .cpu_funcs = {func_cpu, NULL},
  49. .nbuffers = 2,
  50. .modes = {STARPU_W, STARPU_R}
  51. };
  52. struct starpu_codelet mycodelet_r_r =
  53. {
  54. .cpu_funcs = {func_cpu, NULL},
  55. .nbuffers = 2,
  56. .modes = {STARPU_R, STARPU_R}
  57. };
  58. int main(int argc, char **argv)
  59. {
  60. int ret, rank, size, err, node;
  61. int x0=32, x1=23;
  62. starpu_data_handle_t data_handlesx0;
  63. starpu_data_handle_t data_handlesx1;
  64. ret = starpu_init(NULL);
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  66. ret = starpu_mpi_init(&argc, &argv, 1);
  67. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  68. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  69. MPI_Comm_size(MPI_COMM_WORLD, &size);
  70. if (rank != 0 && rank != 1) goto end;
  71. if (rank == 0)
  72. {
  73. starpu_variable_data_register(&data_handlesx0, STARPU_MAIN_RAM, (uintptr_t)&x0, sizeof(x0));
  74. starpu_mpi_data_register(data_handlesx0, 0, rank);
  75. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(int));
  76. starpu_mpi_data_register(data_handlesx1, 1, 1);
  77. }
  78. else if (rank == 1)
  79. {
  80. starpu_variable_data_register(&data_handlesx1, STARPU_MAIN_RAM, (uintptr_t)&x1, sizeof(x1));
  81. starpu_mpi_data_register(data_handlesx1, 1, rank);
  82. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(int));
  83. starpu_mpi_data_register(data_handlesx0, 0, 0);
  84. }
  85. node = starpu_data_get_rank(data_handlesx1);
  86. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_w,
  87. STARPU_VALUE, &node, sizeof(node),
  88. STARPU_R, data_handlesx0, STARPU_W, data_handlesx1,
  89. 0);
  90. assert(err == 0);
  91. node = starpu_data_get_rank(data_handlesx0);
  92. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_r,
  93. STARPU_VALUE, &node, sizeof(node),
  94. STARPU_RW, data_handlesx0, STARPU_R, data_handlesx1,
  95. 0);
  96. assert(err == 0);
  97. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  98. STARPU_VALUE, &node, sizeof(node),
  99. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  100. 0);
  101. assert(err == -EINVAL);
  102. node = 1;
  103. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  104. STARPU_VALUE, &node, sizeof(node),
  105. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  106. 0);
  107. assert(err == 0);
  108. node = 0;
  109. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_rw_rw,
  110. STARPU_VALUE, &node, sizeof(node),
  111. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  112. 0);
  113. assert(err == 0);
  114. node = 0;
  115. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_r,
  116. STARPU_VALUE, &node, sizeof(node),
  117. STARPU_R, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  118. 0);
  119. assert(err == 0);
  120. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  121. going to overwrite the node even though the data model clearly specifies
  122. which node is going to execute the codelet */
  123. node = 0;
  124. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r_w,
  125. STARPU_VALUE, &node, sizeof(node),
  126. STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  127. 0);
  128. assert(err == 0);
  129. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  130. going to overwrite the node even though the data model clearly specifies
  131. which node is going to execute the codelet */
  132. node = 0;
  133. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_w_r,
  134. STARPU_VALUE, &node, sizeof(node),
  135. STARPU_W, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE_ON_NODE, node,
  136. 0);
  137. assert(err == 0);
  138. FPRINTF_MPI("Waiting ...\n");
  139. starpu_task_wait_for_all();
  140. starpu_data_unregister(data_handlesx0);
  141. starpu_data_unregister(data_handlesx1);
  142. end:
  143. starpu_mpi_shutdown();
  144. starpu_shutdown();
  145. return 0;
  146. }