multiple_send.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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 "helper.h"
  18. int main(int argc, char **argv)
  19. {
  20. int ret, rank, size;
  21. unsigned send[2] = {42, 11};
  22. unsigned recv[2] = {33, 33};
  23. starpu_mpi_req req[2];
  24. starpu_data_handle_t send_handle[2];
  25. starpu_data_handle_t recv_handle[2];
  26. ret = starpu_mpi_init_conf(&argc, &argv, 1, MPI_COMM_WORLD, NULL);
  27. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  28. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  29. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  30. if (size < 2)
  31. {
  32. if (rank == 0)
  33. FPRINTF(stderr, "We need at least 2 processes.\n");
  34. starpu_mpi_shutdown();
  35. return STARPU_TEST_SKIPPED;
  36. }
  37. starpu_variable_data_register(&send_handle[0], STARPU_MAIN_RAM, (uintptr_t)&send[0], sizeof(unsigned));
  38. starpu_variable_data_register(&send_handle[1], STARPU_MAIN_RAM, (uintptr_t)&send[1], sizeof(unsigned));
  39. starpu_variable_data_register(&recv_handle[0], STARPU_MAIN_RAM, (uintptr_t)&recv[0], sizeof(unsigned));
  40. starpu_variable_data_register(&recv_handle[1], STARPU_MAIN_RAM, (uintptr_t)&recv[1], sizeof(unsigned));
  41. if (rank == 0)
  42. {
  43. starpu_mpi_isend(send_handle[0], &(req[0]), 1, 12, MPI_COMM_WORLD);
  44. starpu_mpi_isend(send_handle[1], &(req[1]), 1, 13, MPI_COMM_WORLD);
  45. }
  46. else if (rank == 1)
  47. {
  48. starpu_mpi_irecv(recv_handle[0], &(req[0]), 0, 12, MPI_COMM_WORLD);
  49. starpu_mpi_irecv(recv_handle[1], &(req[1]), 0, 13, MPI_COMM_WORLD);
  50. }
  51. if (rank == 0 || rank == 1)
  52. {
  53. int nb_req=2;
  54. while (nb_req)
  55. {
  56. int r=0;
  57. for(r=0 ; r<2 ; r++)
  58. {
  59. if (req[r])
  60. {
  61. int finished = 0;
  62. MPI_Status status;
  63. starpu_mpi_test(&req[r], &finished, &status);
  64. STARPU_ASSERT(finished != -1);
  65. if (finished)
  66. {
  67. FPRINTF(stderr, "[%d] Request %d finished\n", rank, r);
  68. req[r] = NULL;
  69. nb_req--;
  70. }
  71. }
  72. }
  73. #ifdef STARPU_SIMGRID
  74. starpu_sleep(0.001);
  75. #endif
  76. }
  77. }
  78. FPRINTF(stderr, "[%d] All requests finished\n", rank);
  79. starpu_data_unregister(send_handle[0]);
  80. starpu_data_unregister(send_handle[1]);
  81. starpu_data_unregister(recv_handle[0]);
  82. starpu_data_unregister(recv_handle[1]);
  83. starpu_mpi_shutdown();
  84. return 0;
  85. }