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  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
100 
101 
102 
104 
105 
112  Lapack(Teuchos::RCP<const Matrix> A,
113  Teuchos::RCP<Vector> X,
114  Teuchos::RCP<const Vector> B);
115 
116 
118  ~Lapack( );
119 
121 
122  private:
123 
127  int preOrdering_impl();
128 
129 
134 
135 
142 
143 
154  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
155  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
156 
157 
161  bool matrixShapeOK_impl() const;
162 
163 
172  void setParameters_impl(const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
173 
174 
179  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
180 
181 
190  bool loadA_impl(EPhase current_phase);
191 
192 
193  // We keep some `temporary' storage for when we retrive values
194  // from the input matrix
195  //
196  // NOTE:: It seems that the Teuchos::LAPACK wrappers only really
197  // work for the OrdinalType=int case, so that's what we'll work
198  // with, but ideally we should just be able to give
199  // global_ordinal_type.
200 
202  Teuchos::Array<scalar_type> nzvals_;
204  // Teuchos::Array<global_ordinal_type> rowind_;
205  Teuchos::Array<int> rowind_;
207  // Teuchos::Array<global_size_type> colptr_;
208  Teuchos::Array<int> colptr_;
210  mutable Teuchos::Array<scalar_type> rhsvals_;
211 
213  // Teuchos::SerialDenseMatrix<global_ordinal_type,scalar_type> lu_;
214  Teuchos::SerialDenseMatrix<int,scalar_type> lu_;
215 
217  // Teuchos::SerialDenseSolver<global_ordinal_type,scalar_type> solver_;
218  mutable Teuchos::SerialDenseSolver<int,scalar_type> solver_;
219 
220  bool is_contiguous_;
221 
222  }; // End class Lapack
223 
224 
225  // Specialize the solver_traits struct for Lapack.
226  //
227  // Specializations of Teuchos::LAPACK only exist for real and
228  // complex float and double types.
229  //
230  // TODO: Reinstate the complex support once the bug in
231  // Teuchos::SerialDenseSolver has been fixed
232  template <>
233  struct solver_traits<Lapack> {
234 // #ifdef HAVE_TEUCHOS_COMPLEX
235 // typedef Meta::make_list4<float,
236 // double,
237 // std::complex<float>,
238 // std::complex<double> >supported_scalars;
239 // #else
240  typedef Meta::make_list2<float, double> supported_scalars;
241 // #endif
242 };
243 
244 } // end namespace Amesos2
245 
246 #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:208
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:100
Teuchos::SerialDenseMatrix< int, scalar_type > lu_
L and U storage.
Definition: Amesos2_Lapack_decl.hpp:214
Teuchos::SerialDenseSolver< int, scalar_type > solver_
The serial solver.
Definition: Amesos2_Lapack_decl.hpp:218
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_Lapack_def.hpp:230
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:509
Teuchos::Array< int > rowind_
Stores the column indices of the nonzero entries.
Definition: Amesos2_Lapack_decl.hpp:205
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:219
Teuchos::Array< scalar_type > nzvals_
Stores the values of the nonzero entries.
Definition: Amesos2_Lapack_decl.hpp:202
int preOrdering_impl()
No-op.
Definition: Amesos2_Lapack_def.hpp:92
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Lapack_def.hpp:246
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Lapack solve.
Definition: Amesos2_Lapack_def.hpp:135
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Lapack_def.hpp:270
Provides access to interesting solver traits.
Teuchos::Array< scalar_type > rhsvals_
Store for RHS and Solution values.
Definition: Amesos2_Lapack_decl.hpp:210
int numericFactorization_impl()
Perform numeric factorization using LAPACK.
Definition: Amesos2_Lapack_def.hpp:108