gather.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013,2015,2017 CNRS
  4. * Copyright (C) 2014-2015,2017 Université de Bordeaux
  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. int main(int argc, char **argv)
  20. {
  21. int ret, rank, size;
  22. starpu_data_handle_t handle;
  23. int var;
  24. int mpi_init;
  25. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  26. ret = starpu_init(NULL);
  27. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  28. ret = starpu_mpi_init(&argc, &argv, mpi_init);
  29. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  30. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  31. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  32. if (size<3)
  33. {
  34. FPRINTF(stderr, "We need more than 2 processes.\n");
  35. starpu_mpi_shutdown();
  36. starpu_shutdown();
  37. if (!mpi_init)
  38. MPI_Finalize();
  39. return STARPU_TEST_SKIPPED;
  40. }
  41. if (rank == 0)
  42. {
  43. int n;
  44. for(n=1 ; n<size ; n++)
  45. {
  46. MPI_Status status;
  47. FPRINTF_MPI(stderr, "receiving from node %d\n", n);
  48. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  49. starpu_mpi_recv(handle, n, 42, MPI_COMM_WORLD, &status);
  50. starpu_data_acquire(handle, STARPU_R);
  51. STARPU_ASSERT_MSG(var == n, "Received incorrect value <%d> from node <%d>\n", var, n);
  52. FPRINTF_MPI(stderr, "received <%d> from node %d\n", var, n);
  53. starpu_data_release(handle);
  54. starpu_data_unregister(handle);
  55. }
  56. }
  57. else
  58. {
  59. FPRINTF_MPI(stderr, "sending to node %d\n", 0);
  60. var = rank;
  61. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  62. starpu_mpi_send(handle, 0, 42, MPI_COMM_WORLD);
  63. starpu_data_unregister(handle);
  64. }
  65. starpu_mpi_shutdown();
  66. starpu_shutdown();
  67. if (!mpi_init)
  68. MPI_Finalize();
  69. return 0;
  70. }