policy_selection.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015,2017 CNRS
  4. * Copyright (C) 2017 Inria
  5. * Copyright (C) 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 "helper.h"
  20. void func_cpu(void *descr[], void *_args)
  21. {
  22. (void)descr;
  23. (void)_args;
  24. }
  25. struct starpu_codelet mycodelet_2 =
  26. {
  27. .cpu_funcs = {func_cpu},
  28. .nbuffers = 2,
  29. .modes = {STARPU_W, STARPU_W},
  30. .model = &starpu_perfmodel_nop,
  31. };
  32. struct starpu_codelet mycodelet_3 =
  33. {
  34. .cpu_funcs = {func_cpu},
  35. .nbuffers = 3,
  36. .modes = {STARPU_R, STARPU_W, STARPU_W},
  37. .model = &starpu_perfmodel_nop,
  38. };
  39. int main(int argc, char **argv)
  40. {
  41. int ret;
  42. int rank, size;
  43. int policy = 12;
  44. struct starpu_task *task;
  45. starpu_data_handle_t handles[3];
  46. int mpi_init;
  47. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  48. (void)mpi_init;
  49. ret = starpu_mpi_init_conf(NULL, NULL, 0, MPI_COMM_WORLD, NULL);
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  51. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  52. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  53. if (size < 3)
  54. {
  55. if (rank == 0)
  56. FPRINTF(stderr, "We need at least 3 processes.\n");
  57. starpu_mpi_shutdown();
  58. if (!mpi_init)
  59. MPI_Finalize();
  60. return STARPU_TEST_SKIPPED;
  61. }
  62. if (rank == 0)
  63. {
  64. starpu_variable_data_register(&handles[0], STARPU_MAIN_RAM, (uintptr_t)&policy, sizeof(int));
  65. }
  66. else
  67. {
  68. starpu_variable_data_register(&handles[0], -1, (uintptr_t)NULL, sizeof(int));
  69. }
  70. starpu_mpi_data_register(handles[0], 10, 0);
  71. if (rank == 1)
  72. {
  73. starpu_variable_data_register(&handles[1], STARPU_MAIN_RAM, (uintptr_t)&policy, sizeof(int));
  74. }
  75. else
  76. {
  77. starpu_variable_data_register(&handles[1], -1, (uintptr_t)NULL, sizeof(int));
  78. }
  79. starpu_mpi_data_register(handles[1], 20, 1);
  80. if (rank == 2)
  81. {
  82. starpu_variable_data_register(&handles[2], STARPU_MAIN_RAM, (uintptr_t)&policy, sizeof(int));
  83. }
  84. else
  85. {
  86. starpu_variable_data_register(&handles[2], -1, (uintptr_t)NULL, sizeof(int));
  87. }
  88. starpu_mpi_data_register(handles[2], 30, 2);
  89. // Force the execution on node 1
  90. task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet_3,
  91. STARPU_R, handles[2],
  92. STARPU_W, handles[0], STARPU_W, handles[1],
  93. STARPU_EXECUTE_ON_NODE, 1,
  94. 0);
  95. FPRINTF_MPI(stderr, "Task %p\n", task);
  96. if (rank == 1)
  97. {
  98. STARPU_ASSERT_MSG(task, "Task should be executed by rank 1\n");
  99. task->destroy = 0;
  100. starpu_task_destroy(task);
  101. }
  102. else
  103. {
  104. STARPU_ASSERT_MSG(task == NULL, "Task should be executed by rank 1\n");
  105. }
  106. // Force the execution on node 1
  107. task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet_2,
  108. STARPU_W, handles[0], STARPU_W, handles[1],
  109. STARPU_EXECUTE_ON_NODE, 1,
  110. 0);
  111. FPRINTF_MPI(stderr, "Task %p\n", task);
  112. if (rank == 1)
  113. {
  114. STARPU_ASSERT_MSG(task, "Task should be executed by rank 1\n");
  115. task->destroy = 0;
  116. starpu_task_destroy(task);
  117. }
  118. else
  119. {
  120. STARPU_ASSERT_MSG(task == NULL, "Task should be executed by rank 1\n");
  121. }
  122. // Let StarPU choose the node
  123. task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet_3,
  124. STARPU_R, handles[2],
  125. STARPU_W, handles[0], STARPU_W, handles[1],
  126. 0);
  127. FPRINTF_MPI(stderr, "Task %p\n", task);
  128. if (rank == 2)
  129. {
  130. STARPU_ASSERT_MSG(task, "Task should be executed by rank 2\n");
  131. task->destroy = 0;
  132. starpu_task_destroy(task);
  133. }
  134. else
  135. {
  136. STARPU_ASSERT_MSG(task == NULL, "Task should be executed by rank 2\n");
  137. }
  138. // Let StarPU choose the node
  139. task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet_2,
  140. STARPU_W, handles[0], STARPU_W, handles[1],
  141. 0);
  142. FPRINTF_MPI(stderr, "Task %p\n", task);
  143. if (rank == 0)
  144. {
  145. STARPU_ASSERT_MSG(task, "Task should be executed by rank 0\n");
  146. task->destroy = 0;
  147. starpu_task_destroy(task);
  148. }
  149. else
  150. {
  151. STARPU_ASSERT_MSG(task == NULL, "Task should be executed by rank 0\n");
  152. }
  153. starpu_data_unregister(handles[0]);
  154. starpu_data_unregister(handles[1]);
  155. starpu_data_unregister(handles[2]);
  156. starpu_mpi_shutdown();
  157. if (!mpi_init)
  158. MPI_Finalize();
  159. return 0;
  160. }