mpi_irecv.c 1.9 KB

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