Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_TpetraMultiVecAdapter_decl.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// Amesos2: Templated Direct Sparse Solver Package
6// Copyright 2011 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39//
40// ***********************************************************************
41//
42// @HEADER
43
53#ifndef AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
54#define AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
55
56#include <Teuchos_RCP.hpp>
57#include <Teuchos_Array.hpp>
58#include <Teuchos_as.hpp>
59#include <Tpetra_MultiVector.hpp>
60#include <Tpetra_Vector_decl.hpp>
61
62#include "Amesos2_MultiVecAdapter_decl.hpp"
63
64namespace Amesos2 {
65
71 template< typename Scalar,
72 typename LocalOrdinal,
73 typename GlobalOrdinal,
74 class Node >
75 class MultiVecAdapter<Tpetra::MultiVector<Scalar,
76 LocalOrdinal,
77 GlobalOrdinal,
78 Node> >
79 {
80 public:
81 // public type definitions
82 typedef Tpetra::MultiVector<Scalar,
83 LocalOrdinal,
84 GlobalOrdinal,
85 Node> multivec_t;
86 typedef Scalar scalar_t;
87 typedef LocalOrdinal local_ordinal_t;
88 typedef GlobalOrdinal global_ordinal_t;
89 typedef Node node_t;
90 typedef Tpetra::global_size_t global_size_t;
91
92 friend Teuchos::RCP<MultiVecAdapter<multivec_t> > createMultiVecAdapter<> (Teuchos::RCP<multivec_t>);
93 friend Teuchos::RCP<const MultiVecAdapter<multivec_t> > createConstMultiVecAdapter<> (Teuchos::RCP<const multivec_t>);
94
95 static const char* name;
96
97 protected:
98 // Do not allow direct construction of MultiVecAdapter's. Only
99 // allow construction through the non-member friend functions.
100
103
109 MultiVecAdapter( const Teuchos::RCP<multivec_t>& m );
110
111
112 public:
113
115 { }
116
117
119 bool isLocallyIndexed() const
120 {
121 if(getComm()->getSize() == 1){
122 return true;
123 } // There may be other conditions to check
124 return false;
125 }
126
127 // TODO
128 bool isGloballyIndexed() const;
129
130
131 Teuchos::RCP<const Tpetra::Map<
132 local_ordinal_t,
133 global_ordinal_t,
134 node_t > >
135 getMap() const
136 {
137 return mv_->getMap();
138 }
139
141 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
142 {
143 return mv_->getMap()->getComm();
144 }
145
147 size_t getLocalLength() const
148 {
149 return Teuchos::as<size_t>(mv_->getLocalLength());
150 }
151
152
154 size_t getLocalNumVectors() const
155 {
156 return mv_->getNumVectors();
157 }
158
159
161 global_size_t getGlobalLength() const
162 {
163 return mv_->getGlobalLength();
164 //return getMap()->getMaxAllGlobalIndex() + 1;
165 }
166
167
169 global_size_t getGlobalNumVectors() const
170 {
171 return Teuchos::as<global_size_t>(mv_->getNumVectors());
172 }
173
174
176 size_t getStride() const
177 {
178 return mv_->getStride();
179 }
180
181
183 bool isConstantStride() const
184 {
185 return mv_->isConstantStride();
186 }
187
188
190 Teuchos::RCP<const Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
191 getVector( size_t j ) const
192 {
193 return mv_->getVector(j);
194 }
195
196
198 Teuchos::RCP<Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
200 {
201 return mv_->getVectorNonConst(j);
202 }
203
205 typename multivec_t::impl_scalar_type * getMVPointer_impl() const;
206
210 Teuchos::RCP<multivec_t>
211 clone() const;
212
241 void
242 get1dCopy (const Teuchos::ArrayView<scalar_t>& A,
243 size_t lda,
244 Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,
245 global_ordinal_t,
246 node_t> > distribution_map,
247 EDistribution distribution) const;
248
249 template<typename KV>
250 bool
251 get1dCopy_kokkos_view (bool bInitialize, KV& v,
252 size_t lda,
253 Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,
254 global_ordinal_t,
255 node_t> > distribution_map,
256 EDistribution distribution) const;
257
271 Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
272
282 void
283 put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
284 size_t lda,
285 Teuchos::Ptr< const Tpetra::Map<local_ordinal_t,
286 global_ordinal_t,
287 node_t> > source_map,
288 EDistribution distribution );
289
290 template<typename KV>
291 void
292 put1dData_kokkos_view (KV& kokkos_new_data,
293 size_t lda,
294 Teuchos::Ptr< const Tpetra::Map<local_ordinal_t,
295 global_ordinal_t,
296 node_t> > source_map,
297 EDistribution distribution );
298
299
301 std::string description () const;
302
304 void
305 describe (Teuchos::FancyOStream& os,
306 const Teuchos::EVerbosityLevel verbLevel =
307 Teuchos::Describable::verbLevel_default) const;
308
309 private:
311 Teuchos::RCP<multivec_t> mv_;
312
314 typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
315
317 typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
318
325 mutable Teuchos::RCP<export_type> exporter_;
326
333 mutable Teuchos::RCP<import_type> importer_;
334 }; // end class MultiVecAdapter<Tpetra::MultiVector>
335
336} // end namespace Amesos2
337
338
339#endif // AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
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:317
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:191
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:199
global_size_t getGlobalLength() const
Get the length of vectors in the global space.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:161
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:311
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:314
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:325
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:141
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:154
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:147
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:119
size_t getStride() const
Return the stride between vectors on this node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:176
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:333
bool isConstantStride() const
Return true if this MV has constant stride between vectors on this node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:183
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:169
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176