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_TPETRA_MPI)
47  ,
48  DISTRIBUTOR_IALLTOFEWV
49 #endif
50 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
51  ,
52  DISTRIBUTOR_MPIADVANCE_ALLTOALL,
53  DISTRIBUTOR_MPIADVANCE_NBRALLTOALLV
54 #endif
55 };
56 
61 std::string
63 
66 DistributorSendTypeStringToEnum (const std::string_view s);
67 
69 Teuchos::Array<std::string> distributorSendTypes ();
70 
72 Teuchos::Array<EDistributorSendType> distributorSendTypeEnums ();
73 
75 Teuchos::Array<std::string> distributorSendTypes ();
76 
78 const std::string &validSendTypeOrThrow (const std::string &s);
79 
85  DISTRIBUTOR_NOT_INITIALIZED, // Not initialized yet
86  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_SENDS, // By createFromSends
87  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_RECVS, // By createFromRecvs
88  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_SENDS_N_RECVS, // By createFromSendsAndRecvs
89  DISTRIBUTOR_INITIALIZED_BY_REVERSE, // By createReverseDistributor
90  DISTRIBUTOR_INITIALIZED_BY_COPY, // By copy constructor
91 };
92 
97 std::string
99 
110 class DistributorPlan : public Teuchos::ParameterListAcceptorDefaultBase {
111  static constexpr int DEFAULT_MPI_TAG = 0;
112 
113 public:
114 
115  using IndexView = std::vector<size_t>;
116  using SubViewLimits = std::pair<IndexView, IndexView>;
117 
118  DistributorPlan(Teuchos::RCP<const Teuchos::Comm<int>> comm);
119  DistributorPlan(const DistributorPlan& otherPlan);
120 
121  size_t createFromSends(const Teuchos::ArrayView<const int>& exportProcIDs);
122  void createFromRecvs(const Teuchos::ArrayView<const int>& remoteProcIDs);
123  void createFromSendsAndRecvs(const Teuchos::ArrayView<const int>& exportProcIDs,
124  const Teuchos::ArrayView<const int>& remoteProcIDs);
125 
126  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList>& plist);
127 
128  Teuchos::RCP<DistributorPlan> getReversePlan() const;
129 
130  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const { return comm_; }
131 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
132  Teuchos::RCP<MPIX_Comm*> getMPIXComm() const { return mpixComm_; }
133 #endif
134  EDistributorSendType getSendType() const { return sendType_; }
135  size_t getNumReceives() const { return numReceives_; }
136  size_t getNumSends() const { return numSendsToOtherProcs_; }
137  bool hasSelfMessage() const { return sendMessageToSelf_; }
138  size_t getMaxSendLength() const { return maxSendLength_; }
139  size_t getTotalReceiveLength() const { return totalReceiveLength_; }
140  Teuchos::ArrayView<const int> getProcsFrom() const { return procsFrom_; }
141  Teuchos::ArrayView<const int> getProcsTo() const { return procIdsToSendTo_; }
142  Teuchos::ArrayView<const size_t> getLengthsFrom() const { return lengthsFrom_; }
143  Teuchos::ArrayView<const size_t> getLengthsTo() const { return lengthsTo_; }
144  Teuchos::ArrayView<const size_t> getStartsTo() const { return startsTo_; }
145  Teuchos::ArrayView<const size_t> getIndicesTo() const { return indicesTo_; }
146  Details::EDistributorHowInitialized howInitialized() const { return howInitialized_; }
147 
148  SubViewLimits getImportViewLimits(size_t numPackets) const;
149  SubViewLimits getImportViewLimits(const Teuchos::ArrayView<const size_t> &numImportPacketsPerLID) const;
150  SubViewLimits getExportViewLimits(size_t numPackets) const;
151  SubViewLimits getExportViewLimits(const Teuchos::ArrayView<const size_t> &numExportPacketsPerLID) const;
152 
153 #if defined(HAVE_TPETRA_MPI)
154  const std::vector<int> getRoots() const {
155  return roots_;
156  }
157 #endif
158 private:
159 
160  // after the plan has been created we have the info we need to initialize the MPI advance communicator
161 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
162  void initializeMpiAdvance();
163 #endif
164 
165 #if defined(HAVE_TPETRA_MPI)
166  void maybeInitializeRoots();
167 #endif
168 
169  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
170 
171  void createReversePlan() const;
172 
183  void computeReceives();
184 
185  Teuchos::RCP<const Teuchos::Comm<int>> comm_;
186 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
187  Teuchos::RCP<MPIX_Comm*> mpixComm_;
188 #endif
189 
190  Details::EDistributorHowInitialized howInitialized_;
191  mutable Teuchos::RCP<DistributorPlan> reversePlan_;
192 
194 
195  EDistributorSendType sendType_;
197 
198  bool sendMessageToSelf_;
199  size_t numSendsToOtherProcs_;
200  Teuchos::Array<int> procIdsToSendTo_;
201 
210  Teuchos::Array<size_t> startsTo_;
211 
217  Teuchos::Array<size_t> lengthsTo_;
218 
222  size_t maxSendLength_;
223 
239  Teuchos::Array<size_t> indicesTo_;
240 
250  size_t numReceives_;
251 
258  size_t totalReceiveLength_;
259 
265  Teuchos::Array<size_t> lengthsFrom_;
266 
272  Teuchos::Array<int> procsFrom_;
273 
279  Teuchos::Array<size_t> startsFrom_;
280 
286  Teuchos::Array<size_t> indicesFrom_;
287 
288 #if defined(HAVE_TPETRA_MPI)
289  std::vector<int> roots_;
294 
295 #endif
296 };
297 
298 }
299 }
300 
301 #endif
EDistributorHowInitialized
Enum indicating how and whether a Distributor was initialized.
const std::string & validSendTypeOrThrow(const std::string &s)
Valid enum values of distributor send types.
std::string DistributorSendTypeEnumToString(EDistributorSendType sendType)
Convert an EDistributorSendType enum value to a string.
EDistributorSendType DistributorSendTypeStringToEnum(const std::string_view s)
Convert a string to an EDistributorSendType. Throw on error.
Teuchos::Array< EDistributorSendType > distributorSendTypeEnums()
Valid enum values of distributor send types.
std::string DistributorHowInitializedEnumToString(EDistributorHowInitialized how)
Convert an EDistributorHowInitialized enum value to a string.
Teuchos::Array< std::string > distributorSendTypes()
Valid string values for Distributor&#39;s &quot;Send type&quot; parameter.
EDistributorSendType
The type of MPI send that Distributor should use.