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
210 void
211 get1dCopy ( const Teuchos::ArrayView<scalar_t>& av,
212 size_t lda,
213 Teuchos::Ptr<
214 const Tpetra::Map<local_ordinal_t,
215 global_ordinal_t,
216 node_t> > distribution_map,
217 EDistribution distribution) const;
218
219 template<typename KV>
220 bool
221 get1dCopy_kokkos_view (bool bInitialize, KV& kokkos_view,
222 size_t lda,
223 Teuchos::Ptr<
224 const Tpetra::Map<local_ordinal_t,
225 global_ordinal_t,
226 node_t> > distribution_map,
227 EDistribution distribution) const {
228 bool bAssigned; // deep_copy_or_assign_view sets true if assigned (no deep copy)
229 deep_copy_or_assign_view(bInitialize, kokkos_view, *mv_, bAssigned);
230 return bAssigned;
231 }
232
246 Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
247
257 void
258 put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
259 size_t lda,
260 Teuchos::Ptr<
261 const Tpetra::Map<local_ordinal_t,
262 global_ordinal_t,
263 node_t> > distribution_map,
264 EDistribution) const;
265
266 template<typename KV>
267 void
268 put1dData_kokkos_view (KV& kokkos_new_data,
269 size_t lda,
270 Teuchos::Ptr<
271 const Tpetra::Map<local_ordinal_t,
272 global_ordinal_t,
273 node_t> > distribution_map,
274 EDistribution) const {
275 deep_copy_or_assign_view(*mv_, kokkos_new_data);
276 }
277
278
280 std::string description () const;
281
283 void
284 describe (Teuchos::FancyOStream& os,
285 const Teuchos::EVerbosityLevel verbLevel =
286 Teuchos::Describable::verbLevel_default) const;
287
288 private:
289
291 Teuchos::RCP<multivec_t> mv_;
292
294 typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
295
297 typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
298
305 mutable Teuchos::RCP<export_type> exporter_;
306
313 mutable Teuchos::RCP<import_type> importer_;
314
315 }; // end class MultiVecAdapter<Tpetra::MultiVector>
316
317} // end namespace Amesos2
318
319
320#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:313
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:305
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:294
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:291
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:297
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