policy_selection.c 4.7 KB

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