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 
208  void setParameters_impl(const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
209 
210 
215  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
216 
217 
226  bool loadA_impl(EPhase current_phase);
227 
228 
230 
251  void check_pardiso_mkl_error(EPhase phase, int_t error) const;
252 
262  void set_pardiso_mkl_matrix_type(int_t mtype = 0);
263 
264 
265  /* Declare private variables necessary for interaction with the
266  * PardisoMKL TPL.
267  *
268  * For example, the following Arrays are persisting storage arrays
269  * for A, X, and B that can be used with solvers expecting a
270  * compressed-row representation of the matrix A.
271  */
272 
274  Teuchos::Array<solver_scalar_type> nzvals_;
276  Teuchos::Array<int_t> colind_;
278  Teuchos::Array<int_t> rowptr_;
280  mutable Teuchos::Array<solver_scalar_type> xvals_;
282  mutable Teuchos::Array<solver_scalar_type> bvals_;
283 
285  mutable void* pt_[64];
287  int_t mtype_;
289  int_t n_;
291  Teuchos::Array<int_t> perm_;
293  mutable int_t nrhs_;
294 
297  int_t iparm_[64];
298 
300  static const int_t msglvl_;
301 
302  // We will deal with 1 factor at a time
303  static const int_t maxfct_;
304  static const int_t mnum_;
305 
306 
307  static const bool complex_
308  = Meta::or_<Meta::is_same<solver_scalar_type, PMKL::_MKL_Complex8>::value,
309  Meta::is_same<solver_scalar_type, PMKL::_DOUBLE_COMPLEX_t>::value>::value;
310 
311  bool is_contiguous_;
312 
313 }; // End class PardisoMKL
314 
315 
316 // Specialize the solver_traits struct for PardisoMKL.
317 template <>
318 struct solver_traits<PardisoMKL> {
319 #ifdef HAVE_TEUCHOS_COMPLEX
320  typedef Meta::make_list6<float,
321  double,
322  std::complex<float>,
323  std::complex<double>,
324  PMKL::_MKL_Complex8,
325  PMKL::_DOUBLE_COMPLEX_t> supported_scalars;
326 #else
327 typedef Meta::make_list2<float,
328  double> supported_scalars;
329 #endif
330 };
331 
332 } // end namespace Amesos
333 
334 #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:274
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:289
int_t nrhs_
number of righthand-side vectors
Definition: Amesos2_PardisoMKL_decl.hpp:293
void set_pardiso_mkl_matrix_type(int_t mtype=0)
Definition: Amesos2_PardisoMKL_def.hpp:609
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:300
Teuchos::Array< solver_scalar_type > bvals_
Persisting, contiguous, 1D store for B.
Definition: Amesos2_PardisoMKL_decl.hpp:282
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:509
void * pt_[64]
PardisoMKL internal data address pointer.
Definition: Amesos2_PardisoMKL_decl.hpp:285
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71
Teuchos::Array< int_t > perm_
Permutation vector.
Definition: Amesos2_PardisoMKL_decl.hpp:291
Amesos2 interface to the PardisoMKL package.
Definition: Amesos2_PardisoMKL_decl.hpp:83
int numericFactorization_impl()
PardisoMKL specific numeric factorization.
Definition: Amesos2_PardisoMKL_def.hpp:179
Teuchos::Array< int_t > rowptr_
Stores the row indices of the nonzero entries.
Definition: Amesos2_PardisoMKL_decl.hpp:278
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using PardisoMKL.
Definition: Amesos2_PardisoMKL_def.hpp:147
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_PardisoMKL_def.hpp:511
Teuchos::Array< solver_scalar_type > xvals_
Persisting, contiguous, 1D store for X.
Definition: Amesos2_PardisoMKL_decl.hpp:280
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_PardisoMKL_def.hpp:306
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:206
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 &lt; 0 .
Definition: Amesos2_PardisoMKL_def.hpp:556
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:276
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_PardisoMKL_def.hpp:409
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_PardisoMKL_def.hpp:297
int_t mtype_
The matrix type. We deal only with unsymmetrix matrices.
Definition: Amesos2_PardisoMKL_decl.hpp:287
int_t iparm_[64]
Definition: Amesos2_PardisoMKL_decl.hpp:297
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_PardisoMKL_def.hpp:136