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:
97 MultiVecAdapter( const MultiVecAdapter<multivec_t>& adapter );
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
118 Teuchos::RCP<Epetra_MultiVector> clone() const;
119
126 Teuchos::RCP<const Tpetra::Map<local_ordinal_t, global_ordinal_t, node_t> >
127 getMap() const;
128
130 const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
131
132
134 size_t getLocalLength() const;
135
136
138 size_t getLocalNumVectors() const;
139
140
142 global_size_t getGlobalLength() const;
143
144
146 size_t getGlobalNumVectors() const;
147
148
150 size_t getStride() const;
151
152
154 bool isConstantStride() const;
155
156
158 Teuchos::RCP<const Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
159 getVector( size_t j ) const;
160
161
169 Teuchos::RCP<Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
170 getVectorNonConst( size_t j );
171
172
174 double * getMVPointer_impl() const;
175
181 void get1dCopy( const Teuchos::ArrayView<scalar_t>& A,
182 size_t lda,
183 Teuchos::Ptr<
184 const Tpetra::Map<local_ordinal_t,
185 global_ordinal_t,
186 node_t> > distribution_map,
187 EDistribution distribution) const;
188
189 template<typename KV>
190 bool get1dCopy_kokkos_view(bool bInitialize, KV & A,
191 size_t lda,
192 Teuchos::Ptr<
193 const Tpetra::Map<local_ordinal_t,
194 global_ordinal_t,
195 node_t> > distribution_map,
196 EDistribution distribution) const {
197 Kokkos::View<double**, Kokkos::LayoutLeft, Kokkos::HostSpace> host_new_data;
198 get1dCopy_kokkos_view_host(host_new_data, lda, distribution_map, distribution);
199 bool bAssigned;
200 deep_copy_or_assign_view(bInitialize, A, host_new_data, bAssigned);
201 return false; // currently Epetra and prior get1dCopy_kokkos_view_host call cannot get direct assignment so always return false
202 }
203
204 void get1dCopy_kokkos_view_host(
205 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & new_data,
206 size_t lda,
207 Teuchos::Ptr<
208 const Tpetra::Map<local_ordinal_t,
209 global_ordinal_t,
210 node_t> > distribution_map,
211 EDistribution) const;
212
230 Teuchos::ArrayRCP<scalar_t> get1dViewNonConst( bool local = false );
231
232
243 void put1dData( const Teuchos::ArrayView<const scalar_t>& new_data,
244 size_t lda,
245 Teuchos::Ptr<
246 const Tpetra::Map<local_ordinal_t,
247 global_ordinal_t,
248 node_t> > source_map,
249 EDistribution distribution );
250
251 template<typename KV>
252 void put1dData_kokkos_view(
253 KV & new_data,
254 size_t lda,
255 Teuchos::Ptr<
256 const Tpetra::Map<local_ordinal_t,
257 global_ordinal_t,
258 node_t> > source_map,
259 EDistribution distribution ) {
260 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> host_new_data(
261 Kokkos::ViewAllocateWithoutInitializing("host_new_data"),
262 new_data.extent(0), new_data.extent(1));
263 Kokkos::deep_copy(host_new_data, new_data);
264 put1dData_kokkos_view_host(host_new_data, lda, source_map, distribution);
265 }
266
267 void put1dData_kokkos_view_host(
268 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & new_data,
269 size_t lda,
270 Teuchos::Ptr<
271 const Tpetra::Map<local_ordinal_t,
272 global_ordinal_t,
273 node_t> > source_map,
274 EDistribution distribution );
275
277 std::string description() const;
278
279
281 void describe( Teuchos::FancyOStream& os,
282 const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const;
283
284
285 private:
286
288 Teuchos::RCP<multivec_t> mv_;
289
290 mutable Teuchos::RCP<Epetra_Import> importer_;
291 mutable Teuchos::RCP<Epetra_Export> exporter_;
292
293 mutable Teuchos::RCP<const Epetra_BlockMap> mv_map_;
294
295 }; // end class MultiVecAdapter<NewMultiVec>
296
297} // end namespace Amesos2
298
299
300#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:288
EDistribution
Definition Amesos2_TypeDecl.hpp:123
A templated MultiVector class adapter for Amesos2.
Definition Amesos2_MultiVecAdapter_decl.hpp:176