mpi_isend.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu_mpi.h>
  18. #define NITER 2048
  19. #define SIZE 16
  20. float *tab;
  21. starpu_data_handle tab_handle;
  22. int main(int argc, char **argv)
  23. {
  24. MPI_Init(NULL, NULL);
  25. int rank, size;
  26. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  27. MPI_Comm_size(MPI_COMM_WORLD, &size);
  28. if (size != 2)
  29. {
  30. if (rank == 0)
  31. fprintf(stderr, "We need exactly 2 processes.\n");
  32. MPI_Finalize();
  33. return 0;
  34. }
  35. starpu_init(NULL);
  36. starpu_mpi_initialize();
  37. tab = malloc(SIZE*sizeof(float));
  38. starpu_vector_data_register(&tab_handle, 0, (uintptr_t)tab, SIZE, sizeof(float));
  39. unsigned nloops = NITER;
  40. unsigned loop;
  41. int other_rank = (rank + 1)%2;
  42. for (loop = 0; loop < nloops; loop++)
  43. {
  44. if ((loop % 2) == rank)
  45. {
  46. MPI_Status status;
  47. starpu_mpi_req req;
  48. starpu_mpi_isend(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
  49. starpu_mpi_wait(&req, &status);
  50. }
  51. else {
  52. MPI_Status status;
  53. starpu_mpi_recv(tab_handle, other_rank, loop, MPI_COMM_WORLD, &status);
  54. }
  55. }
  56. starpu_mpi_shutdown();
  57. starpu_shutdown();
  58. MPI_Finalize();
  59. return 0;
  60. }