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 
62 DistributorSendTypeStringToEnum (const std::string_view s);
63 
65 Teuchos::Array<std::string> distributorSendTypes ();
66 
68 Teuchos::Array<EDistributorSendType> distributorSendTypeEnums ();
69 
71 Teuchos::Array<std::string> distributorSendTypes ();
72 
74 const std::string &validSendTypeOrThrow (const std::string &s);
75 
81  DISTRIBUTOR_NOT_INITIALIZED, // Not initialized yet
82  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_SENDS, // By createFromSends
83  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_RECVS, // By createFromRecvs
84  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_SENDS_N_RECVS, // By createFromSendsAndRecvs
85  DISTRIBUTOR_INITIALIZED_BY_REVERSE, // By createReverseDistributor
86  DISTRIBUTOR_INITIALIZED_BY_COPY, // By copy constructor
87 };
88 
93 std::string
95 
106 class DistributorPlan : public Teuchos::ParameterListAcceptorDefaultBase {
107  static constexpr int DEFAULT_MPI_TAG = 0;
108 
109 public:
110 
111  using IndexView = std::vector<size_t>;
112  using SubViewLimits = std::pair<IndexView, IndexView>;
113 
114  DistributorPlan(Teuchos::RCP<const Teuchos::Comm<int>> comm);
115  DistributorPlan(const DistributorPlan& otherPlan);
116 
117  size_t createFromSends(const Teuchos::ArrayView<const int>& exportProcIDs);
118  void createFromRecvs(const Teuchos::ArrayView<const int>& remoteProcIDs);
119  void createFromSendsAndRecvs(const Teuchos::ArrayView<const int>& exportProcIDs,
120  const Teuchos::ArrayView<const int>& remoteProcIDs);
121 
122  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList>& plist);
123 
124  Teuchos::RCP<DistributorPlan> getReversePlan() const;
125 
126  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const { return comm_; }
127 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
128  Teuchos::RCP<MPIX_Comm*> getMPIXComm() const { return mpixComm_; }
129 #endif
130  EDistributorSendType getSendType() const { return sendType_; }
131  size_t getNumReceives() const { return numReceives_; }
132  size_t getNumSends() const { return numSendsToOtherProcs_; }
133  bool hasSelfMessage() const { return sendMessageToSelf_; }
134  size_t getMaxSendLength() const { return maxSendLength_; }
135  size_t getTotalReceiveLength() const { return totalReceiveLength_; }
136  Teuchos::ArrayView<const int> getProcsFrom() const { return procsFrom_; }
137  Teuchos::ArrayView<const int> getProcsTo() const { return procIdsToSendTo_; }
138  Teuchos::ArrayView<const size_t> getLengthsFrom() const { return lengthsFrom_; }
139  Teuchos::ArrayView<const size_t> getLengthsTo() const { return lengthsTo_; }
140  Teuchos::ArrayView<const size_t> getStartsTo() const { return startsTo_; }
141  Teuchos::ArrayView<const size_t> getIndicesTo() const { return indicesTo_; }
142  Details::EDistributorHowInitialized howInitialized() const { return howInitialized_; }
143 
144  SubViewLimits getImportViewLimits(size_t numPackets) const;
145  SubViewLimits getImportViewLimits(const Teuchos::ArrayView<const size_t> &numImportPacketsPerLID) const;
146  SubViewLimits getExportViewLimits(size_t numPackets) const;
147  SubViewLimits getExportViewLimits(const Teuchos::ArrayView<const size_t> &numExportPacketsPerLID) const;
148 
149 private:
150 
151  // after the plan has been created we have the info we need to initialize the MPI advance communicator
152 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
153  void initializeMpiAdvance();
154 #endif
155 
156  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
157 
158  void createReversePlan() const;
159 
170  void computeReceives();
171 
172  Teuchos::RCP<const Teuchos::Comm<int>> comm_;
173 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
174  Teuchos::RCP<MPIX_Comm*> mpixComm_;
175 #endif
176 
177  Details::EDistributorHowInitialized howInitialized_;
178  mutable Teuchos::RCP<DistributorPlan> reversePlan_;
179 
181 
182  EDistributorSendType sendType_;
184 
185  bool sendMessageToSelf_;
186  size_t numSendsToOtherProcs_;
187  Teuchos::Array<int> procIdsToSendTo_;
188 
197  Teuchos::Array<size_t> startsTo_;
198 
204  Teuchos::Array<size_t> lengthsTo_;
205 
209  size_t maxSendLength_;
210 
226  Teuchos::Array<size_t> indicesTo_;
227 
237  size_t numReceives_;
238 
245  size_t totalReceiveLength_;
246 
252  Teuchos::Array<size_t> lengthsFrom_;
253 
259  Teuchos::Array<int> procsFrom_;
260 
266  Teuchos::Array<size_t> startsFrom_;
267 
273  Teuchos::Array<size_t> indicesFrom_;
274 };
275 
276 }
277 }
278 
279 #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.