mpi_isend.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011,2014-2015,2017 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_init(NULL);
  34. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  35. ret = starpu_mpi_init(&argc, &argv, mpi_init);
  36. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  37. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  38. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  39. if (size%2 != 0)
  40. {
  41. if (rank == 0)
  42. FPRINTF(stderr, "We need a even number of processes.\n");
  43. starpu_mpi_shutdown();
  44. starpu_shutdown();
  45. if (!mpi_init)
  46. MPI_Finalize();
  47. return STARPU_TEST_SKIPPED;
  48. }
  49. tab = calloc(SIZE, sizeof(float));
  50. starpu_vector_data_register(&tab_handle, STARPU_MAIN_RAM, (uintptr_t)tab, SIZE, sizeof(float));
  51. int nloops = NITER;
  52. int loop;
  53. int other_rank = rank%2 == 0 ? rank+1 : rank-1;
  54. for (loop = 0; loop < nloops; loop++)
  55. {
  56. if ((loop % 2) == (rank%2))
  57. {
  58. MPI_Status status;
  59. starpu_mpi_req req;
  60. starpu_mpi_isend(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
  61. starpu_mpi_wait(&req, &status);
  62. }
  63. else
  64. {
  65. MPI_Status status;
  66. starpu_mpi_recv(tab_handle, other_rank, loop, MPI_COMM_WORLD, &status);
  67. }
  68. }
  69. starpu_data_unregister(tab_handle);
  70. free(tab);
  71. starpu_mpi_shutdown();
  72. starpu_shutdown();
  73. if (!mpi_init)
  74. MPI_Finalize();
  75. return 0;
  76. }