Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_DistributorPlan.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
22 #ifndef TPETRA_DETAILS_DISTRIBUTOR_PLAN_HPP
23 #define TPETRA_DETAILS_DISTRIBUTOR_PLAN_HPP
24 
25 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
26 #include "Teuchos_Array.hpp"
27 #include "Teuchos_Comm.hpp"
28 #include "Teuchos_RCP.hpp"
29 #include "TpetraCore_config.h"
30 
31 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
32 #include <mpi_advance.h>
33 #endif
34 
35 namespace Tpetra {
36 namespace Details {
37 
43  DISTRIBUTOR_ISEND, // Use MPI_Isend (Teuchos::isend)
44  DISTRIBUTOR_SEND, // Use MPI_Send (Teuchos::send)
45  DISTRIBUTOR_ALLTOALL // Use MPI_Alltoall
46 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
47  ,
48  DISTRIBUTOR_MPIADVANCE_ALLTOALL,
49  DISTRIBUTOR_MPIADVANCE_NBRALLTOALLV
50 #endif
51 };
52 
57 std::string
59 
65  DISTRIBUTOR_NOT_INITIALIZED, // Not initialized yet
66  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_SENDS, // By createFromSends
67  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_RECVS, // By createFromRecvs
68  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_SENDS_N_RECVS, // By createFromSendsAndRecvs
69  DISTRIBUTOR_INITIALIZED_BY_REVERSE, // By createReverseDistributor
70  DISTRIBUTOR_INITIALIZED_BY_COPY, // By copy constructor
71 };
72 
77 std::string
79 
90 class DistributorPlan : public Teuchos::ParameterListAcceptorDefaultBase {
91  static constexpr int DEFAULT_MPI_TAG = 0;
92 
93 public:
94  DistributorPlan(Teuchos::RCP<const Teuchos::Comm<int>> comm);
95  DistributorPlan(const DistributorPlan& otherPlan);
96 
97  size_t createFromSends(const Teuchos::ArrayView<const int>& exportProcIDs);
98  void createFromRecvs(const Teuchos::ArrayView<const int>& remoteProcIDs);
99  void createFromSendsAndRecvs(const Teuchos::ArrayView<const int>& exportProcIDs,
100  const Teuchos::ArrayView<const int>& remoteProcIDs);
101 
102  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList>& plist);
103 
104  Teuchos::RCP<DistributorPlan> getReversePlan() const;
105 
106  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const { return comm_; }
107 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
108  Teuchos::RCP<MPIX_Comm*> getMPIXComm() const { return mpixComm_; }
109 #endif
110  EDistributorSendType getSendType() const { return sendType_; }
111  size_t getNumReceives() const { return numReceives_; }
112  size_t getNumSends() const { return numSendsToOtherProcs_; }
113  bool hasSelfMessage() const { return sendMessageToSelf_; }
114  size_t getMaxSendLength() const { return maxSendLength_; }
115  size_t getTotalReceiveLength() const { return totalReceiveLength_; }
116  Teuchos::ArrayView<const int> getProcsFrom() const { return procsFrom_; }
117  Teuchos::ArrayView<const int> getProcsTo() const { return procIdsToSendTo_; }
118  Teuchos::ArrayView<const size_t> getLengthsFrom() const { return lengthsFrom_; }
119  Teuchos::ArrayView<const size_t> getLengthsTo() const { return lengthsTo_; }
120  Teuchos::ArrayView<const size_t> getStartsTo() const { return startsTo_; }
121  Teuchos::ArrayView<const size_t> getIndicesTo() const { return indicesTo_; }
122  Details::EDistributorHowInitialized howInitialized() const { return howInitialized_; }
123 
124 private:
125 
126  // after the plan has been created we have the info we need to initialize the MPI advance communicator
127 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
128  void initializeMpiAdvance();
129 #endif
130 
131  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
132 
133  void createReversePlan() const;
134 
145  void computeReceives();
146 
147  Teuchos::RCP<const Teuchos::Comm<int>> comm_;
148 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
149  Teuchos::RCP<MPIX_Comm*> mpixComm_;
150 #endif
151 
152  Details::EDistributorHowInitialized howInitialized_;
153  mutable Teuchos::RCP<DistributorPlan> reversePlan_;
154 
156 
157  EDistributorSendType sendType_;
159 
160  bool sendMessageToSelf_;
161  size_t numSendsToOtherProcs_;
162  Teuchos::Array<int> procIdsToSendTo_;
163 
172  Teuchos::Array<size_t> startsTo_;
173 
179  Teuchos::Array<size_t> lengthsTo_;
180 
184  size_t maxSendLength_;
185 
201  Teuchos::Array<size_t> indicesTo_;
202 
212  size_t numReceives_;
213 
220  size_t totalReceiveLength_;
221 
227  Teuchos::Array<size_t> lengthsFrom_;
228 
234  Teuchos::Array<int> procsFrom_;
235 
241  Teuchos::Array<size_t> startsFrom_;
242 
248  Teuchos::Array<size_t> indicesFrom_;
249 };
250 
251 }
252 }
253 
254 #endif
EDistributorHowInitialized
Enum indicating how and whether a Distributor was initialized.
std::string DistributorSendTypeEnumToString(EDistributorSendType sendType)
Convert an EDistributorSendType enum value to a string.
std::string DistributorHowInitializedEnumToString(EDistributorHowInitialized how)
Convert an EDistributorHowInitialized enum value to a string.
EDistributorSendType
The type of MPI send that Distributor should use.