multiple_send.c 2.7 KB

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