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 typedef typename multivec_t::dual_view_type::t_host::value_type host_value_t;
58
59 friend Teuchos::RCP<MultiVecAdapter<multivec_t> > createMultiVecAdapter<> (Teuchos::RCP<multivec_t>);
60 friend Teuchos::RCP<const MultiVecAdapter<multivec_t> > createConstMultiVecAdapter<> (Teuchos::RCP<const multivec_t>);
61
62 static const char* name;
63
64 protected:
65 // Do not allow direct construction of MultiVecAdapter's. Only
66 // allow construction through the non-member friend functions.
67
70
76 MultiVecAdapter( const Teuchos::RCP<multivec_t>& m );
77
78
79 public:
80
82 { }
83
84
86 bool isLocallyIndexed() const
87 {
88 if(getComm()->getSize() == 1){
89 return true;
90 } // There may be other conditions to check
91 return false;
92 }
93
94 // TODO
95 bool isGloballyIndexed() const;
96
97
98 Teuchos::RCP<const Tpetra::Map<
99 local_ordinal_t,
100 global_ordinal_t,
101 node_t > >
102 getMap() const
103 {
104 return mv_->getMap();
105 }
106
108 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
109 {
110 return mv_->getMap()->getComm();
111 }
112
114 size_t getLocalLength() const
115 {
116 return Teuchos::as<size_t>(mv_->getLocalLength());
117 }
118
119
121 size_t getLocalNumVectors() const
122 {
123 return mv_->getNumVectors();
124 }
125
126
128 global_size_t getGlobalLength() const
129 {
130 return mv_->getGlobalLength();
131 //return getMap()->getMaxAllGlobalIndex() + 1;
132 }
133
134
136 global_size_t getGlobalNumVectors() const
137 {
138 return Teuchos::as<global_size_t>(mv_->getNumVectors());
139 }
140
141
143 size_t getStride() const
144 {
145 return mv_->getStride();
146 }
147
148
150 bool isConstantStride() const
151 {
152 return mv_->isConstantStride();
153 }
154
155
157 Teuchos::RCP<const Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
158 getVector( size_t j ) const
159 {
160 return mv_->getVector(j);
161 }
162
163
165 Teuchos::RCP<Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
167 {
168 return mv_->getVectorNonConst(j);
169 }
170
172 typename multivec_t::impl_scalar_type * getMVPointer_impl() const;
173
177 Teuchos::RCP<multivec_t>
178 clone() const;
179
208 void
209 get1dCopy (const Teuchos::ArrayView<scalar_t>& A,
210 size_t lda,
211 Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,
212 global_ordinal_t,
213 node_t> > distribution_map,
214 EDistribution distribution) const;
215
216 template<typename KV>
217 bool
218 get1dCopy_kokkos_view (bool bInitialize, KV& v,
219 size_t lda,
220 Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,
221 global_ordinal_t,
222 node_t> > distribution_map,
223 EDistribution distribution) const;
224
238 Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
239
249 void
250 put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
251 size_t lda,
252 Teuchos::Ptr< const Tpetra::Map<local_ordinal_t,
253 global_ordinal_t,
254 node_t> > source_map,
255 EDistribution distribution );
256
257 template<typename KV>
258 void
259 put1dData_kokkos_view (KV& kokkos_new_data,
260 size_t lda,
261 Teuchos::Ptr< const Tpetra::Map<local_ordinal_t,
262 global_ordinal_t,
263 node_t> > source_map,
264 EDistribution distribution );
265
266 template<typename KV, typename host_ordinal_type_array>
267 LocalOrdinal
268 gather (KV& kokkos_new_view,
269 host_ordinal_type_array &perm_g2l,
270 host_ordinal_type_array &recvCountRows,
271 host_ordinal_type_array &recvDisplRows,
272 EDistribution distribution) const;
273
274 template<typename KV, typename host_ordinal_type_array>
275 LocalOrdinal
276 scatter (KV& kokkos_new_view,
277 host_ordinal_type_array &perm_g2l,
278 host_ordinal_type_array &recvCountRows,
279 host_ordinal_type_array &recvDisplRows,
280 EDistribution distribution) const;
281
282
284 std::string description () const;
285
287 void
288 describe (Teuchos::FancyOStream& os,
289 const Teuchos::EVerbosityLevel verbLevel =
290 Teuchos::Describable::verbLevel_default) const;
291
292 private:
294 Teuchos::RCP<multivec_t> mv_;
295 mutable typename multivec_t::host_view_type buf_;
296
298 typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
299
301 typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
302
309 mutable Teuchos::RCP<export_type> exporter_;
310
317 mutable Teuchos::RCP<import_type> importer_;
318 }; // end class MultiVecAdapter<Tpetra::MultiVector>
319
320} // end namespace Amesos2
321
322
323#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:301
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:158
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:166
global_size_t getGlobalLength() const
Get the length of vectors in the global space.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:128
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:294
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:298
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:309
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:108
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:121
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:114
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:86
size_t getStride() const
Return the stride between vectors on this node.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:143
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:317
bool isConstantStride() const
Return true if this MV has constant stride between vectors on this node.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:150
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition Amesos2_TpetraMultiVecAdapter_decl.hpp:136
A templated MultiVector class adapter for Amesos2.
Definition Amesos2_MultiVecAdapter_decl.hpp:142