policy_selection.c 4.4 KB

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