mpi_test.c 2.2 KB

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