gather.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if (!mpi_init)
  35. MPI_Finalize();
  36. return STARPU_TEST_SKIPPED;
  37. }
  38. if (rank == 0)
  39. {
  40. int n;
  41. for(n=1 ; n<size ; n++)
  42. {
  43. MPI_Status status;
  44. FPRINTF_MPI(stderr, "receiving from node %d\n", n);
  45. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  46. starpu_mpi_recv(handle, n, 42, MPI_COMM_WORLD, &status);
  47. starpu_data_acquire(handle, STARPU_R);
  48. STARPU_ASSERT_MSG(var == n, "Received incorrect value <%d> from node <%d>\n", var, n);
  49. FPRINTF_MPI(stderr, "received <%d> from node %d\n", var, n);
  50. starpu_data_release(handle);
  51. starpu_data_unregister(handle);
  52. }
  53. }
  54. else
  55. {
  56. FPRINTF_MPI(stderr, "sending to node %d\n", 0);
  57. var = rank;
  58. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  59. starpu_mpi_send(handle, 0, 42, MPI_COMM_WORLD);
  60. starpu_data_unregister(handle);
  61. }
  62. starpu_mpi_shutdown();
  63. if (!mpi_init)
  64. MPI_Finalize();
  65. return 0;
  66. }