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 
64 namespace 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 
109  ~MultiVecAdapter()
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  void
221  get1dCopy_kokkos_view (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  deep_copy_or_assign_view(kokkos_view, *mv_);
229  }
230 
244  Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
245 
255  void
256  put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
257  size_t lda,
258  Teuchos::Ptr<
259  const Tpetra::Map<local_ordinal_t,
260  global_ordinal_t,
261  node_t> > distribution_map,
262  EDistribution) const;
263 
264  template<typename KV>
265  void
266  put1dData_kokkos_view (KV& kokkos_new_data,
267  size_t lda,
268  Teuchos::Ptr<
269  const Tpetra::Map<local_ordinal_t,
270  global_ordinal_t,
271  node_t> > distribution_map,
272  EDistribution) const {
273  deep_copy_or_assign_view(*mv_, kokkos_new_data);
274  }
275 
276 
278  std::string description () const;
279 
281  void
282  describe (Teuchos::FancyOStream& os,
283  const Teuchos::EVerbosityLevel verbLevel =
284  Teuchos::Describable::verbLevel_default) const;
285 
286  private:
287 
289  Teuchos::RCP<multivec_t> mv_;
290 
292  typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
293 
295  typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
296 
303  mutable Teuchos::RCP<export_type> exporter_;
304 
311  mutable Teuchos::RCP<import_type> importer_;
312 
313  }; // end class MultiVecAdapter<Tpetra::MultiVector>
314 
315 } // end namespace Amesos2
316 
317 
318 #endif // AMESOS2_KOKKOS_MULTIVEC_ADAPTER_DECL_HPP
Teuchos::RCP< multivec_t > mv_
The multivector which this adapter wraps.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:289
global_size_t getGlobalLength() const
Get the length of vectors in the global space.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:153
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:160
size_t getLocalNumVectors() const
Get the number of vectors on this node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:146
bool isConstantStride() const
Return true if this MV has constant stride between vectors on this node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:174
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this multi-vector.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:133
Teuchos::RCP< import_type > importer_
Used for data redistribution from the solver&#39;s output MultiVector to the user&#39;s output MultiVector...
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:311
Copy or assign views based on memory spaces.
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:292
size_t getStride() const
Return the stride between vectors on this node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:167
Teuchos::RCP< export_type > exporter_
Used for data redistribution from the user&#39;s input MultiVector to the solver&#39;s input MultiVector...
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:303
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:295
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
size_t getLocalLength() const
Get the length of vectors local to the calling node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:139
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:113