multiple_send.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013 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 "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_init(NULL);
  27. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  28. ret = starpu_mpi_init(&argc, &argv, 1);
  29. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  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. starpu_shutdown();
  38. return STARPU_TEST_SKIPPED;
  39. }
  40. starpu_variable_data_register(&send_handle[0], STARPU_MAIN_RAM, (uintptr_t)&send[0], sizeof(unsigned));
  41. starpu_variable_data_register(&send_handle[1], STARPU_MAIN_RAM, (uintptr_t)&send[1], sizeof(unsigned));
  42. starpu_variable_data_register(&recv_handle[0], STARPU_MAIN_RAM, (uintptr_t)&recv[0], sizeof(unsigned));
  43. starpu_variable_data_register(&recv_handle[1], STARPU_MAIN_RAM, (uintptr_t)&recv[1], sizeof(unsigned));
  44. if (rank == 0)
  45. {
  46. starpu_mpi_isend(send_handle[0], &(req[0]), 1, 12, MPI_COMM_WORLD);
  47. starpu_mpi_isend(send_handle[1], &(req[1]), 1, 13, MPI_COMM_WORLD);
  48. }
  49. else if (rank == 1)
  50. {
  51. starpu_mpi_irecv(recv_handle[0], &(req[0]), 0, 12, MPI_COMM_WORLD);
  52. starpu_mpi_irecv(recv_handle[1], &(req[1]), 0, 13, MPI_COMM_WORLD);
  53. }
  54. if (rank == 0 || rank == 1)
  55. {
  56. int nb_req=2;
  57. while (nb_req)
  58. {
  59. int r=0;
  60. for(r=0 ; r<2 ; r++)
  61. {
  62. if (req[r])
  63. {
  64. int finished = 0;
  65. MPI_Status status;
  66. starpu_mpi_test(&req[r], &finished, &status);
  67. STARPU_ASSERT(finished != -1);
  68. if (finished)
  69. {
  70. FPRINTF(stderr, "[%d] Request %d finished\n", rank, r);
  71. req[r] = NULL;
  72. nb_req--;
  73. }
  74. }
  75. }
  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. starpu_shutdown();
  85. return 0;
  86. }