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 
64 namespace 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 
114  ~MultiVecAdapter()
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> >
199  getVectorNonConst( size_t j )
200  {
201  return mv_->getVectorNonConst(j);
202  }
203 
205  typename multivec_t::impl_scalar_type * getMVPointer_impl() const;
206 
235  void
236  get1dCopy (const Teuchos::ArrayView<scalar_t>& A,
237  size_t lda,
238  Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,
239  global_ordinal_t,
240  node_t> > distribution_map,
241  EDistribution distribution) const;
242 
256  Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
257 
267  void
268  put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
269  size_t lda,
270  Teuchos::Ptr< const Tpetra::Map<local_ordinal_t,
271  global_ordinal_t,
272  node_t> > source_map,
273  EDistribution distribution );
274 
276  std::string description () const;
277 
279  void
280  describe (Teuchos::FancyOStream& os,
281  const Teuchos::EVerbosityLevel verbLevel =
282  Teuchos::Describable::verbLevel_default) const;
283 
284  private:
286  Teuchos::RCP<multivec_t> mv_;
287 
289  typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
290 
292  typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
293 
300  mutable Teuchos::RCP<export_type> exporter_;
301 
308  mutable Teuchos::RCP<import_type> importer_;
309  }; // end class MultiVecAdapter<Tpetra::MultiVector>
310 
311 } // end namespace Amesos2
312 
313 
314 #endif // AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
size_t getStride() const
Return the stride between vectors on this node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:176
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:308
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:169
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:119
size_t getLocalNumVectors() const
Get the number of vectors on this node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:154
Teuchos::RCP< multivec_t > mv_
The multivector which this adapter wraps.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:286
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:292
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:289
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::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:300
size_t getLocalLength() const
Get the length of vectors local to the calling node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:147
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
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
global_size_t getGlobalLength() const
Get the length of vectors in the global space.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:161
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176
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
bool isConstantStride() const
Return true if this MV has constant stride between vectors on this node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:183