Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_KokkosMultiVecAdapter_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_KOKKOS_MULTIVEC_ADAPTER_DECL_HPP
54#define AMESOS2_KOKKOS_MULTIVEC_ADAPTER_DECL_HPP
55
56#include <Teuchos_RCP.hpp>
57#include <Teuchos_Array.hpp>
58#include <Teuchos_as.hpp>
59#include <Tpetra_Core.hpp>
60
61#include "Amesos2_MultiVecAdapter_decl.hpp"
63
64namespace Amesos2 {
65
71 template< typename Scalar,
72 typename ExecutionSpace >
73 class MultiVecAdapter<Kokkos::View<Scalar**, Kokkos::LayoutLeft, ExecutionSpace> >
74 {
75 public:
76 // public type definitions
77 typedef Tpetra::Map<>::node_type node_t;
78 typedef Kokkos::View<Scalar**,Kokkos::LayoutLeft, ExecutionSpace> multivec_t;
79 typedef int local_ordinal_t;
80 typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
81 typedef size_t global_size_t;
82 typedef Scalar scalar_t;
83
84 typedef Kokkos::View<scalar_t**, Kokkos::LayoutLeft, ExecutionSpace> kokkos_view_t;
85
86 friend Teuchos::RCP<MultiVecAdapter<multivec_t> > createMultiVecAdapter<> (Teuchos::RCP<multivec_t>);
87 friend Teuchos::RCP<const MultiVecAdapter<multivec_t> > createConstMultiVecAdapter<> (Teuchos::RCP<const multivec_t>);
88
89 static const char* name;
90
91
92 protected:
93 // Do not allow direct construction of MultiVecAdapter's. Only
94 // allow construction through the non-member friend functions.
95
98
104 MultiVecAdapter( const Teuchos::RCP<multivec_t>& m );
105
106
107 public:
108
110 { }
111
113 bool isLocallyIndexed() const
114 {
115 if(getComm()->getSize() == 1){
116 return true;
117 } // There may be other conditions to check
118 return false;
119 }
120
121 bool isGloballyIndexed() const;
122
123 Teuchos::RCP<const Tpetra::Map<
124 local_ordinal_t,
125 global_ordinal_t,
126 node_t > >
127 getMap() const
128 {
129 return Teuchos::null; // serial only for Kokkos adapter right now
130 }
131
133 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
134 {
135 return Tpetra::getDefaultComm(); // serial only for Kokkos adapter right now
136 }
137
139 size_t getLocalLength() const
140 {
141 return mv_->extent(0);
142 }
143
144
146 size_t getLocalNumVectors() const
147 {
148 return mv_->extent(1);
149 }
150
151
153 global_size_t getGlobalLength() const
154 {
155 return mv_->extent(0);
156 }
157
158
160 global_size_t getGlobalNumVectors() const
161 {
162 return mv_->extent(1);
163 }
164
165
167 size_t getStride() const
168 {
169 return mv_->getStride();
170 }
171
172
174 bool isConstantStride() const
175 {
176 return mv_->isConstantStride();
177 }
178
180 Scalar * getMVPointer_impl() const;
181
182
183 Teuchos::RCP<multivec_t> clone() const;
184
213 void
214 get1dCopy ( const Teuchos::ArrayView<scalar_t>& av,
215 size_t lda,
216 Teuchos::Ptr<
217 const Tpetra::Map<local_ordinal_t,
218 global_ordinal_t,
219 node_t> > distribution_map,
220 EDistribution distribution) const;
221
222 template<typename KV>
223 bool
224 get1dCopy_kokkos_view (bool bInitialize, KV& kokkos_view,
225 size_t lda,
226 Teuchos::Ptr<
227 const Tpetra::Map<local_ordinal_t,
228 global_ordinal_t,
229 node_t> > distribution_map,
230 EDistribution distribution) const {
231 bool bAssigned; // deep_copy_or_assign_view sets true if assigned (no deep copy)
232 deep_copy_or_assign_view(bInitialize, kokkos_view, *mv_, bAssigned);
233 return bAssigned;
234 }
235
249 Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
250
260 void
261 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> > distribution_map,
267 EDistribution) const;
268
269 template<typename KV>
270 void
271 put1dData_kokkos_view (KV& kokkos_new_data,
272 size_t lda,
273 Teuchos::Ptr<
274 const Tpetra::Map<local_ordinal_t,
275 global_ordinal_t,
276 node_t> > distribution_map,
277 EDistribution) const {
278 deep_copy_or_assign_view(*mv_, kokkos_new_data);
279 }
280
281
283 std::string description () const;
284
286 void
287 describe (Teuchos::FancyOStream& os,
288 const Teuchos::EVerbosityLevel verbLevel =
289 Teuchos::Describable::verbLevel_default) const;
290
291 private:
292
294 Teuchos::RCP<multivec_t> mv_;
295
297 typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
298
300 typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
301
308 mutable Teuchos::RCP<export_type> exporter_;
309
316 mutable Teuchos::RCP<import_type> importer_;
317
318 }; // end class MultiVecAdapter<Tpetra::MultiVector>
319
320} // end namespace Amesos2
321
322
323#endif // AMESOS2_KOKKOS_MULTIVEC_ADAPTER_DECL_HPP
Copy or assign views based on memory spaces.
bool isConstantStride() const
Return true if this MV has constant stride between vectors on this node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:174
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:113
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:316
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:308
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:160
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:297
size_t getLocalLength() const
Get the length of vectors local to the calling node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:139
MultiVecAdapter(const MultiVecAdapter< multivec_t > &adapter)
Copy constructor.
Teuchos::RCP< multivec_t > mv_
The multivector which this adapter wraps.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:294
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this multi-vector.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:133
size_t getStride() const
Return the stride between vectors on this node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:167
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:300
size_t getLocalNumVectors() const
Get the number of vectors on this node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:146
global_size_t getGlobalLength() const
Get the length of vectors in the global space.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:153
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176