multiple_send.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #define NITER 2048
  18. int main(int argc, char **argv)
  19. {
  20. int rank, size;
  21. unsigned send[2] = {42, 11};
  22. unsigned recv[2] = {33, 33};
  23. starpu_mpi_req req[2];
  24. starpu_data_handle send_handle[2];
  25. starpu_data_handle recv_handle[2];
  26. starpu_init(NULL);
  27. starpu_mpi_initialize_extended(1, &rank, &size);
  28. if (size < 2)
  29. {
  30. if (rank == 0)
  31. fprintf(stderr, "We need at least 2 processes.\n");
  32. starpu_mpi_shutdown();
  33. starpu_shutdown();
  34. return 0;
  35. }
  36. starpu_variable_data_register(&send_handle[0], 0, (uintptr_t)&send[0], sizeof(unsigned));
  37. starpu_variable_data_register(&send_handle[1], 0, (uintptr_t)&send[1], sizeof(unsigned));
  38. starpu_variable_data_register(&recv_handle[0], 0, (uintptr_t)&recv[0], sizeof(unsigned));
  39. starpu_variable_data_register(&recv_handle[1], 0, (uintptr_t)&recv[1], sizeof(unsigned));
  40. if (rank == 0) {
  41. starpu_mpi_isend(send_handle[0], &(req[0]), 1, 12, MPI_COMM_WORLD);
  42. starpu_mpi_isend(send_handle[1], &(req[1]), 1, 13, MPI_COMM_WORLD);
  43. }
  44. else if (rank == 1) {
  45. starpu_mpi_irecv(recv_handle[0], &(req[0]), 0, 12, MPI_COMM_WORLD);
  46. starpu_mpi_irecv(recv_handle[1], &(req[1]), 0, 13, MPI_COMM_WORLD);
  47. }
  48. if (rank == 0 || rank == 1) {
  49. int nb_req=2;
  50. while (nb_req) {
  51. int r=0;
  52. for(r=0 ; r<2 ; r++) {
  53. if (req[r]) {
  54. int finished = 0;
  55. MPI_Status status;
  56. starpu_mpi_test(&req[r], &finished, &status);
  57. STARPU_ASSERT(finished != -1);
  58. if(finished) {
  59. fprintf(stderr, "[%d] Request %d finished\n", rank, r);
  60. req[r] = NULL;
  61. nb_req--;
  62. }
  63. }
  64. }
  65. }
  66. }
  67. fprintf(stderr, "[%d] All requests finished\n", rank);
  68. starpu_mpi_shutdown();
  69. starpu_shutdown();
  70. return 0;
  71. }