insert_task_owner.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012 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[], __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. .where = STARPU_CPU,
  31. .cpu_funcs = {func_cpu, NULL},
  32. .nbuffers = 2,
  33. .modes = {STARPU_R, STARPU_W}
  34. };
  35. struct starpu_codelet mycodelet_rw_r =
  36. {
  37. .where = STARPU_CPU,
  38. .cpu_funcs = {func_cpu, NULL},
  39. .nbuffers = 2,
  40. .modes = {STARPU_RW, STARPU_R}
  41. };
  42. struct starpu_codelet mycodelet_rw_rw =
  43. {
  44. .where = STARPU_CPU,
  45. .cpu_funcs = {func_cpu, NULL},
  46. .nbuffers = 2,
  47. .modes = {STARPU_RW, STARPU_RW}
  48. };
  49. struct starpu_codelet mycodelet_w_r =
  50. {
  51. .where = STARPU_CPU,
  52. .cpu_funcs = {func_cpu, NULL},
  53. .nbuffers = 2,
  54. .modes = {STARPU_W, STARPU_R}
  55. };
  56. int main(int argc, char **argv)
  57. {
  58. int ret, rank, size, err, node;
  59. int x0=32, x1=23;
  60. starpu_data_handle_t data_handlesx0;
  61. starpu_data_handle_t data_handlesx1;
  62. ret = starpu_init(NULL);
  63. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  64. ret = starpu_mpi_initialize_extended(&rank, &size);
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_initialize_extended");
  66. if (size != 2)
  67. {
  68. if (rank == 0) FPRINTF(stderr, "We need exactly 2 processes.\n");
  69. starpu_mpi_shutdown();
  70. starpu_shutdown();
  71. return STARPU_TEST_SKIPPED;
  72. }
  73. if (rank == 0)
  74. {
  75. starpu_variable_data_register(&data_handlesx0, 0, (uintptr_t)&x0, sizeof(x0));
  76. starpu_data_set_rank(data_handlesx0, rank);
  77. starpu_data_set_tag(data_handlesx0, 0);
  78. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(int));
  79. starpu_data_set_rank(data_handlesx1, 1);
  80. starpu_data_set_tag(data_handlesx1, 1);
  81. }
  82. else if (rank == 1)
  83. {
  84. starpu_variable_data_register(&data_handlesx1, 0, (uintptr_t)&x1, sizeof(x1));
  85. starpu_data_set_rank(data_handlesx1, rank);
  86. starpu_data_set_tag(data_handlesx1, 1);
  87. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(int));
  88. starpu_data_set_rank(data_handlesx0, 0);
  89. starpu_data_set_tag(data_handlesx0, 0);
  90. }
  91. node = starpu_data_get_rank(data_handlesx1);
  92. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_r_w,
  93. STARPU_VALUE, &node, sizeof(node),
  94. STARPU_R, data_handlesx0, STARPU_W, data_handlesx1,
  95. 0);
  96. assert(err == 0);
  97. node = starpu_data_get_rank(data_handlesx0);
  98. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_rw_r,
  99. STARPU_VALUE, &node, sizeof(node),
  100. STARPU_RW, data_handlesx0, STARPU_R, data_handlesx1,
  101. 0);
  102. assert(err == 0);
  103. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet_rw_rw,
  104. STARPU_VALUE, &node, sizeof(node),
  105. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  106. 0);
  107. assert(err == -EINVAL);
  108. node = 1;
  109. err = starpu_mpi_insert_task(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_insert_task(MPI_COMM_WORLD, &mycodelet_rw_rw,
  116. STARPU_VALUE, &node, sizeof(node),
  117. STARPU_RW, data_handlesx0, STARPU_RW, 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_insert_task(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_insert_task(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(stderr, "Waiting ...\n");
  139. starpu_task_wait_for_all();
  140. starpu_mpi_shutdown();
  141. starpu_shutdown();
  142. return 0;
  143. }