mpi_irecv.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu_mpi.h>
  17. #include "helper.h"
  18. #ifdef STARPU_QUICK_CHECK
  19. # define NITER 16
  20. #else
  21. # define NITER 2048
  22. #endif
  23. #define SIZE 16
  24. float *tab;
  25. starpu_data_handle_t tab_handle;
  26. int main(int argc, char **argv)
  27. {
  28. int ret, rank, size;
  29. int mpi_init;
  30. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  31. ret = starpu_mpi_init_conf(&argc, &argv, mpi_init, MPI_COMM_WORLD, NULL);
  32. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  33. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  34. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  35. if (size%2 != 0)
  36. {
  37. if (rank == 0)
  38. FPRINTF(stderr, "We need a even number of processes.\n");
  39. starpu_mpi_shutdown();
  40. if (!mpi_init)
  41. MPI_Finalize();
  42. return STARPU_TEST_SKIPPED;
  43. }
  44. tab = calloc(SIZE, sizeof(float));
  45. starpu_vector_data_register(&tab_handle, STARPU_MAIN_RAM, (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. free(tab);
  65. starpu_mpi_shutdown();
  66. if (!mpi_init)
  67. MPI_Finalize();
  68. return 0;
  69. }