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 
61 #include "Amesos2_MultiVecAdapter_decl.hpp"
62 
63 namespace Amesos2 {
64 
70  template< typename Scalar,
71  typename LocalOrdinal,
72  typename GlobalOrdinal,
73  class Node >
74  class MultiVecAdapter<Tpetra::MultiVector<Scalar,
75  LocalOrdinal,
76  GlobalOrdinal,
77  Node> >
78  {
79  public:
80 
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 
98  protected:
99  // Do not allow direct construction of MultiVecAdapter's. Only
100  // allow construction throw the non-member friend functions.
101 
104 
110  MultiVecAdapter( const Teuchos::RCP<multivec_t>& m );
111 
112 
113  public:
114 
115  ~MultiVecAdapter()
116  { }
117 
118 
120  bool isLocallyIndexed() const
121  {
122  if(getComm()->getSize() == 1){
123  return true;
124  } // There may be other conditions to check
125  }
126 
127  // TODO
128  bool isGloballyIndexed() const;
129 
130 
131  const 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  const Teuchos::RCP<const Teuchos::Comm<int> >& getComm() const
142  {
143  return 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 
204 
231  void get1dCopy( const Teuchos::ArrayView<scalar_t>& A,
232  size_t lda,
233  Teuchos::Ptr<
234  const Tpetra::Map<local_ordinal_t,
235  global_ordinal_t,
236  node_t> > distribution_map ) const;
237 
251  Teuchos::ArrayRCP<scalar_t> get1dViewNonConst( bool local = false );
252 
261  void put1dData( const Teuchos::ArrayView<const scalar_t>& new_data,
262  size_t lda,
263  Teuchos::Ptr<
264  const Tpetra::Map<local_ordinal_t,
265  global_ordinal_t,
266  node_t> > source_map );
267 
268 
270  std::string description() const;
271 
272 
274  void describe( Teuchos::FancyOStream& os,
275  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default ) const;
276 
277 
278  private:
279 
281  Teuchos::RCP<multivec_t> mv_;
282 
283 
285  mutable Teuchos::RCP<Tpetra::Import<local_ordinal_t,
286  global_ordinal_t,
287  node_t> > importer_;
288  mutable Teuchos::RCP<Tpetra::Export<local_ordinal_t,
289  global_ordinal_t,
290  node_t> > exporter_;
291 
293  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,
294  global_ordinal_t,
295  node_t> > mv_map_;
296 
297  }; // end class MultiVecAdapter<Tpetra::MultiVector>
298 
299 } // end namespace Amesos2
300 
301 
302 #endif // AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
Teuchos::RCP< const Tpetra::Map< local_ordinal_t, global_ordinal_t, node_t > > mv_map_
The adapted multivector&#39;s map.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:295
size_t getStride() const
Return the stride between vectors on this node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:176
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:169
Teuchos::RCP< Tpetra::Import< local_ordinal_t, global_ordinal_t, node_t > > importer_
Used for transferring between local and global multivectors.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:287
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:120
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 this adapter wraps.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:281
const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Returns the Teuchos::Comm object associated with this multi-vector.
Definition: Amesos2_TpetraMultiVecAdapter_decl.hpp:141
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
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:175
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