multiple_send.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Inria
  4. * Copyright (C) 2011-2013,2015,2017 CNRS
  5. * Copyright (C) 2011,2015,2018 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu_mpi.h>
  19. #include "helper.h"
  20. int main(int argc, char **argv)
  21. {
  22. int ret, rank, size;
  23. unsigned send[2] = {42, 11};
  24. unsigned recv[2] = {33, 33};
  25. starpu_mpi_req req[2];
  26. starpu_data_handle_t send_handle[2];
  27. starpu_data_handle_t recv_handle[2];
  28. ret = starpu_mpi_init_conf(&argc, &argv, 1, MPI_COMM_WORLD, NULL);
  29. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  30. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  31. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  32. if (size < 2)
  33. {
  34. if (rank == 0)
  35. FPRINTF(stderr, "We need at least 2 processes.\n");
  36. starpu_mpi_shutdown();
  37. return STARPU_TEST_SKIPPED;
  38. }
  39. starpu_variable_data_register(&send_handle[0], STARPU_MAIN_RAM, (uintptr_t)&send[0], sizeof(unsigned));
  40. starpu_variable_data_register(&send_handle[1], STARPU_MAIN_RAM, (uintptr_t)&send[1], sizeof(unsigned));
  41. starpu_variable_data_register(&recv_handle[0], STARPU_MAIN_RAM, (uintptr_t)&recv[0], sizeof(unsigned));
  42. starpu_variable_data_register(&recv_handle[1], STARPU_MAIN_RAM, (uintptr_t)&recv[1], sizeof(unsigned));
  43. if (rank == 0)
  44. {
  45. starpu_mpi_isend(send_handle[0], &(req[0]), 1, 12, MPI_COMM_WORLD);
  46. starpu_mpi_isend(send_handle[1], &(req[1]), 1, 13, MPI_COMM_WORLD);
  47. }
  48. else if (rank == 1)
  49. {
  50. starpu_mpi_irecv(recv_handle[0], &(req[0]), 0, 12, MPI_COMM_WORLD);
  51. starpu_mpi_irecv(recv_handle[1], &(req[1]), 0, 13, MPI_COMM_WORLD);
  52. }
  53. if (rank == 0 || rank == 1)
  54. {
  55. int nb_req=2;
  56. while (nb_req)
  57. {
  58. int r=0;
  59. for(r=0 ; r<2 ; r++)
  60. {
  61. if (req[r])
  62. {
  63. int finished = 0;
  64. MPI_Status status;
  65. starpu_mpi_test(&req[r], &finished, &status);
  66. STARPU_ASSERT(finished != -1);
  67. if (finished)
  68. {
  69. FPRINTF(stderr, "[%d] Request %d finished\n", rank, r);
  70. req[r] = NULL;
  71. nb_req--;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. FPRINTF(stderr, "[%d] All requests finished\n", rank);
  78. starpu_data_unregister(send_handle[0]);
  79. starpu_data_unregister(send_handle[1]);
  80. starpu_data_unregister(recv_handle[0]);
  81. starpu_data_unregister(recv_handle[1]);
  82. starpu_mpi_shutdown();
  83. return 0;
  84. }