insert_task_node_choice.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013, 2014, 2015 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. .name = "insert_task_node_choice"
  34. };
  35. int main(int argc, char **argv)
  36. {
  37. int ret, rank, size, err, node;
  38. int x0=32;
  39. long x1=23;
  40. starpu_data_handle_t data_handlesx0;
  41. starpu_data_handle_t data_handlesx1;
  42. ret = starpu_init(NULL);
  43. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  44. ret = starpu_mpi_init(&argc, &argv, 1);
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  46. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  47. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  48. if (rank != 0 && rank != 1) goto end;
  49. if (rank == 0)
  50. {
  51. starpu_variable_data_register(&data_handlesx0, STARPU_MAIN_RAM, (uintptr_t)&x0, sizeof(x0));
  52. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(x1));
  53. }
  54. else
  55. {
  56. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(x0));
  57. starpu_variable_data_register(&data_handlesx1, STARPU_MAIN_RAM, (uintptr_t)&x1, sizeof(x1));
  58. }
  59. starpu_mpi_data_register(data_handlesx0, 100, 0);
  60. starpu_mpi_data_register(data_handlesx1, 200, 1);
  61. node = 0;
  62. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  63. STARPU_VALUE, &node, sizeof(node),
  64. STARPU_EXECUTE_ON_NODE, 0,
  65. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  66. 0);
  67. assert(err == 0);
  68. node = starpu_data_get_rank(data_handlesx1);
  69. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  70. STARPU_VALUE, &node, sizeof(node),
  71. STARPU_EXECUTE_ON_DATA, data_handlesx1,
  72. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  73. 0);
  74. assert(err == 0);
  75. node = 1; // Node 1 has a long which is bigger than a int
  76. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  77. STARPU_VALUE, &node, sizeof(node),
  78. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  79. 0);
  80. assert(err == 0);
  81. FPRINTF_MPI(stderr, "Waiting ...\n");
  82. starpu_task_wait_for_all();
  83. starpu_data_unregister(data_handlesx0);
  84. starpu_data_unregister(data_handlesx1);
  85. end:
  86. starpu_mpi_shutdown();
  87. starpu_shutdown();
  88. return 0;
  89. }