Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_EpetraMultiVecAdapter_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_EPETRA_MULTIVEC_ADAPTER_DECL_HPP
54 #define AMESOS2_EPETRA_MULTIVEC_ADAPTER_DECL_HPP
55 
56 #include <Teuchos_RCP.hpp>
57 #include <Teuchos_Array.hpp>
58 #include <Teuchos_as.hpp>
59 
60 #include <Tpetra_Vector.hpp>
61 #include <Tpetra_Map.hpp>
62 
63 #include <Epetra_MultiVector.h>
64 
65 #include "Amesos2_MultiVecAdapter_decl.hpp"
67 
68 namespace Amesos2 {
69 
75  template <>
76  class MultiVecAdapter<Epetra_MultiVector>
77  {
78  public:
79 
80  // public type definitions
81  typedef double scalar_t;
82  typedef int local_ordinal_t;
83  typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
84  typedef size_t global_size_t;
85  typedef Tpetra::Map<>::node_type node_t;
86  typedef Epetra_MultiVector multivec_t;
87 
88  friend Teuchos::RCP<MultiVecAdapter<multivec_t> > createMultiVecAdapter<>(Teuchos::RCP<multivec_t>);
89  friend Teuchos::RCP<const MultiVecAdapter<multivec_t> > createConstMultiVecAdapter<>(Teuchos::RCP<const multivec_t>);
90 
91 
92  static const char* name;
93 
94 
95  protected:
98 
104  MultiVecAdapter( const Teuchos::RCP<multivec_t>& m );
105 
106 
107  public:
108 
109  ~MultiVecAdapter() = default;
110 
111 
113  bool isLocallyIndexed() const;
114 
115  bool isGloballyIndexed() const;
116 
117 
124  Teuchos::RCP<const Tpetra::Map<local_ordinal_t, global_ordinal_t, node_t> >
125  getMap() const;
126 
128  const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
129 
130 
132  size_t getLocalLength() const;
133 
134 
136  size_t getLocalNumVectors() const;
137 
138 
140  global_size_t getGlobalLength() const;
141 
142 
144  size_t getGlobalNumVectors() const;
145 
146 
148  size_t getStride() const;
149 
150 
152  bool isConstantStride() const;
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 
167  Teuchos::RCP<Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
168  getVectorNonConst( size_t j );
169 
170 
172  double * getMVPointer_impl() const;
173 
179  void get1dCopy( const Teuchos::ArrayView<scalar_t>& A,
180  size_t lda,
181  Teuchos::Ptr<
182  const Tpetra::Map<local_ordinal_t,
183  global_ordinal_t,
184  node_t> > distribution_map,
185  EDistribution distribution) const;
186 
187  template<typename KV>
188  void get1dCopy_kokkos_view( KV & A,
189  size_t lda,
190  Teuchos::Ptr<
191  const Tpetra::Map<local_ordinal_t,
192  global_ordinal_t,
193  node_t> > distribution_map,
194  EDistribution distribution) const {
195  Kokkos::View<double**, Kokkos::LayoutLeft, Kokkos::HostSpace> host_new_data;
196  get1dCopy_kokkos_view_host(host_new_data, lda, distribution_map, distribution);
197  deep_copy_or_assign_view(A, host_new_data);
198  }
199 
200  void get1dCopy_kokkos_view_host(
201  Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & new_data,
202  size_t lda,
203  Teuchos::Ptr<
204  const Tpetra::Map<local_ordinal_t,
205  global_ordinal_t,
206  node_t> > distribution_map,
207  EDistribution) const;
208 
226  Teuchos::ArrayRCP<scalar_t> get1dViewNonConst( bool local = false );
227 
228 
239  void put1dData( const Teuchos::ArrayView<const scalar_t>& new_data,
240  size_t lda,
241  Teuchos::Ptr<
242  const Tpetra::Map<local_ordinal_t,
243  global_ordinal_t,
244  node_t> > source_map,
245  EDistribution distribution );
246 
247  template<typename KV>
248  void put1dData_kokkos_view(
249  KV & new_data,
250  size_t lda,
251  Teuchos::Ptr<
252  const Tpetra::Map<local_ordinal_t,
253  global_ordinal_t,
254  node_t> > source_map,
255  EDistribution distribution ) {
256  Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> host_new_data(
257  Kokkos::ViewAllocateWithoutInitializing("host_new_data"),
258  new_data.extent(0), new_data.extent(1));
259  Kokkos::deep_copy(host_new_data, new_data);
260  put1dData_kokkos_view_host(host_new_data, lda, source_map, distribution);
261  }
262 
263  void put1dData_kokkos_view_host(
264  Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & new_data,
265  size_t lda,
266  Teuchos::Ptr<
267  const Tpetra::Map<local_ordinal_t,
268  global_ordinal_t,
269  node_t> > source_map,
270  EDistribution distribution );
271 
273  std::string description() const;
274 
275 
277  void describe( Teuchos::FancyOStream& os,
278  const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const;
279 
280 
281  private:
282 
284  Teuchos::RCP<multivec_t> mv_;
285 
286  mutable Teuchos::RCP<Epetra_Import> importer_;
287  mutable Teuchos::RCP<Epetra_Export> exporter_;
288 
289  mutable Teuchos::RCP<const Epetra_BlockMap> mv_map_;
290 
291  }; // end class MultiVecAdapter<NewMultiVec>
292 
293 } // end namespace Amesos2
294 
295 
296 #endif // AMESOS2_EPETRA_MULTIVEC_ADAPTER_DECL_HPP
Teuchos::RCP< multivec_t > mv_
The multi-vector this adapter wraps.
Definition: Amesos2_EpetraMultiVecAdapter_decl.hpp:284
Copy or assign views based on memory spaces.
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176