Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Superlu_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_SUPERLU_DECL_HPP
54 #define AMESOS2_SUPERLU_DECL_HPP
55 
56 #include "Amesos2_SolverTraits.hpp"
57 #include "Amesos2_SolverCore.hpp"
59 
60 
61 namespace Amesos2 {
62 
63 
71 template <class Matrix,
72  class Vector>
73 class Superlu : public SolverCore<Amesos2::Superlu, Matrix, Vector>
74 {
75  friend class SolverCore<Amesos2::Superlu,Matrix,Vector>; // Give our base access
76  // to our private
77  // implementation funcs
78 public:
79 
81  static const char* name; // declaration. Initialization outside.
82 
83  typedef Superlu<Matrix,Vector> type;
84  typedef SolverCore<Amesos2::Superlu,Matrix,Vector> super_type;
85 
86  // Since typedef's are not inheritted, go grab them
87  typedef typename super_type::scalar_type scalar_type;
88  typedef typename super_type::local_ordinal_type local_ordinal_type;
89  typedef typename super_type::global_ordinal_type global_ordinal_type;
90  typedef typename super_type::global_size_type global_size_type;
91 
92  typedef TypeMap<Amesos2::Superlu,scalar_type> type_map;
93 
94  /*
95  * The SuperLU interface will need two other typedef's, which are:
96  * - the superlu type that corresponds to scalar_type and
97  * - the corresponding type to use for magnitude
98  */
99  typedef typename type_map::type slu_type;
100  typedef typename type_map::magnitude_type magnitude_type;
101 
102  typedef FunctionMap<Amesos2::Superlu,slu_type> function_map;
103 
104 #ifdef HAVE_AMESOS2_SUPERLU5_API
105  typedef typename function_map::GlobalLU_type GlobalLU_t;
106 #endif
107 
109 
110 
117  Superlu(Teuchos::RCP<const Matrix> A,
118  Teuchos::RCP<Vector> X,
119  Teuchos::RCP<const Vector> B);
120 
121 
123  ~Superlu( );
124 
126 
128  std::string description() const;
129 
130 private:
131 
137  int preOrdering_impl();
138 
139 
148 
149 
156 
157 
169  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
170  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
171 
172 
176  bool matrixShapeOK_impl() const;
177 
178 
212  void setParameters_impl(
213  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
214 
215 
222  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
223 
224 
233  bool loadA_impl(EPhase current_phase);
234 
235 
236  // struct holds all data necessary to make a superlu factorization or solve call
237  mutable struct SLUData {
238  SLU::SuperMatrix A, B, X, L, U; // matrix A in NCformat
239  SLU::SuperMatrix AC; // permuted matrix A in NCPformat
240 
241  SLU::superlu_options_t options;
242  SLU::mem_usage_t mem_usage;
243 #ifdef HAVE_AMESOS2_SUPERLU5_API
244  GlobalLU_t lu; // Use for gssvx and gsisx in SuperLU 5.0
245 #endif
246  SLU::SuperLUStat_t stat;
247 
248  Teuchos::Array<magnitude_type> berr;
249  Teuchos::Array<magnitude_type> ferr;
250  Teuchos::Array<int> perm_r;
251  Teuchos::Array<int> perm_c;
252  Teuchos::Array<int> etree;
253  Teuchos::Array<magnitude_type> R;
254  Teuchos::Array<magnitude_type> C;
255 
256  char equed;
257  bool rowequ, colequ; // flags what type of equilibration
258  // has been performed
259 
260  int relax;
261  int panel_size;
262  } data_;
263 
264  // The following Arrays are persisting storage arrays for A, X, and B
266  Teuchos::Array<slu_type> nzvals_;
268  Teuchos::Array<int> rowind_;
270  Teuchos::Array<int> colptr_;
271 
273  Teuchos::Array<slu_type> xvals_; int ldx_;
275  Teuchos::Array<slu_type> bvals_; int ldb_;
276 
277  /* Note: In the above, must use "Amesos2::Superlu" rather than
278  * "Superlu" because otherwise the compiler references the
279  * specialized type of the class, and not the templated type that is
280  * required for Amesos2::TypeMap
281  */
282 
283  /* SuperLU can accept input in either compressed-row or
284  * compressed-column storage. We will store and pass matrices in
285  * *compressed-column* format.
286  */
287 
288  /*
289  * Internal flag that is used for the numericFactorization_impl
290  * routine. If true, then the superlu gstrf routine should have
291  * SamePattern_SameRowPerm in its options. Otherwise, it should
292  * factor from scratch.
293  *
294  * This is somewhat of a kludge to get around the fact that the
295  * superlu routines all expect something different from the options
296  * struct. The big issue is that we don't want gstrf doing the
297  * symbolic factorization if it doesn't need to. On the other hand,
298  * we can't leave options.Fact set to SamePattern_SameRowPerm
299  * because the solver driver needs it to be set at FACTORED. But
300  * having it set at FACTORED upon re-entrance into
301  * numericFactorization prompts gstrf to redo the symbolic
302  * factorization.
303  */
304  bool same_symbolic_;
305  bool ILU_Flag_;
306 
307  bool is_contiguous_;
308 }; // End class Superlu
309 
310 
311 // Specialize solver_traits struct for SuperLU
312 template <>
313 struct solver_traits<Superlu> {
314 #ifdef HAVE_TEUCHOS_COMPLEX
315  typedef Meta::make_list6<float,
316  double,
317  std::complex<float>,
318  std::complex<double>,
319  SLU::C::complex,
320  SLU::Z::doublecomplex> supported_scalars;
321 #else
322  typedef Meta::make_list2<float, double> supported_scalars;
323 #endif
324 };
325 
326 } // end namespace Amesos2
327 
328 #endif // AMESOS2_SUPERLU_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
Teuchos::Array< slu_type > nzvals_
Stores the values of the nonzero entries for SuperLU.
Definition: Amesos2_Superlu_decl.hpp:266
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Superlu_def.hpp:731
Teuchos::Array< int > colptr_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Superlu_decl.hpp:270
int numericFactorization_impl()
Superlu specific numeric factorization.
Definition: Amesos2_Superlu_def.hpp:233
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
Teuchos::Array< int > rowind_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Superlu_decl.hpp:268
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Superlu_def.hpp:509
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:509
Provides a mechanism to map function calls to the correct Solver function based on the scalar type of...
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:70
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Superlu_def.hpp:605
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Superlu specific solve.
Definition: Amesos2_Superlu_def.hpp:374
Teuchos::Array< slu_type > bvals_
Persisting 1D store for B.
Definition: Amesos2_Superlu_decl.hpp:275
Teuchos::Array< slu_type > xvals_
Persisting 1D store for X.
Definition: Amesos2_Superlu_decl.hpp:273
Interface to Amesos2 solver objects.
Definition: Amesos2_Solver_decl.hpp:78
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:76
Provides access to interesting solver traits.
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_Superlu_def.hpp:520
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Superlu_def.hpp:186
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_Superlu_def.hpp:132
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Superlu.
Definition: Amesos2_Superlu_def.hpp:211
Amesos2 interface to the SuperLU package.
Definition: Amesos2_Superlu_decl.hpp:73