mpi_test.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2021 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. int main(int argc, char **argv)
  25. {
  26. int ret, rank, size;
  27. float *tab;
  28. starpu_data_handle_t tab_handle;
  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. starpu_mpi_req req;
  52. if ((loop % 2) == (rank%2))
  53. {
  54. starpu_mpi_isend(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
  55. }
  56. else
  57. {
  58. starpu_mpi_irecv(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
  59. }
  60. int finished = 0;
  61. do
  62. {
  63. MPI_Status status;
  64. starpu_mpi_test(&req, &finished, &status);
  65. #ifdef STARPU_SIMGRID
  66. starpu_sleep(0.001);
  67. #endif
  68. }
  69. while (!finished);
  70. }
  71. starpu_data_unregister(tab_handle);
  72. free(tab);
  73. starpu_mpi_shutdown();
  74. if (!mpi_init)
  75. MPI_Finalize();
  76. return 0;
  77. }