insert_task_node_choice.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2015,2017 CNRS
  4. * Copyright (C) 2015,2017 Université de Bordeaux
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu_mpi.h>
  18. #include <math.h>
  19. #include "helper.h"
  20. void func_cpu(void *descr[], void *_args)
  21. {
  22. int node;
  23. int rank;
  24. (void)descr;
  25. starpu_codelet_unpack_args(_args, &node);
  26. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  27. FPRINTF_MPI(stderr, "Expected node: %d - Actual node: %d\n", node, rank);
  28. assert(node == rank);
  29. }
  30. struct starpu_codelet mycodelet =
  31. {
  32. .cpu_funcs = {func_cpu},
  33. .nbuffers = 2,
  34. .modes = {STARPU_RW, STARPU_RW},
  35. .model = &starpu_perfmodel_nop,
  36. .name = "insert_task_node_choice"
  37. };
  38. int main(int argc, char **argv)
  39. {
  40. int ret, rank, size, err, node;
  41. int x0=32;
  42. long long x1=23;
  43. starpu_data_handle_t data_handlesx0;
  44. starpu_data_handle_t data_handlesx1;
  45. ret = starpu_init(NULL);
  46. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  47. ret = starpu_mpi_init(&argc, &argv, 1);
  48. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  49. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  50. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  51. if (rank != 0 && rank != 1)
  52. goto end;
  53. if (rank == 0)
  54. {
  55. starpu_variable_data_register(&data_handlesx0, STARPU_MAIN_RAM, (uintptr_t)&x0, sizeof(x0));
  56. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(x1));
  57. }
  58. else
  59. {
  60. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(x0));
  61. starpu_variable_data_register(&data_handlesx1, STARPU_MAIN_RAM, (uintptr_t)&x1, sizeof(x1));
  62. }
  63. starpu_mpi_data_register(data_handlesx0, 100, 0);
  64. starpu_mpi_data_register(data_handlesx1, 200, 1);
  65. node = 0;
  66. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  67. STARPU_VALUE, &node, sizeof(node),
  68. STARPU_EXECUTE_ON_NODE, 0,
  69. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  70. 0);
  71. assert(err == 0);
  72. node = starpu_data_get_rank(data_handlesx1);
  73. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  74. STARPU_VALUE, &node, sizeof(node),
  75. STARPU_EXECUTE_ON_DATA, data_handlesx1,
  76. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  77. 0);
  78. assert(err == 0);
  79. // Node 1 has a long long data which has a bigger size than a
  80. // int, so it is going to be selected by the node selection
  81. // policy to execute the codelet
  82. err = starpu_mpi_node_selection_set_current_policy(STARPU_MPI_NODE_SELECTION_MOST_R_DATA);
  83. assert(err == 0);
  84. node = 1;
  85. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  86. STARPU_VALUE, &node, sizeof(node),
  87. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  88. 0);
  89. assert(err == 0);
  90. FPRINTF_MPI(stderr, "Waiting ...\n");
  91. starpu_task_wait_for_all();
  92. starpu_data_unregister(data_handlesx0);
  93. starpu_data_unregister(data_handlesx1);
  94. end:
  95. starpu_mpi_shutdown();
  96. starpu_shutdown();
  97. return 0;
  98. }