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 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // ************************************************************************
38 // @HEADER
39 
52 #ifndef TPETRA_DETAILS_DISTRIBUTOR_PLAN_HPP
53 #define TPETRA_DETAILS_DISTRIBUTOR_PLAN_HPP
54 
55 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
56 #include "Teuchos_Array.hpp"
57 #include "Teuchos_Comm.hpp"
58 #include "Teuchos_RCP.hpp"
59 #include "TpetraCore_config.h"
60 
61 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
62 #include <mpi_advance.h>
63 #endif
64 
65 namespace Tpetra {
66 namespace Details {
67 
73  DISTRIBUTOR_ISEND, // Use MPI_Isend (Teuchos::isend)
74  DISTRIBUTOR_SEND, // Use MPI_Send (Teuchos::send)
75  DISTRIBUTOR_ALLTOALL // Use MPI_Alltoall
76 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
77  ,
78  DISTRIBUTOR_MPIADVANCE_ALLTOALL,
79  DISTRIBUTOR_MPIADVANCE_NBRALLTOALLV
80 #endif
81 };
82 
87 std::string
89 
95  DISTRIBUTOR_NOT_INITIALIZED, // Not initialized yet
96  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_SENDS, // By createFromSends
97  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_RECVS, // By createFromRecvs
98  DISTRIBUTOR_INITIALIZED_BY_CREATE_FROM_SENDS_N_RECVS, // By createFromSendsAndRecvs
99  DISTRIBUTOR_INITIALIZED_BY_REVERSE, // By createReverseDistributor
100  DISTRIBUTOR_INITIALIZED_BY_COPY, // By copy constructor
101 };
102 
107 std::string
109 
120 class DistributorPlan : public Teuchos::ParameterListAcceptorDefaultBase {
121  static constexpr int DEFAULT_MPI_TAG = 0;
122 
123 public:
124  DistributorPlan(Teuchos::RCP<const Teuchos::Comm<int>> comm);
125  DistributorPlan(const DistributorPlan& otherPlan);
126 
127  size_t createFromSends(const Teuchos::ArrayView<const int>& exportProcIDs);
128  void createFromRecvs(const Teuchos::ArrayView<const int>& remoteProcIDs);
129  void createFromSendsAndRecvs(const Teuchos::ArrayView<const int>& exportProcIDs,
130  const Teuchos::ArrayView<const int>& remoteProcIDs);
131 
132  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList>& plist);
133 
134  Teuchos::RCP<DistributorPlan> getReversePlan() const;
135 
136  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const { return comm_; }
137 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
138  Teuchos::RCP<MPIX_Comm*> getMPIXComm() const { return mpixComm_; }
139 #endif
140  EDistributorSendType getSendType() const { return sendType_; }
141  size_t getNumReceives() const { return numReceives_; }
142  size_t getNumSends() const { return numSendsToOtherProcs_; }
143  bool hasSelfMessage() const { return sendMessageToSelf_; }
144  size_t getMaxSendLength() const { return maxSendLength_; }
145  size_t getTotalReceiveLength() const { return totalReceiveLength_; }
146  Teuchos::ArrayView<const int> getProcsFrom() const { return procsFrom_; }
147  Teuchos::ArrayView<const int> getProcsTo() const { return procIdsToSendTo_; }
148  Teuchos::ArrayView<const size_t> getLengthsFrom() const { return lengthsFrom_; }
149  Teuchos::ArrayView<const size_t> getLengthsTo() const { return lengthsTo_; }
150  Teuchos::ArrayView<const size_t> getStartsTo() const { return startsTo_; }
151  Teuchos::ArrayView<const size_t> getIndicesTo() const { return indicesTo_; }
152  Details::EDistributorHowInitialized howInitialized() const { return howInitialized_; }
153 
154 private:
155 
156  // after the plan has been created we have the info we need to initialize the MPI advance communicator
157 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
158  void initializeMpiAdvance();
159 #endif
160 
161  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
162 
163  void createReversePlan() const;
164 
175  void computeReceives();
176 
177  Teuchos::RCP<const Teuchos::Comm<int>> comm_;
178 #if defined(HAVE_TPETRACORE_MPI_ADVANCE)
179  Teuchos::RCP<MPIX_Comm*> mpixComm_;
180 #endif
181 
182  Details::EDistributorHowInitialized howInitialized_;
183  mutable Teuchos::RCP<DistributorPlan> reversePlan_;
184 
186 
187  EDistributorSendType sendType_;
189 
190  bool sendMessageToSelf_;
191  size_t numSendsToOtherProcs_;
192  Teuchos::Array<int> procIdsToSendTo_;
193 
202  Teuchos::Array<size_t> startsTo_;
203 
209  Teuchos::Array<size_t> lengthsTo_;
210 
214  size_t maxSendLength_;
215 
231  Teuchos::Array<size_t> indicesTo_;
232 
242  size_t numReceives_;
243 
250  size_t totalReceiveLength_;
251 
257  Teuchos::Array<size_t> lengthsFrom_;
258 
264  Teuchos::Array<int> procsFrom_;
265 
271  Teuchos::Array<size_t> startsFrom_;
272 
278  Teuchos::Array<size_t> indicesFrom_;
279 };
280 
281 }
282 }
283 
284 #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.