insert_task_node_choice.c 3.3 KB

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