Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_TpetraMultiVecAdapter_decl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Amesos2: Templated Direct Sparse Solver Package
4//
5// Copyright 2011 NTESS and the Amesos2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
19#ifndef AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
20#define AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
21
22#include <Teuchos_RCP.hpp>
23#include <Teuchos_Array.hpp>
24#include <Teuchos_as.hpp>
25#include <Tpetra_MultiVector.hpp>
26#include <Tpetra_Vector_decl.hpp>
27
28#include "Amesos2_MultiVecAdapter_decl.hpp"
29
30namespace Amesos2 {
31
37 template< typename Scalar,
38 typename LocalOrdinal,
39 typename GlobalOrdinal,
40 class Node >
41 class MultiVecAdapter<Tpetra::MultiVector<Scalar,
42 LocalOrdinal,
43 GlobalOrdinal,
44 Node> >
45 {
46 public:
47 // public type definitions
48 typedef Tpetra::MultiVector<Scalar,
49 LocalOrdinal,
50 GlobalOrdinal,
51 Node> multivec_t;
52 typedef Scalar scalar_t;
53 typedef LocalOrdinal local_ordinal_t;
54 typedef GlobalOrdinal global_ordinal_t;
55 typedef Node node_t;
56 typedef Tpetra::global_size_t global_size_t;
57
58 friend Teuchos::RCP<MultiVecAdapter<multivec_t> > createMultiVecAdapter<> (Teuchos::RCP<multivec_t>);
59 friend Teuchos::RCP<const MultiVecAdapter<multivec_t> > createConstMultiVecAdapter<> (Teuchos::RCP<const multivec_t>);
60
61 static const char* name;
62
63 protected:
64 // Do not allow direct construction of MultiVecAdapter's. Only
65 // allow construction through the non-member friend functions.
66
69
75 MultiVecAdapter( const Teuchos::RCP<multivec_t>& m );
76
77
78 public:
79
81 { }
82
83
85 bool isLocallyIndexed() const
86 {
87 if(getComm()->getSize() == 1){
88 return true;
89 } // There may be other conditions to check
90 return false;
91 }
92
93 // TODO
94 bool isGloballyIndexed() const;
95
96
97 Teuchos::RCP<const Tpetra::Map<
98 local_ordinal_t,
99 global_ordinal_t,
100 node_t > >
101 getMap() const
102 {
103 return mv_->getMap();
104 }
105
107 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
108 {
109 return mv_->getMap()->getComm();
110 }
111
113 size_t getLocalLength() const
114 {
115 return Teuchos::as<size_t>(mv_->getLocalLength());
116 }
117
118
120 size_t getLocalNumVectors() const
121 {
122 return mv_->getNumVectors();
123 }
124
125
127 global_size_t getGlobalLength() const
128 {
129 return mv_->getGlobalLength();
130 //return getMap()->getMaxAllGlobalIndex() + 1;
131 }
132
133
135 global_size_t getGlobalNumVectors() const
136 {
137 return Teuchos::as<global_size_t>(mv_->getNumVectors());
138 }
139
140
142 size_t getStride() const
143 {
144 return mv_->getStride();
145 }
146
147
149 bool isConstantStride() const
150 {
151 return mv_->isConstantStride();
152 }
153
154
156 Teuchos::RCP<const Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
157 getVector( size_t j ) const
158 {
159 return mv_->getVector(j);
160 }
161
162
164 Teuchos::RCP<Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
166 {
167 return mv_->getVectorNonConst(j);
168 }
169
171 typename multivec_t::impl_scalar_type * getMVPointer_impl() const;
172
176 Teuchos::RCP<multivec_t>
177 clone() const;
178
207 void
208 get1dCopy (const Teuchos::ArrayView<scalar_t>& A,
209 size_t lda,
210 Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,
211 global_ordinal_t,
212 node_t> > distribution_map,
213 EDistribution distribution) const;
214
215 template<typename KV>
216 bool
217 get1dCopy_kokkos_view (bool bInitialize, KV& v,
218 size_t lda,
219 Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,
220 global_ordinal_t,
221 node_t> > distribution_map,
222 EDistribution distribution) const;
223
237 Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
238
248 void
249 put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
250 size_t lda,
251 Teuchos::Ptr< const Tpetra::Map<local_ordinal_t,
252 global_ordinal_t,
253 node_t> > source_map,
254 EDistribution distribution );
255
256 template<typename KV>
257 void
258 put1dData_kokkos_view (KV& kokkos_new_data,
259 size_t lda,
260 Teuchos::Ptr< const Tpetra::Map<local_ordinal_t,
261 global_ordinal_t,
262 node_t> > source_map,
263 EDistribution distribution );
264
265 template<typename KV, typename host_ordinal_type_array>
266 LocalOrdinal
267 gather (KV& kokkos_new_view,
268 host_ordinal_type_array &perm_g2l,
269 host_ordinal_type_array &recvCountRows,
270 host_ordinal_type_array &recvDisplRows,
271 EDistribution distribution) const;
272
273 template<typename KV, typename host_ordinal_type_array>
274 LocalOrdinal
275 scatter (KV& kokkos_new_view,
276 host_ordinal_type_array &perm_g2l,
277 host_ordinal_type_array &recvCountRows,
278 host_ordinal_type_array &recvDisplRows,
279 EDistribution distribution) const;
280
281
283 std::string description () const;
284
286 void
287 describe (Teuchos::FancyOStream& os,
288 const Teuchos::EVerbosityLevel verbLevel =
289 Teuchos::Describable::verbLevel_default) const;
290
291 private:
293 Teuchos::RCP<multivec_t> mv_;
294 mutable typename multivec_t::host_view_type buf_;
295
297 typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
298
300 typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
301
308 mutable Teuchos::RCP<export_type> exporter_;
309
316 mutable Teuchos::RCP<import_type> importer_;
317 }; // end class MultiVecAdapter<Tpetra::MultiVector>
318
319} // end namespace Amesos2
320
321
322#endif // AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
EDistribution
Definition Amesos2_TypeDecl.hpp:89
Tpetra::Import< local_ordinal_t, global_ordinal_t, node_t > import_type
The Tpetra::Import specialization used by this class.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:300
void put1dData(const Teuchos::ArrayView< const scalar_t > &new_data, size_t lda, Teuchos::Ptr< const Tpetra::Map< local_ordinal_t, global_ordinal_t, node_t > > source_map, EDistribution distribution)
Export data into the global MultiVector space.
multivec_t::impl_scalar_type * getMVPointer_impl() const
Return pointer to vector when number of vectors == 1 and single MPI process.
Teuchos::RCP< const Tpetra::Vector< scalar_t, local_ordinal_t, global_ordinal_t, node_t > > getVector(size_t j) const
Const vector access.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:157
Teuchos::RCP< Tpetra::Vector< scalar_t, local_ordinal_t, global_ordinal_t, node_t > > getVectorNonConst(size_t j)
Nonconst vector access.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:165
global_size_t getGlobalLength() const
Get the length of vectors in the global space.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:127
std::string description() const
Get a short description of this adapter class.
Teuchos::RCP< multivec_t > mv_
The multivector which this adapter wraps.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:293
Tpetra::Export< local_ordinal_t, global_ordinal_t, node_t > export_type
The Tpetra::Export specialization used by this class.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:297
Teuchos::RCP< export_type > exporter_
Used for data redistribution from the user's input MultiVector to the solver's input MultiVector.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:308
MultiVecAdapter(const MultiVecAdapter< multivec_t > &adapter)
Copy constructor.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this multi-vector.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:107
Teuchos::ArrayRCP< scalar_t > get1dViewNonConst(bool local=false)
Extracts a 1 dimensional view of this MultiVector's data.
size_t getLocalNumVectors() const
Get the number of vectors on this node.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:120
void describe(Teuchos::FancyOStream &os, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print a description of this adapter to the given output stream.
size_t getLocalLength() const
Get the length of vectors local to the calling node.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:113
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:85
size_t getStride() const
Return the stride between vectors on this node.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:142
void get1dCopy(const Teuchos::ArrayView< scalar_t > &A, size_t lda, Teuchos::Ptr< const Tpetra::Map< local_ordinal_t, global_ordinal_t, node_t > > distribution_map, EDistribution distribution) const
Copies the multivector's data into the user-provided vector.
MultiVecAdapter(const Teuchos::RCP< multivec_t > &m)
Initialize an adapter from a multi-vector RCP.
Teuchos::RCP< import_type > importer_
Used for data redistribution from the solver's output MultiVector to the user's output MultiVector.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:316
bool isConstantStride() const
Return true if this MV has constant stride between vectors on this node.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:149
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:135
A templated MultiVector class adapter for Amesos2.
Definition Amesos2_MultiVecAdapter_decl.hpp:142