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  using IndexView = std::vector<size_t>;
115  using SubViewLimits = std::pair<IndexView, IndexView>;
116 
117  DistributorPlan(Teuchos::RCP<const Teuchos::Comm<int>> comm);
118  DistributorPlan(const DistributorPlan& otherPlan);
119 
120  size_t createFromSends(const Teuchos::ArrayView<const int>& exportProcIDs);
121  void createFromRecvs(const Teuchos::ArrayView<const int>& remoteProcIDs);
122  void createFromSendsAndRecvs(const Teuchos::ArrayView<const int>& exportProcIDs,
123  const Teuchos::ArrayView<const int>& remoteProcIDs);
124 
125  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList>& plist);
126 
127  Teuchos::RCP<DistributorPlan> getReversePlan() const;
128 
129  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const { return comm_; }
130 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
131  Teuchos::RCP<MPIX_Comm*> getMPIXComm() const { return mpixComm_; }
132 #endif
133  EDistributorSendType getSendType() const { return sendType_; }
134  size_t getNumReceives() const { return numReceives_; }
135  size_t getNumSends() const { return numSendsToOtherProcs_; }
136  bool hasSelfMessage() const { return sendMessageToSelf_; }
137  size_t getMaxSendLength() const { return maxSendLength_; }
138  size_t getTotalReceiveLength() const { return totalReceiveLength_; }
139  Teuchos::ArrayView<const int> getProcsFrom() const { return procsFrom_; }
140  Teuchos::ArrayView<const int> getProcsTo() const { return procIdsToSendTo_; }
141  Teuchos::ArrayView<const size_t> getLengthsFrom() const { return lengthsFrom_; }
142  Teuchos::ArrayView<const size_t> getLengthsTo() const { return lengthsTo_; }
143  Teuchos::ArrayView<const size_t> getStartsTo() const { return startsTo_; }
144  Teuchos::ArrayView<const size_t> getIndicesTo() const { return indicesTo_; }
145  Details::EDistributorHowInitialized howInitialized() const { return howInitialized_; }
146 
147  SubViewLimits getImportViewLimits(size_t numPackets) const;
148  SubViewLimits getImportViewLimits(const Teuchos::ArrayView<const size_t>& numImportPacketsPerLID) const;
149  SubViewLimits getExportViewLimits(size_t numPackets) const;
150  SubViewLimits getExportViewLimits(const Teuchos::ArrayView<const size_t>& numExportPacketsPerLID) const;
151 
152 #if defined(HAVE_TPETRA_MPI)
153  const std::vector<int> getRoots() const {
154  return roots_;
155  }
156 #endif
157  private:
158  // after the plan has been created we have the info we need to initialize the MPI advance communicator
159 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
160  void initializeMpiAdvance();
161 #endif
162 
163 #if defined(HAVE_TPETRA_MPI)
164  void maybeInitializeRoots();
165 #endif
166 
167  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
168 
169  void createReversePlan() const;
170 
181  void computeReceives();
182 
183  Teuchos::RCP<const Teuchos::Comm<int>> comm_;
184 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
185  Teuchos::RCP<MPIX_Comm*> mpixComm_;
186 #endif
187 
188  Details::EDistributorHowInitialized howInitialized_;
189  mutable Teuchos::RCP<DistributorPlan> reversePlan_;
190 
192 
193  EDistributorSendType sendType_;
195 
196  bool sendMessageToSelf_;
197  size_t numSendsToOtherProcs_;
198  Teuchos::Array<int> procIdsToSendTo_;
199 
208  Teuchos::Array<size_t> startsTo_;
209 
215  Teuchos::Array<size_t> lengthsTo_;
216 
220  size_t maxSendLength_;
221 
237  Teuchos::Array<size_t> indicesTo_;
238 
248  size_t numReceives_;
249 
256  size_t totalReceiveLength_;
257 
263  Teuchos::Array<size_t> lengthsFrom_;
264 
270  Teuchos::Array<int> procsFrom_;
271 
277  Teuchos::Array<size_t> startsFrom_;
278 
284  Teuchos::Array<size_t> indicesFrom_;
285 
286 #if defined(HAVE_TPETRA_MPI)
287  std::vector<int> roots_;
292 
293 #endif
294 };
295 
296 } // namespace Details
297 } // namespace Tpetra
298 
299 #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.