insert_task_node_choice.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. struct starpu_codelet mycodelet =
  29. {
  30. .cpu_funcs = {func_cpu},
  31. .nbuffers = 2,
  32. .modes = {STARPU_RW, STARPU_RW},
  33. .model = &starpu_nop_perf_model,
  34. .name = "insert_task_node_choice"
  35. };
  36. int main(int argc, char **argv)
  37. {
  38. int ret, rank, size, err, node;
  39. int x0=32;
  40. long long x1=23;
  41. starpu_data_handle_t data_handlesx0;
  42. starpu_data_handle_t data_handlesx1;
  43. ret = starpu_init(NULL);
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  45. ret = starpu_mpi_init(&argc, &argv, 1);
  46. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  47. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  48. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  49. if (rank != 0 && rank != 1)
  50. goto end;
  51. if (rank == 0)
  52. {
  53. starpu_variable_data_register(&data_handlesx0, STARPU_MAIN_RAM, (uintptr_t)&x0, sizeof(x0));
  54. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(x1));
  55. }
  56. else
  57. {
  58. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(x0));
  59. starpu_variable_data_register(&data_handlesx1, STARPU_MAIN_RAM, (uintptr_t)&x1, sizeof(x1));
  60. }
  61. starpu_mpi_data_register(data_handlesx0, 100, 0);
  62. starpu_mpi_data_register(data_handlesx1, 200, 1);
  63. node = 0;
  64. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  65. STARPU_VALUE, &node, sizeof(node),
  66. STARPU_EXECUTE_ON_NODE, 0,
  67. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  68. 0);
  69. assert(err == 0);
  70. node = starpu_data_get_rank(data_handlesx1);
  71. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  72. STARPU_VALUE, &node, sizeof(node),
  73. STARPU_EXECUTE_ON_DATA, data_handlesx1,
  74. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  75. 0);
  76. assert(err == 0);
  77. // Node 1 has a long long data which has a bigger size than a
  78. // int, so it is going to be selected by the node selection
  79. // policy to execute the codelet
  80. err = starpu_mpi_node_selection_set_current_policy(STARPU_MPI_NODE_SELECTION_MOST_R_DATA);
  81. assert(err == 0);
  82. node = 1;
  83. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  84. STARPU_VALUE, &node, sizeof(node),
  85. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  86. 0);
  87. assert(err == 0);
  88. FPRINTF_MPI(stderr, "Waiting ...\n");
  89. starpu_task_wait_for_all();
  90. starpu_data_unregister(data_handlesx0);
  91. starpu_data_unregister(data_handlesx1);
  92. end:
  93. starpu_mpi_shutdown();
  94. starpu_shutdown();
  95. return 0;
  96. }