Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Cholmod_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_CHOLMOD_DECL_HPP
54 #define AMESOS2_CHOLMOD_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 Cholmod : public SolverCore<Amesos2::Cholmod, Matrix, Vector>
74 {
75  friend class SolverCore<Amesos2::Cholmod,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 Cholmod<Matrix,Vector> type;
84  typedef SolverCore<Amesos2::Cholmod,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  typedef typename super_type::node_type node_type;
92 
93  typedef TypeMap<Amesos2::Cholmod,scalar_type> type_map;
94 
95  /*
96  * The SuperLU interface will need two other typedef's, which are:
97  * - the superlu type that corresponds to scalar_type and
98  * - the corresponding type to use for magnitude
99  */
100  typedef typename type_map::type chol_type;
101  typedef typename type_map::magnitude_type magnitude_type;
102 
103  typedef FunctionMap<Amesos2::Cholmod,chol_type> function_map;
104 
106 
107 
114  Cholmod(Teuchos::RCP<const Matrix> A,
115  Teuchos::RCP<Vector> X,
116  Teuchos::RCP<const Vector> B);
117 
118 
120  ~Cholmod( );
121 
123 
124 private:
125 
129  int preOrdering_impl();
130 
131 
140 
141 
148 
149 
161  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
162  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
163 
164 
168  bool matrixShapeOK_impl() const;
169 
170 
198  void setParameters_impl(
199  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
200 
201 
208  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
209 
210 
219  bool loadA_impl(EPhase current_phase);
220 
221 
222  // struct holds all data necessary to make a superlu factorization or solve call
223  mutable struct CholData {
224  CHOL::cholmod_sparse A;
225  CHOL::cholmod_dense x, b;
226  CHOL::cholmod_dense *Y, *E;
227  CHOL::cholmod_factor *L;
228  CHOL::cholmod_common c;
229  } data_;
230 
231  // The following Arrays are persisting storage arrays for A, X, and B
233  Teuchos::Array<chol_type> nzvals_;
235  Teuchos::Array<int> rowind_;
237  Teuchos::Array<int> colptr_;
238 
240  Teuchos::Array<chol_type> xvals_; int ldx_;
242  Teuchos::Array<chol_type> bvals_; int ldb_;
243 
244  bool firstsolve;
245 
246  // Used as a hack around cholmod doing ordering and symfact together
247  bool skip_symfact;
248 
249  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > map;
250 
251  bool is_contiguous_;
252 }; // End class Cholmod
253 
254 
255 /* Specialize solver_traits struct for Cholmod
256  *
257  * Based on the CHOLMOD documentation, the support for
258  * single-precision complex numbers is unclear. Much of the
259  * discussion of complex types only makes explicit mention of 'double'
260  * types. So, be pessimistic for now and don't declare
261  * single-precision complex support
262  */
263 template <>
264 struct solver_traits<Cholmod> {
265 #ifdef HAVE_TEUCHOS_COMPLEX
266  typedef Meta::make_list4<float,
267  double,
268  std::complex<double>,
269  CHOL::complex> supported_scalars;
270 #else
271  typedef Meta::make_list2<float, double> supported_scalars;
272 #endif
273 };
274 
275 } // end namespace Amesos2
276 
277 #endif // AMESOS2_CHOLMOD_DECL_HPP
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Cholmod_def.hpp:104
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
Teuchos::Array< chol_type > xvals_
Persisting 1D store for X.
Definition: Amesos2_Cholmod_decl.hpp:240
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Cholmod_def.hpp:346
Template for providing a mechanism to map function calls to the correct Solver function based on the ...
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
Teuchos::Array< chol_type > nzvals_
Stores the values of the nonzero entries for CHOLMOD.
Definition: Amesos2_Cholmod_decl.hpp:233
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Cholmod_def.hpp:291
Teuchos::Array< chol_type > bvals_
Persisting 1D store for B.
Definition: Amesos2_Cholmod_decl.hpp:242
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:509
Teuchos::Array< int > colptr_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Cholmod_decl.hpp:237
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:70
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
CHOLMOD specific solve.
Definition: Amesos2_Cholmod_def.hpp:191
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_Cholmod_def.hpp:299
Teuchos::Array< int > rowind_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Cholmod_decl.hpp:235
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:76
Provides access to interesting solver traits.
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Cholmod_def.hpp:392
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using CHOLMOD.
Definition: Amesos2_Cholmod_def.hpp:121
Amesos2 interface to the SuperLU package.
Definition: Amesos2_Cholmod_decl.hpp:73
int numericFactorization_impl()
CHOLMOD specific numeric factorization.
Definition: Amesos2_Cholmod_def.hpp:143