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 
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 (
225  bool bInitialize, KV& kokkos_view,
226  [[maybe_unused]] size_t lda,
227  [[maybe_unused]] Teuchos::Ptr<
228  const Tpetra::Map<local_ordinal_t,
229  global_ordinal_t,
230  node_t>
231  > distribution_map,
232  [[maybe_unused]] EDistribution distribution
233  ) const {
234  bool bAssigned; // deep_copy_or_assign_view sets true if assigned (no deep copy)
235  deep_copy_or_assign_view(bInitialize, kokkos_view, *mv_, bAssigned);
236  return bAssigned;
237  }
238 
252  Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
253 
263  void
264  put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
265  size_t lda,
266  Teuchos::Ptr<
267  const Tpetra::Map<local_ordinal_t,
268  global_ordinal_t,
269  node_t> > distribution_map,
270  EDistribution) const;
271 
272  template<typename KV>
273  void
274  put1dData_kokkos_view (
275  KV& kokkos_new_data,
276  [[maybe_unused]] size_t lda,
277  [[maybe_unused]] Teuchos::Ptr<
278  const Tpetra::Map<local_ordinal_t,
279  global_ordinal_t,
280  node_t>
281  > distribution_map,
283  ) const {
284  deep_copy_or_assign_view(*mv_, kokkos_new_data);
285  }
286 
287 
289  std::string description () const;
290 
292  void
293  describe (Teuchos::FancyOStream& os,
294  const Teuchos::EVerbosityLevel verbLevel =
295  Teuchos::Describable::verbLevel_default) const;
296 
297  private:
298 
300  Teuchos::RCP<multivec_t> mv_;
301 
303  typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
304 
306  typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
307 
314  mutable Teuchos::RCP<export_type> exporter_;
315 
322  mutable Teuchos::RCP<import_type> importer_;
323 
324  }; // end class MultiVecAdapter<Tpetra::MultiVector>
325 
326 } // end namespace Amesos2
327 
328 
329 #endif // AMESOS2_KOKKOS_MULTIVEC_ADAPTER_DECL_HPP
Teuchos::RCP< multivec_t > mv_
The multivector which this adapter wraps.
Definition: Amesos2_KokkosMultiVecAdapter_decl.hpp:300
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:322
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:303
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:314
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:306
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