Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_PardisoMKL_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 
56 #ifndef AMESOS2_PARDISOMKL_DECL_HPP
57 #define AMESOS2_PARDISOMKL_DECL_HPP
58 
59 #include <map>
60 
61 #include <Teuchos_StandardParameterEntryValidators.hpp>
62 
63 #include "Amesos2_SolverTraits.hpp"
64 #include "Amesos2_SolverCore.hpp"
65 #include "Amesos2_PardisoMKL_FunctionMap.hpp"
66 
67 
68 namespace Amesos2 {
69 
70 
81  template <class Matrix,
82  class Vector>
83  class PardisoMKL : public SolverCore<Amesos2::PardisoMKL, Matrix, Vector>
84  {
85  friend class SolverCore<Amesos2::PardisoMKL,Matrix,Vector>; // Give our base access
86  // to our private
87  // implementation funcs
88  public:
89 
91  static const char* name; // declaration. Initialization outside.
92 
93  typedef PardisoMKL<Matrix,Vector> type;
94  typedef SolverCore<Amesos2::PardisoMKL,Matrix,Vector> super_type;
95 
96  // Since typedef's are not inheritted, go grab them
97  typedef typename super_type::scalar_type scalar_type;
98  typedef typename super_type::local_ordinal_type local_ordinal_type;
99  typedef typename super_type::global_ordinal_type global_ordinal_type;
100  typedef typename super_type::global_size_type global_size_type;
101 
102  typedef TypeMap<Amesos2::PardisoMKL,scalar_type> type_map;
103 
104  typedef typename type_map::type solver_scalar_type;
105  typedef typename type_map::magnitude_type solver_magnitude_type;
106 
107  // This may be PMKL::_INTEGER_t or long long int depending on the
108  // mapping and input ordinal
109  typedef typename TypeMap<Amesos2::PardisoMKL,local_ordinal_type>::type int_t;
110 
111  /* For PardisoMKL we dispatch based on the integer type instead of
112  * the scalar type:
113  * - _INTEGER_t => use the pardiso(...) method
114  * - long long int => use the pardiso_64(...) method
115  */
116  typedef FunctionMap<Amesos2::PardisoMKL,int_t> function_map;
117 
118 
120 
121 
128  PardisoMKL(Teuchos::RCP<const Matrix> A,
129  Teuchos::RCP<Vector> X,
130  Teuchos::RCP<const Vector> B);
131 
132 
134  ~PardisoMKL( );
135 
137 
138  private:
139 
147  int preOrdering_impl();
148 
149 
158 
159 
166 
167 
178  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
179  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
180 
181 
187  bool matrixShapeOK_impl() const;
188 
189 
207  void setParameters_impl(const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
208 
209 
214  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
215 
216 
225  bool loadA_impl(EPhase current_phase);
226 
227 
229 
250  void check_pardiso_mkl_error(EPhase phase, int_t error) const;
251 
261  void set_pardiso_mkl_matrix_type(int_t mtype = 0);
262 
263 
264  /* Declare private variables necessary for interaction with the
265  * PardisoMKL TPL.
266  *
267  * For example, the following Arrays are persisting storage arrays
268  * for A, X, and B that can be used with solvers expecting a
269  * compressed-row representation of the matrix A.
270  */
271 
273  Teuchos::Array<solver_scalar_type> nzvals_;
275  Teuchos::Array<int_t> colind_;
277  Teuchos::Array<int_t> rowptr_;
279  mutable Teuchos::Array<solver_scalar_type> xvals_;
281  mutable Teuchos::Array<solver_scalar_type> bvals_;
282 
284  mutable void* pt_[64];
286  int_t mtype_;
288  int_t n_;
290  Teuchos::Array<int_t> perm_;
292  mutable int_t nrhs_;
293 
296  int_t iparm_[64];
297 
299  static const int_t msglvl_;
300 
301  // We will deal with 1 factor at a time
302  static const int_t maxfct_;
303  static const int_t mnum_;
304 
305 
306  static const bool complex_
307  = Meta::or_<Meta::is_same<solver_scalar_type, PMKL::_MKL_Complex8>::value,
308  Meta::is_same<solver_scalar_type, PMKL::_DOUBLE_COMPLEX_t>::value>::value;
309 
310  mutable std::map<int,Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> > > validators;
311 
312 }; // End class PardisoMKL
313 
314 
315 // Specialize the solver_traits struct for PardisoMKL.
316 template <>
317 struct solver_traits<PardisoMKL> {
318 #ifdef HAVE_TEUCHOS_COMPLEX
319  typedef Meta::make_list6<float,
320  double,
321  std::complex<float>,
322  std::complex<double>,
323  PMKL::_MKL_Complex8,
324  PMKL::_DOUBLE_COMPLEX_t> supported_scalars;
325 #else
326 typedef Meta::make_list2<float,
327  double> supported_scalars;
328 #endif
329 };
330 
331 } // end namespace Amesos
332 
333 #endif // AMESOS2_PARDISOMKL_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
Teuchos::Array< solver_scalar_type > nzvals_
Stores the values of the nonzero entries for PardisoMKL.
Definition: Amesos2_PardisoMKL_decl.hpp:273
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
int_t n_
Number of equations in the sparse linear system.
Definition: Amesos2_PardisoMKL_decl.hpp:288
int_t nrhs_
number of righthand-side vectors
Definition: Amesos2_PardisoMKL_decl.hpp:292
void set_pardiso_mkl_matrix_type(int_t mtype=0)
Definition: Amesos2_PardisoMKL_def.hpp:519
static const int_t msglvl_
The messaging level. Set to 1 if you wish for Pardiso MKL to print statistical info.
Definition: Amesos2_PardisoMKL_decl.hpp:299
Teuchos::Array< solver_scalar_type > bvals_
Persisting, contiguous, 1D store for B.
Definition: Amesos2_PardisoMKL_decl.hpp:281
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:502
void * pt_[64]
PardisoMKL internal data address pointer.
Definition: Amesos2_PardisoMKL_decl.hpp:284
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:70
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
Teuchos::Array< int_t > perm_
Permutation vector.
Definition: Amesos2_PardisoMKL_decl.hpp:290
Amesos2 interface to the PardisoMKL package.
Definition: Amesos2_PardisoMKL_decl.hpp:83
int numericFactorization_impl()
PardisoMKL specific numeric factorization.
Definition: Amesos2_PardisoMKL_def.hpp:178
Teuchos::Array< int_t > rowptr_
Stores the row indices of the nonzero entries.
Definition: Amesos2_PardisoMKL_decl.hpp:277
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using PardisoMKL.
Definition: Amesos2_PardisoMKL_def.hpp:146
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_PardisoMKL_def.hpp:431
Teuchos::Array< solver_scalar_type > xvals_
Persisting, contiguous, 1D store for X.
Definition: Amesos2_PardisoMKL_decl.hpp:279
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_PardisoMKL_def.hpp:286
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
PardisoMKL specific solve.
Definition: Amesos2_PardisoMKL_def.hpp:205
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:76
void check_pardiso_mkl_error(EPhase phase, int_t error) const
Throws an appropriate runtime error in the event that error < 0 .
Definition: Amesos2_PardisoMKL_def.hpp:466
Provides access to interesting solver traits.
Teuchos::Array< int_t > colind_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_PardisoMKL_decl.hpp:275
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_PardisoMKL_def.hpp:325
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_PardisoMKL_def.hpp:277
int_t mtype_
The matrix type. We deal only with unsymmetrix matrices.
Definition: Amesos2_PardisoMKL_decl.hpp:286
int_t iparm_[64]
Definition: Amesos2_PardisoMKL_decl.hpp:296
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_PardisoMKL_def.hpp:135