Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:58

0001 // Copyright (C) 2007 The Trustees of Indiana University.
0002 
0003 // Authors: Douglas Gregor
0004 //          Andrew Lumsdaine
0005 
0006 // Use, modification and distribution is subject to the Boost Software
0007 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0008 // http://www.boost.org/LICENSE_1_0.txt)
0009 
0010 /** @file intercommunicator.hpp
0011  *
0012  *  This header defines the @c intercommunicator class, which permits
0013  *  communication between different process groups.
0014  */
0015 #ifndef BOOST_MPI_INTERCOMMUNICATOR_HPP
0016 #define BOOST_MPI_INTERCOMMUNICATOR_HPP
0017 
0018 #include <boost/mpi/communicator.hpp>
0019 
0020 namespace boost { namespace mpi {
0021 
0022 /**
0023  * INTERNAL ONLY
0024  *
0025  * Forward declaration of the MPI "group" representation, for use in
0026  * the description of the @c intercommunicator class.
0027  */ 
0028 class group;
0029 
0030 /**
0031  * @brief Communication facilities among processes in different
0032  * groups.
0033  *
0034  * The @c intercommunicator class provides communication facilities
0035  * among processes from different groups. An intercommunicator is
0036  * always associated with two process groups: one "local" process
0037  * group, containing the process that initiates an MPI operation
0038  * (e.g., the sender in a @c send operation), and one "remote" process
0039  * group, containing the process that is the target of the MPI
0040  * operation.
0041  *
0042  * While intercommunicators have essentially the same point-to-point
0043  * operations as intracommunicators (the latter communicate only
0044  * within a single process group), all communication with
0045  * intercommunicators occurs between the processes in the local group
0046  * and the processes in the remote group; communication within a group
0047  * must use a different (intra-)communicator.
0048  * 
0049  */   
0050 class BOOST_MPI_DECL intercommunicator : public communicator
0051 {
0052 private:
0053   friend class communicator;
0054 
0055   /**
0056    * INTERNAL ONLY
0057    *
0058    * Construct an intercommunicator given a shared pointer to the
0059    * underlying MPI_Comm. This operation is used for "casting" from a
0060    * communicator to an intercommunicator.
0061    */
0062   explicit intercommunicator(const shared_ptr<MPI_Comm>& cp)
0063   {
0064     this->comm_ptr = cp;
0065   }
0066 
0067 public:
0068   /**
0069    * Build a new Boost.MPI intercommunicator based on the MPI
0070    * intercommunicator @p comm.
0071    *
0072    * @p comm may be any valid MPI intercommunicator. If @p comm is
0073    * MPI_COMM_NULL, an empty communicator (that cannot be used for
0074    * communication) is created and the @p kind parameter is
0075    * ignored. Otherwise, the @p kind parameter determines how the
0076    * Boost.MPI communicator will be related to @p comm:
0077    *
0078    *   - If @p kind is @c comm_duplicate, duplicate @c comm to create
0079    *   a new communicator. This new communicator will be freed when
0080    *   the Boost.MPI communicator (and all copies of it) is
0081    *   destroyed. This option is only permitted if the underlying MPI
0082    *   implementation supports MPI 2.0; duplication of
0083    *   intercommunicators is not available in MPI 1.x.
0084    *
0085    *   - If @p kind is @c comm_take_ownership, take ownership of @c
0086    *   comm. It will be freed automatically when all of the Boost.MPI
0087    *   communicators go out of scope.
0088    *
0089    *   - If @p kind is @c comm_attach, this Boost.MPI communicator
0090    *   will reference the existing MPI communicator @p comm but will
0091    *   not free @p comm when the Boost.MPI communicator goes out of
0092    *   scope. This option should only be used when the communicator is
0093    *   managed by the user.
0094    */
0095   intercommunicator(const MPI_Comm& comm, comm_create_kind kind)
0096     : communicator(comm, kind) { }
0097 
0098   /**
0099    * Constructs a new intercommunicator whose local group is @p local
0100    * and whose remote group is @p peer. The intercommunicator can then
0101    * be used to communicate between processes in the two groups. This
0102    * constructor is equivalent to a call to @c MPI_Intercomm_create.
0103    *
0104    * @param local The intracommunicator containing all of the
0105    * processes that will go into the local group.
0106    *
0107    * @param local_leader The rank within the @p local
0108    * intracommunicator that will serve as its leader.
0109    *
0110    * @param peer The intracommunicator containing all of the processes
0111    * that will go into the remote group.
0112    *
0113    * @param remote_leader The rank within the @p peer group that will
0114    * serve as its leader.
0115    */
0116   intercommunicator(const communicator& local, int local_leader,
0117                     const communicator& peer, int remote_leader);
0118 
0119   /**
0120    * Returns the size of the local group, i.e., the number of local
0121    * processes that are part of the group.
0122    */
0123   int local_size() const { return this->size(); }
0124 
0125   /**
0126    * Returns the local group, containing all of the local processes in
0127    * this intercommunicator.
0128    */
0129   boost::mpi::group local_group() const;
0130 
0131   /**
0132    * Returns the rank of this process within the local group.
0133    */
0134   int local_rank() const { return this->rank(); }
0135 
0136   /**
0137    * Returns the size of the remote group, i.e., the number of
0138    * processes that are part of the remote group.
0139    */
0140   int remote_size() const;
0141 
0142   /**
0143    * Returns the remote group, containing all of the remote processes
0144    * in this intercommunicator.
0145    */
0146   boost::mpi::group remote_group() const;
0147 
0148   /**
0149    * Merge the local and remote groups in this intercommunicator into
0150    * a new intracommunicator containing the union of the processes in
0151    * both groups. This method is equivalent to @c MPI_Intercomm_merge.
0152    *  
0153    * @param high Whether the processes in this group should have the
0154    * higher rank numbers than the processes in the other group. Each
0155    * of the processes within a particular group shall have the same
0156    * "high" value.
0157    *
0158    * @returns the new, merged intracommunicator
0159    */
0160   communicator merge(bool high) const;
0161 };
0162 
0163 } } // end namespace boost::mpi
0164 
0165 #endif // BOOST_MPI_INTERCOMMUNICATOR_HPP