insert_task_node_choice.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013, 2014, 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 <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. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  25. FPRINTF_MPI(stderr, "Expected node: %d - Actual node: %d\n", node, rank);
  26. assert(node == rank);
  27. }
  28. /* Dummy cost function for simgrid */
  29. static double cost_function(struct starpu_task *task STARPU_ATTRIBUTE_UNUSED, unsigned nimpl STARPU_ATTRIBUTE_UNUSED)
  30. {
  31. return 0.000001;
  32. }
  33. static struct starpu_perfmodel dumb_model =
  34. {
  35. .type = STARPU_COMMON,
  36. .cost_function = cost_function
  37. };
  38. struct starpu_codelet mycodelet =
  39. {
  40. .cpu_funcs = {func_cpu},
  41. .nbuffers = 2,
  42. .modes = {STARPU_RW, STARPU_RW},
  43. .model = &dumb_model,
  44. .name = "insert_task_node_choice"
  45. };
  46. int main(int argc, char **argv)
  47. {
  48. int ret, rank, size, err, node;
  49. int x0=32;
  50. long long x1=23;
  51. starpu_data_handle_t data_handlesx0;
  52. starpu_data_handle_t data_handlesx1;
  53. ret = starpu_init(NULL);
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  55. ret = starpu_mpi_init(&argc, &argv, 1);
  56. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  57. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  58. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  59. if (rank != 0 && rank != 1)
  60. goto end;
  61. if (rank == 0)
  62. {
  63. starpu_variable_data_register(&data_handlesx0, STARPU_MAIN_RAM, (uintptr_t)&x0, sizeof(x0));
  64. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(x1));
  65. }
  66. else
  67. {
  68. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(x0));
  69. starpu_variable_data_register(&data_handlesx1, STARPU_MAIN_RAM, (uintptr_t)&x1, sizeof(x1));
  70. }
  71. starpu_mpi_data_register(data_handlesx0, 100, 0);
  72. starpu_mpi_data_register(data_handlesx1, 200, 1);
  73. node = 0;
  74. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  75. STARPU_VALUE, &node, sizeof(node),
  76. STARPU_EXECUTE_ON_NODE, 0,
  77. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  78. 0);
  79. assert(err == 0);
  80. node = starpu_data_get_rank(data_handlesx1);
  81. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  82. STARPU_VALUE, &node, sizeof(node),
  83. STARPU_EXECUTE_ON_DATA, data_handlesx1,
  84. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  85. 0);
  86. assert(err == 0);
  87. // Node 1 has a long long data which has a bigger size than a
  88. // int, so it is going to be selected by the node selection
  89. // policy to execute the codelet
  90. err = starpu_mpi_node_selection_set_current_policy(STARPU_MPI_NODE_SELECTION_MOST_R_DATA);
  91. assert(err == 0);
  92. node = 1;
  93. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  94. STARPU_VALUE, &node, sizeof(node),
  95. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  96. 0);
  97. assert(err == 0);
  98. FPRINTF_MPI(stderr, "Waiting ...\n");
  99. starpu_task_wait_for_all();
  100. starpu_data_unregister(data_handlesx0);
  101. starpu_data_unregister(data_handlesx1);
  102. end:
  103. starpu_mpi_shutdown();
  104. starpu_shutdown();
  105. return 0;
  106. }