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 
95  using IndexView = std::vector<size_t>;
96  using SubViewLimits = std::pair<IndexView, IndexView>;
97 
98  DistributorPlan(Teuchos::RCP<const Teuchos::Comm<int>> comm);
99  DistributorPlan(const DistributorPlan& otherPlan);
100 
101  size_t createFromSends(const Teuchos::ArrayView<const int>& exportProcIDs);
102  void createFromRecvs(const Teuchos::ArrayView<const int>& remoteProcIDs);
103  void createFromSendsAndRecvs(const Teuchos::ArrayView<const int>& exportProcIDs,
104  const Teuchos::ArrayView<const int>& remoteProcIDs);
105 
106  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList>& plist);
107 
108  Teuchos::RCP<DistributorPlan> getReversePlan() const;
109 
110  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const { return comm_; }
111 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
112  Teuchos::RCP<MPIX_Comm*> getMPIXComm() const { return mpixComm_; }
113 #endif
114  EDistributorSendType getSendType() const { return sendType_; }
115  size_t getNumReceives() const { return numReceives_; }
116  size_t getNumSends() const { return numSendsToOtherProcs_; }
117  bool hasSelfMessage() const { return sendMessageToSelf_; }
118  size_t getMaxSendLength() const { return maxSendLength_; }
119  size_t getTotalReceiveLength() const { return totalReceiveLength_; }
120  Teuchos::ArrayView<const int> getProcsFrom() const { return procsFrom_; }
121  Teuchos::ArrayView<const int> getProcsTo() const { return procIdsToSendTo_; }
122  Teuchos::ArrayView<const size_t> getLengthsFrom() const { return lengthsFrom_; }
123  Teuchos::ArrayView<const size_t> getLengthsTo() const { return lengthsTo_; }
124  Teuchos::ArrayView<const size_t> getStartsTo() const { return startsTo_; }
125  Teuchos::ArrayView<const size_t> getIndicesTo() const { return indicesTo_; }
126  Details::EDistributorHowInitialized howInitialized() const { return howInitialized_; }
127 
128  SubViewLimits getImportViewLimits(size_t numPackets) const;
129  SubViewLimits getImportViewLimits(const Teuchos::ArrayView<const size_t> &numImportPacketsPerLID) const;
130  SubViewLimits getExportViewLimits(size_t numPackets) const;
131  SubViewLimits getExportViewLimits(const Teuchos::ArrayView<const size_t> &numExportPacketsPerLID) const;
132 
133 private:
134 
135  // after the plan has been created we have the info we need to initialize the MPI advance communicator
136 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
137  void initializeMpiAdvance();
138 #endif
139 
140  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
141 
142  void createReversePlan() const;
143 
154  void computeReceives();
155 
156  Teuchos::RCP<const Teuchos::Comm<int>> comm_;
157 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
158  Teuchos::RCP<MPIX_Comm*> mpixComm_;
159 #endif
160 
161  Details::EDistributorHowInitialized howInitialized_;
162  mutable Teuchos::RCP<DistributorPlan> reversePlan_;
163 
165 
166  EDistributorSendType sendType_;
168 
169  bool sendMessageToSelf_;
170  size_t numSendsToOtherProcs_;
171  Teuchos::Array<int> procIdsToSendTo_;
172 
181  Teuchos::Array<size_t> startsTo_;
182 
188  Teuchos::Array<size_t> lengthsTo_;
189 
193  size_t maxSendLength_;
194 
210  Teuchos::Array<size_t> indicesTo_;
211 
221  size_t numReceives_;
222 
229  size_t totalReceiveLength_;
230 
236  Teuchos::Array<size_t> lengthsFrom_;
237 
243  Teuchos::Array<int> procsFrom_;
244 
250  Teuchos::Array<size_t> startsFrom_;
251 
257  Teuchos::Array<size_t> indicesFrom_;
258 };
259 
260 }
261 }
262 
263 #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.