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 
30 namespace 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> >
165  getVectorNonConst( size_t j )
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 
267  std::string description () const;
268 
270  void
271  describe (Teuchos::FancyOStream& os,
272  const Teuchos::EVerbosityLevel verbLevel =
273  Teuchos::Describable::verbLevel_default) const;
274 
275  private:
277  Teuchos::RCP<multivec_t> mv_;
278 
280  typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
281 
283  typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
284 
291  mutable Teuchos::RCP<export_type> exporter_;
292 
299  mutable Teuchos::RCP<import_type> importer_;
300  }; // end class MultiVecAdapter<Tpetra::MultiVector>
301 
302 } // end namespace Amesos2
303 
304 
305 #endif // AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
size_t getStride() const
Return the stride between vectors on this node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:142
Teuchos::RCP< import_type > importer_
Used for data redistribution from the solver&#39;s output MultiVector to the user&#39;s output MultiVector...
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:299
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:135
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:85
size_t getLocalNumVectors() const
Get the number of vectors on this node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:120
Teuchos::RCP< multivec_t > mv_
The multivector which this adapter wraps.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:277
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:283
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:280
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::RCP< export_type > exporter_
Used for data redistribution from the user&#39;s input MultiVector to the solver&#39;s input MultiVector...
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:291
size_t getLocalLength() const
Get the length of vectors local to the calling node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:113
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
EDistribution
Definition: Amesos2_TypeDecl.hpp:89
global_size_t getGlobalLength() const
Get the length of vectors in the global space.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:127
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:142
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
bool isConstantStride() const
Return true if this MV has constant stride between vectors on this node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:149