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 
30 namespace 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 
50  typedef Kokkos::View<scalar_t**, Kokkos::LayoutLeft, ExecutionSpace> kokkos_view_t;
51 
52  friend Teuchos::RCP<MultiVecAdapter<multivec_t> > createMultiVecAdapter<> (Teuchos::RCP<multivec_t>);
53  friend Teuchos::RCP<const MultiVecAdapter<multivec_t> > createConstMultiVecAdapter<> (Teuchos::RCP<const multivec_t>);
54 
55  static const char* name;
56 
57 
58  protected:
59  // Do not allow direct construction of MultiVecAdapter's. Only
60  // allow construction through the non-member friend functions.
61 
64 
70  MultiVecAdapter( const Teuchos::RCP<multivec_t>& m );
71 
72 
73  public:
74 
76  { }
77 
79  bool isLocallyIndexed() const
80  {
81  if(getComm()->getSize() == 1){
82  return true;
83  } // There may be other conditions to check
84  return false;
85  }
86 
87  bool isGloballyIndexed() const;
88 
89  Teuchos::RCP<const Tpetra::Map<
90  local_ordinal_t,
91  global_ordinal_t,
92  node_t > >
93  getMap() const
94  {
95  return Teuchos::null; // serial only for Kokkos adapter right now
96  }
97 
99  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
100  {
101  return Tpetra::getDefaultComm(); // serial only for Kokkos adapter right now
102  }
103 
105  size_t getLocalLength() const
106  {
107  return mv_->extent(0);
108  }
109 
110 
112  size_t getLocalNumVectors() const
113  {
114  return mv_->extent(1);
115  }
116 
117 
119  global_size_t getGlobalLength() const
120  {
121  return mv_->extent(0);
122  }
123 
124 
126  global_size_t getGlobalNumVectors() const
127  {
128  return mv_->extent(1);
129  }
130 
131 
133  size_t getStride() const
134  {
135  return mv_->getStride();
136  }
137 
138 
140  bool isConstantStride() const
141  {
142  return mv_->isConstantStride();
143  }
144 
146  Scalar * getMVPointer_impl() const;
147 
148 
149  Teuchos::RCP<multivec_t> clone() const;
150 
179  void
180  get1dCopy ( const Teuchos::ArrayView<scalar_t>& av,
181  size_t lda,
182  Teuchos::Ptr<
183  const Tpetra::Map<local_ordinal_t,
184  global_ordinal_t,
185  node_t> > distribution_map,
186  EDistribution distribution) const;
187 
188  template<typename KV>
189  bool
190  get1dCopy_kokkos_view (
191  bool bInitialize, KV& kokkos_view,
192  [[maybe_unused]] size_t lda,
193  [[maybe_unused]] Teuchos::Ptr<
194  const Tpetra::Map<local_ordinal_t,
195  global_ordinal_t,
196  node_t>
197  > distribution_map,
198  [[maybe_unused]] EDistribution distribution
199  ) const {
200  bool bAssigned; // deep_copy_or_assign_view sets true if assigned (no deep copy)
201  deep_copy_or_assign_view(bInitialize, kokkos_view, *mv_, bAssigned);
202  return bAssigned;
203  }
204 
218  Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
219 
229  void
230  put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
231  size_t lda,
232  Teuchos::Ptr<
233  const Tpetra::Map<local_ordinal_t,
234  global_ordinal_t,
235  node_t> > distribution_map,
236  EDistribution) const;
237 
238  template<typename KV>
239  void
240  put1dData_kokkos_view (
241  KV& kokkos_new_data,
242  [[maybe_unused]] size_t lda,
243  [[maybe_unused]] Teuchos::Ptr<
244  const Tpetra::Map<local_ordinal_t,
245  global_ordinal_t,
246  node_t>
247  > distribution_map,
249  ) const {
250  deep_copy_or_assign_view(*mv_, kokkos_new_data);
251  }
252 
253 
255  std::string description () const;
256 
258  void
259  describe (Teuchos::FancyOStream& os,
260  const Teuchos::EVerbosityLevel verbLevel =
261  Teuchos::Describable::verbLevel_default) const;
262 
263  private:
264 
266  Teuchos::RCP<multivec_t> mv_;
267 
269  typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
270 
272  typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
273 
280  mutable Teuchos::RCP<export_type> exporter_;
281 
288  mutable Teuchos::RCP<import_type> importer_;
289 
290  }; // end class MultiVecAdapter<Tpetra::MultiVector>
291 
292 } // end namespace Amesos2
293 
294 
295 #endif // AMESOS2_KOKKOS_MULTIVEC_ADAPTER_DECL_HPP
Teuchos::RCP< multivec_t > mv_
The multivector which this adapter wraps.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:266
global_size_t getGlobalLength() const
Get the length of vectors in the global space.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:119
global_size_t getGlobalNumVectors() const
Get the number of global vectors.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:126
size_t getLocalNumVectors() const
Get the number of vectors on this node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:112
bool isConstantStride() const
Return true if this MV has constant stride between vectors on this node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:140
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this multi-vector.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:99
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:288
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:269
size_t getStride() const
Return the stride between vectors on this node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:133
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:280
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:272
EDistribution
Definition: Amesos2_TypeDecl.hpp:89
size_t getLocalLength() const
Get the length of vectors local to the calling node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:105
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:142
bool isLocallyIndexed() const
Checks whether this multivector is local to the calling node.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:79