mpi_irecv.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 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. #include "helper.h"
  19. #ifdef STARPU_QUICK_CHECK
  20. # define NITER 16
  21. #else
  22. # define NITER 2048
  23. #endif
  24. #define SIZE 16
  25. float *tab;
  26. starpu_data_handle_t tab_handle;
  27. int main(int argc, char **argv)
  28. {
  29. int ret, rank, size;
  30. MPI_Init(NULL, NULL);
  31. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  32. MPI_Comm_size(MPI_COMM_WORLD, &size);
  33. if (size%2 != 0)
  34. {
  35. if (rank == 0)
  36. FPRINTF(stderr, "We need a even number of processes.\n");
  37. MPI_Finalize();
  38. return STARPU_TEST_SKIPPED;
  39. }
  40. ret = starpu_init(NULL);
  41. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  42. ret = starpu_mpi_init(NULL, NULL, 0);
  43. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  44. tab = malloc(SIZE*sizeof(float));
  45. starpu_vector_data_register(&tab_handle, 0, (uintptr_t)tab, SIZE, sizeof(float));
  46. int nloops = NITER;
  47. int loop;
  48. int other_rank = rank%2 == 0 ? rank+1 : rank-1;
  49. for (loop = 0; loop < nloops; loop++)
  50. {
  51. if ((loop % 2) == (rank%2))
  52. {
  53. starpu_mpi_send(tab_handle, other_rank, loop, MPI_COMM_WORLD);
  54. }
  55. else
  56. {
  57. MPI_Status status;
  58. starpu_mpi_req req;
  59. starpu_mpi_irecv(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
  60. starpu_mpi_wait(&req, &status);
  61. }
  62. }
  63. starpu_data_unregister(tab_handle);
  64. starpu_mpi_shutdown();
  65. starpu_shutdown();
  66. MPI_Finalize();
  67. return 0;
  68. }