mpi_isend.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. MPI_Status status;
  56. starpu_mpi_req req;
  57. starpu_mpi_isend(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
  58. starpu_mpi_wait(&req, &status);
  59. }
  60. else
  61. {
  62. MPI_Status status;
  63. starpu_mpi_recv(tab_handle, other_rank, loop, MPI_COMM_WORLD, &status);
  64. }
  65. }
  66. starpu_data_unregister(tab_handle);
  67. free(tab);
  68. starpu_mpi_shutdown();
  69. if (!mpi_init)
  70. MPI_Finalize();
  71. return 0;
  72. }