intercommunicator.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Copyright (C) 2007 The Trustees of Indiana University.
  2. // Authors: Douglas Gregor
  3. // Andrew Lumsdaine
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. /** @file intercommunicator.hpp
  8. *
  9. * This header defines the @c intercommunicator class, which permits
  10. * communication between different process groups.
  11. */
  12. #ifndef BOOST_MPI_INTERCOMMUNICATOR_HPP
  13. #define BOOST_MPI_INTERCOMMUNICATOR_HPP
  14. #include <boost/mpi/communicator.hpp>
  15. namespace boost { namespace mpi {
  16. /**
  17. * INTERNAL ONLY
  18. *
  19. * Forward declaration of the MPI "group" representation, for use in
  20. * the description of the @c intercommunicator class.
  21. */
  22. class group;
  23. /**
  24. * @brief Communication facilities among processes in different
  25. * groups.
  26. *
  27. * The @c intercommunicator class provides communication facilities
  28. * among processes from different groups. An intercommunicator is
  29. * always associated with two process groups: one "local" process
  30. * group, containing the process that initiates an MPI operation
  31. * (e.g., the sender in a @c send operation), and one "remote" process
  32. * group, containing the process that is the target of the MPI
  33. * operation.
  34. *
  35. * While intercommunicators have essentially the same point-to-point
  36. * operations as intracommunicators (the latter communicate only
  37. * within a single process group), all communication with
  38. * intercommunicators occurs between the processes in the local group
  39. * and the processes in the remote group; communication within a group
  40. * must use a different (intra-)communicator.
  41. *
  42. */
  43. class BOOST_MPI_DECL intercommunicator : public communicator
  44. {
  45. private:
  46. friend class communicator;
  47. /**
  48. * INTERNAL ONLY
  49. *
  50. * Construct an intercommunicator given a shared pointer to the
  51. * underlying MPI_Comm. This operation is used for "casting" from a
  52. * communicator to an intercommunicator.
  53. */
  54. explicit intercommunicator(const shared_ptr<MPI_Comm>& cp)
  55. {
  56. this->comm_ptr = cp;
  57. }
  58. public:
  59. /**
  60. * Build a new Boost.MPI intercommunicator based on the MPI
  61. * intercommunicator @p comm.
  62. *
  63. * @p comm may be any valid MPI intercommunicator. If @p comm is
  64. * MPI_COMM_NULL, an empty communicator (that cannot be used for
  65. * communication) is created and the @p kind parameter is
  66. * ignored. Otherwise, the @p kind parameter determines how the
  67. * Boost.MPI communicator will be related to @p comm:
  68. *
  69. * - If @p kind is @c comm_duplicate, duplicate @c comm to create
  70. * a new communicator. This new communicator will be freed when
  71. * the Boost.MPI communicator (and all copies of it) is
  72. * destroyed. This option is only permitted if the underlying MPI
  73. * implementation supports MPI 2.0; duplication of
  74. * intercommunicators is not available in MPI 1.x.
  75. *
  76. * - If @p kind is @c comm_take_ownership, take ownership of @c
  77. * comm. It will be freed automatically when all of the Boost.MPI
  78. * communicators go out of scope.
  79. *
  80. * - If @p kind is @c comm_attach, this Boost.MPI communicator
  81. * will reference the existing MPI communicator @p comm but will
  82. * not free @p comm when the Boost.MPI communicator goes out of
  83. * scope. This option should only be used when the communicator is
  84. * managed by the user.
  85. */
  86. intercommunicator(const MPI_Comm& comm, comm_create_kind kind)
  87. : communicator(comm, kind) { }
  88. /**
  89. * Constructs a new intercommunicator whose local group is @p local
  90. * and whose remote group is @p peer. The intercommunicator can then
  91. * be used to communicate between processes in the two groups. This
  92. * constructor is equivalent to a call to @c MPI_Intercomm_create.
  93. *
  94. * @param local The intracommunicator containing all of the
  95. * processes that will go into the local group.
  96. *
  97. * @param local_leader The rank within the @p local
  98. * intracommunicator that will serve as its leader.
  99. *
  100. * @param peer The intracommunicator containing all of the processes
  101. * that will go into the remote group.
  102. *
  103. * @param remote_leader The rank within the @p peer group that will
  104. * serve as its leader.
  105. */
  106. intercommunicator(const communicator& local, int local_leader,
  107. const communicator& peer, int remote_leader);
  108. /**
  109. * Returns the size of the local group, i.e., the number of local
  110. * processes that are part of the group.
  111. */
  112. int local_size() const { return this->size(); }
  113. /**
  114. * Returns the local group, containing all of the local processes in
  115. * this intercommunicator.
  116. */
  117. boost::mpi::group local_group() const;
  118. /**
  119. * Returns the rank of this process within the local group.
  120. */
  121. int local_rank() const { return this->rank(); }
  122. /**
  123. * Returns the size of the remote group, i.e., the number of
  124. * processes that are part of the remote group.
  125. */
  126. int remote_size() const;
  127. /**
  128. * Returns the remote group, containing all of the remote processes
  129. * in this intercommunicator.
  130. */
  131. boost::mpi::group remote_group() const;
  132. /**
  133. * Merge the local and remote groups in this intercommunicator into
  134. * a new intracommunicator containing the union of the processes in
  135. * both groups. This method is equivalent to @c MPI_Intercomm_merge.
  136. *
  137. * @param high Whether the processes in this group should have the
  138. * higher rank numbers than the processes in the other group. Each
  139. * of the processes within a particular group shall have the same
  140. * "high" value.
  141. *
  142. * @returns the new, merged intracommunicator
  143. */
  144. communicator merge(bool high) const;
  145. };
  146. } } // end namespace boost::mpi
  147. #endif // BOOST_MPI_INTERCOMMUNICATOR_HPP