Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_KokkosMultiVecAdapter_decl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Amesos2: Templated Direct Sparse Solver Package
4//
5// Copyright 2011 NTESS and the Amesos2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
19#ifndef AMESOS2_KOKKOS_MULTIVEC_ADAPTER_DECL_HPP
20#define AMESOS2_KOKKOS_MULTIVEC_ADAPTER_DECL_HPP
21
22#include <Teuchos_RCP.hpp>
23#include <Teuchos_Array.hpp>
24#include <Teuchos_as.hpp>
25#include <Tpetra_Core.hpp>
26
27#include "Amesos2_MultiVecAdapter_decl.hpp"
29
30namespace Amesos2 {
31
37 template< typename Scalar,
38 typename ExecutionSpace >
39 class MultiVecAdapter<Kokkos::View<Scalar**, Kokkos::LayoutLeft, ExecutionSpace> >
40 {
41 public:
42 // public type definitions
43 typedef Tpetra::Map<>::node_type node_t;
44 typedef Kokkos::View<Scalar**,Kokkos::LayoutLeft, ExecutionSpace> multivec_t;
45 typedef int local_ordinal_t;
46 typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
47 typedef size_t global_size_t;
48 typedef Scalar scalar_t;
49 typedef scalar_t host_value_t;
50
51 typedef Kokkos::View<scalar_t**, Kokkos::LayoutLeft, ExecutionSpace> kokkos_view_t;
52
53 friend Teuchos::RCP<MultiVecAdapter<multivec_t> > createMultiVecAdapter<> (Teuchos::RCP<multivec_t>);
54 friend Teuchos::RCP<const MultiVecAdapter<multivec_t> > createConstMultiVecAdapter<> (Teuchos::RCP<const multivec_t>);
55
56 static const char* name;
57
58
59 protected:
60 // Do not allow direct construction of MultiVecAdapter's. Only
61 // allow construction through the non-member friend functions.
62
65
71 MultiVecAdapter( const Teuchos::RCP<multivec_t>& m );
72
73
74 public:
75
77 { }
78
80 bool isLocallyIndexed() const
81 {
82 if(getComm()->getSize() == 1){
83 return true;
84 } // There may be other conditions to check
85 return false;
86 }
87
88 bool isGloballyIndexed() const;
89
90 Teuchos::RCP<const Tpetra::Map<
91 local_ordinal_t,
92 global_ordinal_t,
93 node_t > >
94 getMap() const
95 {
96 return Teuchos::null; // serial only for Kokkos adapter right now
97 }
98
100 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
101 {
102 return Teuchos::rcp(new Teuchos::SerialComm<int>());
103 }
104
106 size_t getLocalLength() const
107 {
108 return mv_->extent(0);
109 }
110
111
113 size_t getLocalNumVectors() const
114 {
115 return mv_->extent(1);
116 }
117
118
120 global_size_t getGlobalLength() const
121 {
122 return mv_->extent(0);
123 }
124
125
127 global_size_t getGlobalNumVectors() const
128 {
129 return mv_->extent(1);
130 }
131
132
134 size_t getStride() const
135 {
136 return mv_->getStride();
137 }
138
139
141 bool isConstantStride() const
142 {
143 return mv_->isConstantStride();
144 }
145
147 Scalar * getMVPointer_impl() const;
148
149
150 Teuchos::RCP<multivec_t> clone() const;
151
180 void
181 get1dCopy ( const Teuchos::ArrayView<scalar_t>& av,
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
191 get1dCopy_kokkos_view (
192 bool bInitialize, KV& kokkos_view,
193 [[maybe_unused]] size_t lda,
194 [[maybe_unused]] Teuchos::Ptr<
195 const Tpetra::Map<local_ordinal_t,
196 global_ordinal_t,
197 node_t>
198 > distribution_map,
199 [[maybe_unused]] EDistribution distribution
200 ) const {
201 bool bAssigned; // deep_copy_or_assign_view sets true if assigned (no deep copy)
202 deep_copy_or_assign_view(bInitialize, kokkos_view, *mv_, bAssigned);
203 return bAssigned;
204 }
205
219 Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
220
230 void
231 put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
232 size_t lda,
233 Teuchos::Ptr<
234 const Tpetra::Map<local_ordinal_t,
235 global_ordinal_t,
236 node_t> > distribution_map,
237 EDistribution) const;
238
239 template<typename KV>
240 void
241 put1dData_kokkos_view (
242 KV& kokkos_new_data,
243 [[maybe_unused]] size_t lda,
244 [[maybe_unused]] Teuchos::Ptr<
245 const Tpetra::Map<local_ordinal_t,
246 global_ordinal_t,
247 node_t>
248 > distribution_map,
249 EDistribution
250 ) const {
251 deep_copy_or_assign_view(*mv_, kokkos_new_data);
252 }
253
254 template<typename KV, typename host_ordinal_type_array>
255 int
256 gather (KV& kokkos_new_view,
257 host_ordinal_type_array &perm_g2l,
258 host_ordinal_type_array &recvCountRows,
259 host_ordinal_type_array &recvDisplRows,
260 EDistribution distribution ) const;
261
262 template<typename KV, typename host_ordinal_type_array>
263 int
264 scatter (KV& kokkos_old_view,
265 host_ordinal_type_array &perm_g2l,
266 host_ordinal_type_array &recvCountRows,
267 host_ordinal_type_array &recvDisplRows,
268 EDistribution distribution ) const;
269
271 std::string description () const;
272
274 void
275 describe (Teuchos::FancyOStream& os,
276 const Teuchos::EVerbosityLevel verbLevel =
277 Teuchos::Describable::verbLevel_default) const;
278
279 private:
280
282 Teuchos::RCP<multivec_t> mv_;
283
285 typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
286
288 typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
289
296 mutable Teuchos::RCP<export_type> exporter_;
297
304 mutable Teuchos::RCP<import_type> importer_;
305
306 }; // end class MultiVecAdapter<Tpetra::MultiVector>
307
308} // end namespace Amesos2
309
310
311#endif // AMESOS2_KOKKOS_MULTIVEC_ADAPTER_DECL_HPP
Copy or assign views based on memory spaces.
EDistribution
Definition Amesos2_TypeDecl.hpp:89
bool isConstantStride() const
Return true if this MV has constant stride between vectors on this node.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:141
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:80
Teuchos::RCP< import_type > importer_
Used for data redistribution from the solver's output MultiVector to the user's output MultiVector.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:304
Teuchos::RCP< export_type > exporter_
Used for data redistribution from the user's input MultiVector to the solver's input MultiVector.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:296
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:127
Tpetra::Export< local_ordinal_t, global_ordinal_t, node_t > export_type
The Tpetra::Export specialization used by this class.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:285
size_t getLocalLength() const
Get the length of vectors local to the calling node.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:106
MultiVecAdapter(const MultiVecAdapter< multivec_t > &adapter)
Copy constructor.
Teuchos::RCP< multivec_t > mv_
The multivector which this adapter wraps.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:282
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this multi-vector.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:100
size_t getStride() const
Return the stride between vectors on this node.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:134
Tpetra::Import< local_ordinal_t, global_ordinal_t, node_t > import_type
The Tpetra::Import specialization used by this class.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:288
size_t getLocalNumVectors() const
Get the number of vectors on this node.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:113
global_size_t getGlobalLength() const
Get the length of vectors in the global space.
Definition Amesos2_KokkosMultiVecAdapter_decl.hpp:120
A templated MultiVector class adapter for Amesos2.
Definition Amesos2_MultiVecAdapter_decl.hpp:142