Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_KLU2_decl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Amesos2: Templated Direct Sparse Solver Package
4//
5// Copyright 2011 NTESS and the Amesos2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
18#ifndef AMESOS2_KLU2_DECL_HPP
19#define AMESOS2_KLU2_DECL_HPP
20
22#include "Amesos2_SolverCore.hpp"
24
25
26namespace Amesos2 {
27
28
36template <class Matrix,
37 class Vector>
38class KLU2 : public SolverCore<Amesos2::KLU2, Matrix, Vector>
39{
40 friend class SolverCore<Amesos2::KLU2,Matrix,Vector>; // Give our base access
41 // to our private
42 // implementation funcs
43public:
44
46 static const char* name; // declaration. Initialization outside.
47
48 typedef KLU2<Matrix,Vector> type;
49 typedef SolverCore<Amesos2::KLU2,Matrix,Vector> super_type;
50
51 // Since typedef's are not inheritted, go grab them
52 typedef typename VectorTraits<Vector>::scalar_t vector_scalar_type;
53 typedef typename super_type::scalar_type scalar_type;
54 typedef typename super_type::local_ordinal_type local_ordinal_type;
55 typedef typename super_type::global_ordinal_type global_ordinal_type;
56 typedef typename super_type::global_size_type global_size_type;
57 typedef typename super_type::node_type node_type;
58
59 typedef TypeMap<Amesos2::KLU2,scalar_type> type_map;
60
61 /*
62 * The KLU2 interface will need two other typedef's, which are:
63 * - the KLU2 type that corresponds to scalar_type and
64 * - the corresponding type to use for magnitude
65 */
66 typedef typename type_map::type klu2_type;
67 typedef typename type_map::dtype klu2_dtype;
68
69 typedef FunctionMap<Amesos2::KLU2,klu2_type> function_map;
70
71 typedef Matrix matrix_type;
72 typedef MatrixAdapter<matrix_type> matrix_adapter_type;
73
75
76
83 KLU2(Teuchos::RCP<const Matrix> A,
84 Teuchos::RCP<Vector> X,
85 Teuchos::RCP<const Vector> B);
86
87
89 ~KLU2( );
90
92
93private:
94
99 bool single_proc_optimization() const;
100
106 int preOrdering_impl();
107
108
117
118
125
126
138 int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
139 const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
140
141
145 bool matrixShapeOK_impl() const;
146
147
176 const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
177
178
185 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
186
187
196 bool loadA_impl(EPhase current_phase);
197
198
203 void describe_impl(Teuchos::FancyOStream &out,
204 const Teuchos::EVerbosityLevel verbLevel) const;
205
206
207 // struct holds all data necessary for KLU2 factorization or solve call
208 mutable struct KLU2Data {
209 ::KLU2::klu_symbolic<klu2_dtype, local_ordinal_type> *symbolic_;
210 ::KLU2::klu_numeric<klu2_dtype, local_ordinal_type> *numeric_;
211 ::KLU2::klu_common<klu2_dtype, local_ordinal_type> common_;
212 } data_ ;
213
214 typedef Kokkos::DefaultHostExecutionSpace HostSpaceType;
215 typedef Kokkos::View<local_ordinal_type*, HostSpaceType> host_ordinal_type_array;
216
217 typedef Kokkos::View<klu2_type*, HostSpaceType> host_value_type_array;
218
219 // The following Views are persisting storage arrays for A, X, and B
221 host_value_type_array host_nzvals_view_;
222
224 host_ordinal_type_array host_rows_view_;
226 host_ordinal_type_array host_col_ptr_view_;
227
228 typedef typename Kokkos::View<klu2_type**, Kokkos::LayoutLeft, HostSpaceType>
229 host_solve_array_t;
230
232 mutable host_solve_array_t xValues_;
233
235 mutable host_solve_array_t bValues_;
236
239 mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_type,
240 global_ordinal_type,
241 node_type>> distributionMap_;
242
246
247 bool is_contiguous_;
248 bool use_gather_;
249
250 int debug_level_;
251}; // End class KLU2
252
253
254// Specialize solver_traits struct for KLU2
255template <>
256struct solver_traits<KLU2> {
257#ifdef HAVE_TEUCHOS_COMPLEX
258 typedef Meta::make_list6<float,
259 double,
260 Kokkos::complex<float>,
261 Kokkos::complex<double>,
262 std::complex<float>,
263 std::complex<double> > supported_scalars;
264#else
265 typedef Meta::make_list2<float, double> supported_scalars;
266#endif
267};
268
269template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
270struct solver_supports_matrix<KLU2,
271 KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
272 static const bool value = true;
273};
274
275} // end namespace Amesos2
276
277#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:39
host_ordinal_type_array host_rows_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition Amesos2_KLU2_decl.hpp:224
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition Amesos2_KLU2_def.hpp:473
host_solve_array_t xValues_
Persisting 1D store for X.
Definition Amesos2_KLU2_decl.hpp:232
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:79
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > distributionMap_
Definition Amesos2_KLU2_decl.hpp:241
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition Amesos2_KLU2_def.hpp:430
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using KLU2.
Definition Amesos2_KLU2_def.hpp:99
host_value_type_array host_nzvals_view_
Stores the values of the nonzero entries for CHOLMOD.
Definition Amesos2_KLU2_decl.hpp:221
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition Amesos2_KLU2_def.hpp:85
host_ordinal_type_array host_col_ptr_view_
Stores the row indices of the nonzero entries.
Definition Amesos2_KLU2_decl.hpp:226
void describe_impl(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the status information about the current solver with some level of verbosity.
Definition Amesos2_KLU2_def.hpp:589
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:210
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition Amesos2_KLU2_def.hpp:508
host_solve_array_t bValues_
Persisting 1D store for B.
Definition Amesos2_KLU2_decl.hpp:235
int numericFactorization_impl()
KLU2 specific numeric factorization.
Definition Amesos2_KLU2_def.hpp:129
static const char * name
Name of this solver interface.
Definition Amesos2_KLU2_decl.hpp:46
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition Amesos2_KLU2_def.hpp:441
int transFlag_
Definition Amesos2_KLU2_decl.hpp:245
A Matrix adapter interface for Amesos2.
Definition Amesos2_MatrixAdapter_decl.hpp:42
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers.
Definition Amesos2_SolverCore_decl.hpp:72
Passes functions to TPL functions based on type.
Definition Amesos2_FunctionMap.hpp:43
Map types to solver-specific data-types and enums.
Definition Amesos2_TypeMap.hpp:48
Provides traits about solvers.
Definition Amesos2_SolverTraits.hpp:37