Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_KLU2_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
52#ifndef AMESOS2_KLU2_DECL_HPP
53#define AMESOS2_KLU2_DECL_HPP
54
56#include "Amesos2_SolverCore.hpp"
58
59
60namespace Amesos2 {
61
62
70template <class Matrix,
71 class Vector>
72class KLU2 : public SolverCore<Amesos2::KLU2, Matrix, Vector>
73{
74 friend class SolverCore<Amesos2::KLU2,Matrix,Vector>; // Give our base access
75 // to our private
76 // implementation funcs
77public:
78
80 static const char* name; // declaration. Initialization outside.
81
82 typedef KLU2<Matrix,Vector> type;
83 typedef SolverCore<Amesos2::KLU2,Matrix,Vector> super_type;
84
85 // Since typedef's are not inheritted, go grab them
86 typedef typename super_type::scalar_type scalar_type;
87 typedef typename super_type::local_ordinal_type local_ordinal_type;
88 typedef typename super_type::global_ordinal_type global_ordinal_type;
89 typedef typename super_type::global_size_type global_size_type;
90
91 typedef TypeMap<Amesos2::KLU2,scalar_type> type_map;
92
93 /*
94 * The KLU2 interface will need two other typedef's, which are:
95 * - the KLU2 type that corresponds to scalar_type and
96 * - the corresponding type to use for magnitude
97 */
98 typedef typename type_map::type klu2_type;
99 typedef typename type_map::dtype klu2_dtype;
100
101 typedef FunctionMap<Amesos2::KLU2,klu2_type> function_map;
102
103 typedef Matrix matrix_type;
104 typedef MatrixAdapter<matrix_type> matrix_adapter_type;
105
107
108
115 KLU2(Teuchos::RCP<const Matrix> A,
116 Teuchos::RCP<Vector> X,
117 Teuchos::RCP<const Vector> B);
118
119
121 ~KLU2( );
122
124
125private:
126
131 bool single_proc_optimization() const;
132
138 int preOrdering_impl();
139
140
149
150
157
158
170 int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
171 const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
172
173
177 bool matrixShapeOK_impl() const;
178
179
208 const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
209
210
217 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
218
219
228 bool loadA_impl(EPhase current_phase);
229
230 // struct holds all data necessary for KLU2 factorization or solve call
231 mutable struct KLU2Data {
232 ::KLU2::klu_symbolic<klu2_dtype, local_ordinal_type> *symbolic_;
233 ::KLU2::klu_numeric<klu2_dtype, local_ordinal_type> *numeric_;
234 ::KLU2::klu_common<klu2_dtype, local_ordinal_type> common_;
235 } data_ ;
236
237 typedef Kokkos::DefaultHostExecutionSpace HostSpaceType;
238 typedef Kokkos::View<local_ordinal_type*, HostSpaceType> host_ordinal_type_array;
239
240 typedef Kokkos::View<klu2_type*, HostSpaceType> host_value_type_array;
241
242 // The following Views are persisting storage arrays for A, X, and B
244 host_value_type_array host_nzvals_view_;
245
247 host_ordinal_type_array host_rows_view_;
249 host_ordinal_type_array host_col_ptr_view_;
250
251 typedef typename Kokkos::View<klu2_type**, Kokkos::LayoutLeft, HostSpaceType>
252 host_solve_array_t;
253
255 mutable host_solve_array_t xValues_;
256
258 mutable host_solve_array_t bValues_;
259
263
264 bool is_contiguous_;
265}; // End class KLU2
266
267
268// Specialize solver_traits struct for KLU2
269template <>
270struct solver_traits<KLU2> {
271#ifdef HAVE_TEUCHOS_COMPLEX
272 typedef Meta::make_list6<float,
273 double,
274 Kokkos::complex<float>,
275 Kokkos::complex<double>,
276 std::complex<float>,
277 std::complex<double> > supported_scalars;
278#else
279 typedef Meta::make_list2<float, double> supported_scalars;
280#endif
281};
282
283template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
284struct solver_supports_matrix<KLU2,
285 KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
286 static const bool value = true;
287};
288
289} // end namespace Amesos2
290
291#endif // AMESOS2_KLU2_DECL_HPP
Provides a mechanism to map function calls to the correct Solver function based on the scalar type of...
Provides access to interesting solver traits.
Amesos2 interface to the KLU2 package.
Definition: Amesos2_KLU2_decl.hpp:73
host_ordinal_type_array host_rows_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_KLU2_decl.hpp:247
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_KLU2_def.hpp:452
host_solve_array_t xValues_
Persisting 1D store for X.
Definition: Amesos2_KLU2_decl.hpp:255
bool single_proc_optimization() const
can we optimize size_type and ordinal_type for straight pass through, also check that is_contiguous_ ...
Definition: Amesos2_KLU2_def.hpp:111
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_KLU2_def.hpp:416
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using KLU2.
Definition: Amesos2_KLU2_def.hpp:131
host_value_type_array host_nzvals_view_
Stores the values of the nonzero entries for CHOLMOD.
Definition: Amesos2_KLU2_decl.hpp:244
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_KLU2_def.hpp:117
host_ordinal_type_array host_col_ptr_view_
Stores the row indices of the nonzero entries.
Definition: Amesos2_KLU2_decl.hpp:249
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
KLU2 specific solve.
Definition: Amesos2_KLU2_def.hpp:229
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_KLU2_def.hpp:485
host_solve_array_t bValues_
Persisting 1D store for B.
Definition: Amesos2_KLU2_decl.hpp:258
int numericFactorization_impl()
KLU2 specific numeric factorization.
Definition: Amesos2_KLU2_def.hpp:161
static const char * name
Name of this solver interface.
Definition: Amesos2_KLU2_decl.hpp:80
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_KLU2_def.hpp:427
int transFlag_
Definition: Amesos2_KLU2_decl.hpp:262
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers.
Definition: Amesos2_SolverCore_decl.hpp:106
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:77
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71