starpu_mpi_collective.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 *data_handles, int count, int root, MPI_Comm comm)
  20. {
  21. int rank;
  22. int x;
  23. int mpi_tag = 0;
  24. MPI_Comm_rank(comm, &rank);
  25. for(x = 0; x < count ; x++)
  26. {
  27. if (data_handles[x])
  28. {
  29. int owner = starpu_data_get_rank(data_handles[x]);
  30. if ((rank == root) && (owner != root))
  31. {
  32. //fprintf(stderr, "[%d] Sending data[%d] to %d\n", rank, x, owner);
  33. starpu_mpi_isend_detached(data_handles[x], owner, mpi_tag, comm, NULL, NULL);
  34. }
  35. if ((rank != root) && (owner == rank))
  36. {
  37. //fprintf(stderr, "[%d] Receiving data[%d] from %d\n", rank, x, root);
  38. //MPI_Status status;
  39. starpu_mpi_irecv_detached(data_handles[x], root, mpi_tag, comm, NULL, NULL);
  40. }
  41. }
  42. mpi_tag++;
  43. }
  44. return 0;
  45. }
  46. int starpu_mpi_gather_detached(starpu_data_handle *data_handles, int count, int root, MPI_Comm comm)
  47. {
  48. int rank;
  49. int x;
  50. int mpi_tag = 0;
  51. MPI_Comm_rank(comm, &rank);
  52. for(x = 0; x < count ; x++)
  53. {
  54. if (data_handles[x])
  55. {
  56. int owner = starpu_data_get_rank(data_handles[x]);
  57. if ((rank == root) && (owner != root))
  58. {
  59. //fprintf(stderr, "[%d] Receiving data[%d] from %d\n", rank, x, owner);
  60. //MPI_Status status;
  61. starpu_mpi_irecv_detached(data_handles[x], owner, mpi_tag, comm, NULL, NULL);
  62. }
  63. if ((rank != root) && (owner == rank))
  64. {
  65. //fprintf(stderr, "[%d] Sending data[%d] to %d\n", rank, x, root);
  66. starpu_mpi_isend_detached(data_handles[x], root, mpi_tag, comm, NULL, NULL);
  67. }
  68. }
  69. mpi_tag ++;
  70. }
  71. return 0;
  72. }