mpi_irecv.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011,2014-2015,2017-2018 Université de Bordeaux
  4. * Copyright (C) 2010-2013,2015-2017 CNRS
  5. * Copyright (C) 2013 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu_mpi.h>
  19. #include "helper.h"
  20. #ifdef STARPU_QUICK_CHECK
  21. # define NITER 16
  22. #else
  23. # define NITER 2048
  24. #endif
  25. #define SIZE 16
  26. float *tab;
  27. starpu_data_handle_t tab_handle;
  28. int main(int argc, char **argv)
  29. {
  30. int ret, rank, size;
  31. int mpi_init;
  32. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  33. ret = starpu_mpi_init_conf(&argc, &argv, mpi_init, MPI_COMM_WORLD, NULL);
  34. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  35. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  36. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  37. if (size%2 != 0)
  38. {
  39. if (rank == 0)
  40. FPRINTF(stderr, "We need a even number of processes.\n");
  41. starpu_mpi_shutdown();
  42. starpu_shutdown();
  43. if (!mpi_init)
  44. MPI_Finalize();
  45. return STARPU_TEST_SKIPPED;
  46. }
  47. tab = calloc(SIZE, sizeof(float));
  48. starpu_vector_data_register(&tab_handle, STARPU_MAIN_RAM, (uintptr_t)tab, SIZE, sizeof(float));
  49. int nloops = NITER;
  50. int loop;
  51. int other_rank = rank%2 == 0 ? rank+1 : rank-1;
  52. for (loop = 0; loop < nloops; loop++)
  53. {
  54. if ((loop % 2) == (rank%2))
  55. {
  56. starpu_mpi_send(tab_handle, other_rank, loop, MPI_COMM_WORLD);
  57. }
  58. else
  59. {
  60. MPI_Status status;
  61. starpu_mpi_req req;
  62. starpu_mpi_irecv(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
  63. starpu_mpi_wait(&req, &status);
  64. }
  65. }
  66. starpu_data_unregister(tab_handle);
  67. free(tab);
  68. starpu_mpi_shutdown();
  69. starpu_shutdown();
  70. if (!mpi_init)
  71. MPI_Finalize();
  72. return 0;
  73. }