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
68namespace 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 bool get1dCopy_kokkos_view(bool bInitialize, 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 bool bAssigned;
198 deep_copy_or_assign_view(bInitialize, A, host_new_data, bAssigned);
199 return false; // currently Epetra and prior get1dCopy_kokkos_view_host call cannot get direct assignment so always return false
200 }
201
202 void get1dCopy_kokkos_view_host(
203 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & new_data,
204 size_t lda,
205 Teuchos::Ptr<
206 const Tpetra::Map<local_ordinal_t,
207 global_ordinal_t,
208 node_t> > distribution_map,
209 EDistribution) const;
210
228 Teuchos::ArrayRCP<scalar_t> get1dViewNonConst( bool local = false );
229
230
241 void put1dData( const Teuchos::ArrayView<const scalar_t>& new_data,
242 size_t lda,
243 Teuchos::Ptr<
244 const Tpetra::Map<local_ordinal_t,
245 global_ordinal_t,
246 node_t> > source_map,
247 EDistribution distribution );
248
249 template<typename KV>
250 void put1dData_kokkos_view(
251 KV & new_data,
252 size_t lda,
253 Teuchos::Ptr<
254 const Tpetra::Map<local_ordinal_t,
255 global_ordinal_t,
256 node_t> > source_map,
257 EDistribution distribution ) {
258 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> host_new_data(
259 Kokkos::ViewAllocateWithoutInitializing("host_new_data"),
260 new_data.extent(0), new_data.extent(1));
261 Kokkos::deep_copy(host_new_data, new_data);
262 put1dData_kokkos_view_host(host_new_data, lda, source_map, distribution);
263 }
264
265 void put1dData_kokkos_view_host(
266 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & new_data,
267 size_t lda,
268 Teuchos::Ptr<
269 const Tpetra::Map<local_ordinal_t,
270 global_ordinal_t,
271 node_t> > source_map,
272 EDistribution distribution );
273
275 std::string description() const;
276
277
279 void describe( Teuchos::FancyOStream& os,
280 const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const;
281
282
283 private:
284
286 Teuchos::RCP<multivec_t> mv_;
287
288 mutable Teuchos::RCP<Epetra_Import> importer_;
289 mutable Teuchos::RCP<Epetra_Export> exporter_;
290
291 mutable Teuchos::RCP<const Epetra_BlockMap> mv_map_;
292
293 }; // end class MultiVecAdapter<NewMultiVec>
294
295} // end namespace Amesos2
296
297
298#endif // AMESOS2_EPETRA_MULTIVEC_ADAPTER_DECL_HPP
Copy or assign views based on memory spaces.
Teuchos::RCP< multivec_t > mv_
The multi-vector this adapter wraps.
Definition: Amesos2_EpetraMultiVecAdapter_decl.hpp:286
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176