Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Lapack_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 
44 
54 #ifndef AMESOS2_LAPACK_DECL_HPP
55 #define AMESOS2_LAPACK_DECL_HPP
56 
57 #include <Teuchos_ScalarTraits.hpp>
58 #include <Teuchos_SerialDenseSolver.hpp>
59 #include <Teuchos_SerialDenseMatrix.hpp>
60 
61 #include "Amesos2_SolverTraits.hpp"
62 #include "Amesos2_SolverCore.hpp"
63 
64 
65 namespace Amesos2 {
66 
67 
78  template <class Matrix,
79  class Vector>
80  class Lapack : public SolverCore<Amesos2::Lapack, Matrix, Vector>
81  {
82  friend class SolverCore<Amesos2::Lapack,Matrix,Vector>; // Give our base access
83  // to our private
84  // implementation funcs
85  public:
86 
88  static const char* name; // declaration. Initialization outside.
89 
90  typedef Lapack<Matrix,Vector> type;
91  typedef SolverCore<Amesos2::Lapack,Matrix,Vector> super_type;
92 
93  // Since typedef's are not inheritted, go grab them
94  typedef typename super_type::scalar_type scalar_type;
95  typedef typename super_type::local_ordinal_type local_ordinal_type;
96  typedef typename super_type::global_ordinal_type global_ordinal_type;
97  typedef typename super_type::global_size_type global_size_type;
98 
99  // Version of scalar type that can be used in Kokkos device code
100  typedef typename MatrixTraits<Matrix>::impl_scalar_type impl_scalar_type;
101 
102  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
103 
104  typedef Kokkos::DefaultHostExecutionSpace HostExecSpaceType;
105  typedef Kokkos::View<int*, HostExecSpaceType> host_size_type_array;
106  typedef Kokkos::View<int*, HostExecSpaceType> host_ordinal_type_array;
107  typedef Kokkos::View<impl_scalar_type*, HostExecSpaceType> host_value_type_array;
108 
110 
111 
118  Lapack(Teuchos::RCP<const Matrix> A,
119  Teuchos::RCP<Vector> X,
120  Teuchos::RCP<const Vector> B);
121 
122 
124  ~Lapack( );
125 
127 
128  private:
129 
133  int preOrdering_impl();
134 
135 
140 
141 
148 
149 
160  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
161  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
162 
163 
167  bool matrixShapeOK_impl() const;
168 
169 
178  void setParameters_impl(const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
179 
180 
185  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
186 
187 
196  bool loadA_impl(EPhase current_phase);
197 
198 
199  // We keep some `temporary' storage for when we retrive values
200  // from the input matrix
201  //
202  // NOTE:: It seems that the Teuchos::LAPACK wrappers only really
203  // work for the OrdinalType=int case, so that's what we'll work
204  // with, but ideally we should just be able to give
205  // global_ordinal_type.
206 
208  Teuchos::Array<scalar_type> nzvals_;
210  // Teuchos::Array<global_ordinal_type> rowind_;
211  Teuchos::Array<int> rowind_;
213  // Teuchos::Array<global_size_type> colptr_;
214  Teuchos::Array<int> colptr_;
216  mutable Teuchos::Array<scalar_type> rhsvals_;
217 
218  // The following Kokkos::View's are persisting storage for A's CCS arrays
220  host_value_type_array nzvals_view_;
222  host_ordinal_type_array rowind_view_;
224  host_size_type_array colptr_view_;
225 
227  // Teuchos::SerialDenseMatrix<global_ordinal_type,scalar_type> lu_;
228  Teuchos::SerialDenseMatrix<int,scalar_type> lu_;
229 
231  // Teuchos::SerialDenseSolver<global_ordinal_type,scalar_type> solver_;
232  mutable Teuchos::SerialDenseSolver<int,scalar_type> solver_;
233 
234  bool is_contiguous_;
235 
236  }; // End class Lapack
237 
238 
239  // Specialize the solver_traits struct for Lapack.
240  //
241  // Specializations of Teuchos::LAPACK only exist for real and
242  // complex float and double types.
243  //
244  // TODO: Reinstate the complex support once the bug in
245  // Teuchos::SerialDenseSolver has been fixed
246  template <>
247  struct solver_traits<Lapack> {
248 // #ifdef HAVE_TEUCHOS_COMPLEX
249 // typedef Meta::make_list4<float,
250 // double,
251 // std::complex<float>,
252 // std::complex<double> >supported_scalars;
253 // #else
254  typedef Meta::make_list2<float, double> supported_scalars;
255 // #endif
256 };
257 
258 } // end namespace Amesos2
259 
260 #endif // AMESOS2_NEWSOLVER_DECL_HPP
Teuchos::Array< int > colptr_
Stores the location in Ai_ and Aval_ that starts col j.
Definition: Amesos2_Lapack_decl.hpp:214
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
Amesos2 interface to the LAPACK.
Definition: Amesos2_Lapack_decl.hpp:80
int symbolicFactorization_impl()
No-op.
Definition: Amesos2_Lapack_def.hpp:97
host_size_type_array colptr_view_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Lapack_decl.hpp:224
Teuchos::SerialDenseMatrix< int, scalar_type > lu_
L and U storage.
Definition: Amesos2_Lapack_decl.hpp:228
Teuchos::SerialDenseSolver< int, scalar_type > solver_
The serial solver.
Definition: Amesos2_Lapack_decl.hpp:232
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_Lapack_def.hpp:217
Teuchos::Array< int > rowind_
Stores the column indices of the nonzero entries.
Definition: Amesos2_Lapack_decl.hpp:211
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Lapack_def.hpp:206
host_value_type_array nzvals_view_
Stores the values of the nonzero entries for Umfpack.
Definition: Amesos2_Lapack_decl.hpp:220
Teuchos::Array< scalar_type > nzvals_
Stores the values of the nonzero entries.
Definition: Amesos2_Lapack_decl.hpp:208
std::string name() const override
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:759
int preOrdering_impl()
No-op.
Definition: Amesos2_Lapack_def.hpp:89
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Lapack_def.hpp:233
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Lapack solve.
Definition: Amesos2_Lapack_def.hpp:132
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Lapack_def.hpp:257
Provides access to interesting solver traits.
host_ordinal_type_array rowind_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Lapack_decl.hpp:222
Teuchos::Array< scalar_type > rhsvals_
Store for RHS and Solution values.
Definition: Amesos2_Lapack_decl.hpp:216
int numericFactorization_impl()
Perform numeric factorization using LAPACK.
Definition: Amesos2_Lapack_def.hpp:105