starpu_mpi_collective.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Centre National de la Recherche Scientifique
  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 <mpi.h>
  17. #include <starpu.h>
  18. #include <starpu_mpi.h>
  19. int starpu_mpi_scatter_detached(starpu_data_handle_t *data_handles, int count, int root, MPI_Comm comm)
  20. {
  21. int rank;
  22. int x;
  23. MPI_Comm_rank(comm, &rank);
  24. for(x = 0; x < count ; x++)
  25. {
  26. if (data_handles[x])
  27. {
  28. int owner = starpu_data_get_rank(data_handles[x]);
  29. int mpi_tag = starpu_data_get_tag(data_handles[x]);
  30. STARPU_ASSERT(mpi_tag >= 0);
  31. if ((rank == root) && (owner != root))
  32. {
  33. //fprintf(stderr, "[%d] Sending data[%d] to %d\n", rank, x, owner);
  34. starpu_mpi_isend_detached(data_handles[x], owner, mpi_tag, comm, NULL, NULL);
  35. }
  36. if ((rank != root) && (owner == rank))
  37. {
  38. //fprintf(stderr, "[%d] Receiving data[%d] from %d\n", rank, x, root);
  39. starpu_mpi_irecv_detached(data_handles[x], root, mpi_tag, comm, NULL, NULL);
  40. }
  41. }
  42. }
  43. return 0;
  44. }
  45. int starpu_mpi_gather_detached(starpu_data_handle_t *data_handles, int count, int root, MPI_Comm comm)
  46. {
  47. int rank;
  48. int x;
  49. MPI_Comm_rank(comm, &rank);
  50. for(x = 0; x < count ; x++)
  51. {
  52. if (data_handles[x])
  53. {
  54. int owner = starpu_data_get_rank(data_handles[x]);
  55. int mpi_tag = starpu_data_get_tag(data_handles[x]);
  56. STARPU_ASSERT(mpi_tag >= 0);
  57. if ((rank == root) && (owner != root))
  58. {
  59. //fprintf(stderr, "[%d] Receiving data[%d] from %d\n", rank, x, owner);
  60. starpu_mpi_irecv_detached(data_handles[x], owner, mpi_tag, comm, NULL, NULL);
  61. }
  62. if ((rank != root) && (owner == rank))
  63. {
  64. //fprintf(stderr, "[%d] Sending data[%d] to %d\n", rank, x, root);
  65. starpu_mpi_isend_detached(data_handles[x], root, mpi_tag, comm, NULL, NULL);
  66. }
  67. }
  68. }
  69. return 0;
  70. }