mpi_irecv.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011,2014,2015,2017,2018 Université de Bordeaux
  4. * Copyright (C) 2013 Inria
  5. * Copyright (C) 2010-2013,2015-2017 CNRS
  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. if (!mpi_init)
  43. MPI_Finalize();
  44. return STARPU_TEST_SKIPPED;
  45. }
  46. tab = calloc(SIZE, sizeof(float));
  47. starpu_vector_data_register(&tab_handle, STARPU_MAIN_RAM, (uintptr_t)tab, SIZE, sizeof(float));
  48. int nloops = NITER;
  49. int loop;
  50. int other_rank = rank%2 == 0 ? rank+1 : rank-1;
  51. for (loop = 0; loop < nloops; loop++)
  52. {
  53. if ((loop % 2) == (rank%2))
  54. {
  55. starpu_mpi_send(tab_handle, other_rank, loop, MPI_COMM_WORLD);
  56. }
  57. else
  58. {
  59. MPI_Status status;
  60. starpu_mpi_req req;
  61. starpu_mpi_irecv(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
  62. starpu_mpi_wait(&req, &status);
  63. }
  64. }
  65. starpu_data_unregister(tab_handle);
  66. free(tab);
  67. starpu_mpi_shutdown();
  68. if (!mpi_init)
  69. MPI_Finalize();
  70. return 0;
  71. }