multiple_send.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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_initialize_extended(&rank, &size);
  30. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_initialize_extended");
  31. if (size < 2)
  32. {
  33. if (rank == 0)
  34. FPRINTF(stderr, "We need at least 2 processes.\n");
  35. starpu_mpi_shutdown();
  36. starpu_shutdown();
  37. return STARPU_TEST_SKIPPED;
  38. }
  39. starpu_variable_data_register(&send_handle[0], 0, (uintptr_t)&send[0], sizeof(unsigned));
  40. starpu_variable_data_register(&send_handle[1], 0, (uintptr_t)&send[1], sizeof(unsigned));
  41. starpu_variable_data_register(&recv_handle[0], 0, (uintptr_t)&recv[0], sizeof(unsigned));
  42. starpu_variable_data_register(&recv_handle[1], 0, (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_mpi_shutdown();
  79. starpu_shutdown();
  80. return 0;
  81. }