gather.c 2.2 KB

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