Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Cholmod_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
19#ifndef AMESOS2_CHOLMOD_DECL_HPP
20#define AMESOS2_CHOLMOD_DECL_HPP
21
23#include "Amesos2_SolverCore.hpp"
25
26#if defined(KOKKOSKERNELS_ENABLE_SUPERNODAL_SPTRSV) && defined(KOKKOSKERNELS_ENABLE_TPL_CHOLMOD)
27#include "KokkosKernels_Handle.hpp"
28#endif
29
30namespace Amesos2 {
31
32
40template <class Matrix,
41 class Vector>
42class Cholmod : public SolverCore<Amesos2::Cholmod, Matrix, Vector>
43{
44 friend class SolverCore<Amesos2::Cholmod,Matrix,Vector>; // Give our base access
45 // to our private
46 // implementation funcs
47public:
48
50 static const char* name; // declaration. Initialization outside.
51
52 using type = Cholmod<Matrix,Vector>;
53 using super_type = SolverCore<Amesos2::Cholmod,Matrix,Vector>;
54
55 // Since using's are not inheritted, go grab them
56 using scalar_type = typename super_type::scalar_type;
57 using local_ordinal_type = typename super_type::local_ordinal_type;
58 using global_ordinal_type = typename super_type::global_ordinal_type;
59 using global_size_type = typename super_type::global_size_type;
60 using node_type = typename super_type::node_type;
61
62 using type_map = TypeMap<Amesos2::Cholmod,scalar_type>;
63
64 /*
65 * The CHOLMOD interface will need two other using's, which are:
66 * - the CHOLMOD type that corresponds to scalar_type and
67 * - the corresponding type to use for magnitude
68 */
69 using chol_type = typename type_map::type;
70 using magnitude_type = typename type_map::magnitude_type;
71
72 using function_map = FunctionMap<Amesos2::Cholmod,chol_type>;
73
75
76
83 Cholmod(Teuchos::RCP<const Matrix> A,
84 Teuchos::RCP<Vector> X,
85 Teuchos::RCP<const Vector> B);
86
87
89 ~Cholmod( );
90
92
93private:
94
98 int preOrdering_impl();
99
100
109
110
117
118
130 int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
131 const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
132
133
137 bool matrixShapeOK_impl() const;
138
156 const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
157
158
165 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
166
167
176 bool loadA_impl(EPhase current_phase);
177
178
183 void describe_impl(Teuchos::FancyOStream &out,
184 const Teuchos::EVerbosityLevel verbLevel) const;
185
186
187 // struct holds all data necessary to make a cholmod factorization or solve call
188 mutable struct CholData {
189 cholmod_sparse A;
190 cholmod_dense x, b;
191 cholmod_dense *Y, *E;
192 cholmod_factor *L;
193 cholmod_common c;
194 } data_;
195
196 typedef Kokkos::DefaultHostExecutionSpace HostExecSpaceType;
197 typedef typename HostExecSpaceType::memory_space HostMemSpaceType;
198
199 // use_cholmod_int_type controls whether we use CHOLMOD_INT or CHOLMOD_LONG.
200 // To preserve a simple interface for the user where this can be picked
201 // simply by setting a parameter, we prepare both types of arrays and just
202 // one will actually be used.
203 typedef int size_int_type;
204 typedef int ordinal_int_type;
205
206 typedef long size_long_type;
207 typedef long ordinal_long_type;
208
209 typedef Kokkos::View<size_long_type*, HostExecSpaceType> host_size_long_type_array;
210 typedef Kokkos::View<ordinal_long_type*, HostExecSpaceType> host_ordinal_long_type_array;
211
212 typedef Kokkos::View<size_int_type*, HostExecSpaceType> host_size_int_type_array;
213 typedef Kokkos::View<ordinal_int_type*, HostExecSpaceType> host_ordinal_int_type_array;
214
215 typedef Kokkos::View<chol_type*, HostExecSpaceType> host_value_type_array;
216
217 // The following Views are persisting storage arrays for A, X, and B
219 host_value_type_array host_nzvals_view_;
221 host_size_int_type_array host_rows_int_view_;
222 host_size_long_type_array host_rows_long_view_;
224 host_ordinal_int_type_array host_col_ptr_int_view_;
225 host_ordinal_long_type_array host_col_ptr_long_view_;
226
227 typedef typename Kokkos::View<chol_type**, Kokkos::LayoutLeft, HostExecSpaceType>
228 host_solve_array_t;
229
231 mutable host_solve_array_t host_xValues_;
232
234 mutable host_solve_array_t host_bValues_;
235
236#if defined(KOKKOSKERNELS_ENABLE_SUPERNODAL_SPTRSV) && defined(KOKKOSKERNELS_ENABLE_TPL_CHOLMOD)
237
238 using DeviceExecSpaceType= Kokkos::DefaultExecutionSpace;
239
240 #ifdef KOKKOS_ENABLE_CUDA
241 // solver will be UVM off even though Tpetra is CudaUVMSpace
242 using DeviceMemSpaceType = typename Kokkos::CudaSpace;
243 #elif KOKKOS_ENABLE_HIP
244 // same as above, make the solver UVM off
245 using DeviceMemSpaceType = typename Kokkos::HIPSpace;
246 #else
247 using DeviceMemSpaceType = typename DeviceExecSpaceType::memory_space;
248 #endif
249
250 typedef Kokkos::View<chol_type**, Kokkos::LayoutLeft, DeviceMemSpaceType>
251 device_solve_array_t;
252 // For triangular solves we have both host and device versions of xValues and
253 // bValues because a parameter can turn it on or off.
254 mutable device_solve_array_t device_xValues_;
255 mutable device_solve_array_t device_bValues_;
256 typedef Kokkos::View<int*, HostMemSpaceType> host_int_array;
257 typedef Kokkos::View<int*, DeviceMemSpaceType> device_int_array;
258 host_int_array host_trsv_etree_;
259 host_int_array host_trsv_perm_;
260 device_int_array device_trsv_perm_;
261 mutable device_solve_array_t device_trsv_rhs_;
262 mutable device_solve_array_t device_trsv_sol_;
263 typedef KokkosKernels::Experimental::KokkosKernelsHandle <size_int_type, ordinal_int_type, chol_type,
264 DeviceExecSpaceType, DeviceMemSpaceType, DeviceMemSpaceType> kernel_handle_int_type;
265 typedef KokkosKernels::Experimental::KokkosKernelsHandle <size_long_type, ordinal_long_type, chol_type,
266 DeviceExecSpaceType, DeviceMemSpaceType, DeviceMemSpaceType> kernel_handle_long_type;
267 mutable kernel_handle_int_type device_int_khL_;
268 mutable kernel_handle_int_type device_int_khU_;
269 mutable kernel_handle_long_type device_long_khL_;
270 mutable kernel_handle_long_type device_long_khU_;
271#endif
272
273 bool firstsolve;
274
275 // Used as a hack around cholmod doing ordering and symfact together
276 bool skip_symfact;
277
278 Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > map;
279
280 bool is_contiguous_;
281 bool use_triangular_solves_;
282 bool use_cholmod_int_type_; // controls if Cholmod is int or long
283
284 void triangular_solve_symbolic();
285 void triangular_solve_numeric();
286
287public: // for GPU
288 void triangular_solve() const; // Only for internal use - public to support kernels
289}; // End class Cholmod
290
291template <>
292struct solver_traits<Cholmod> {
293
294// Cholmod does not yet support float.
295#ifdef HAVE_TEUCHOS_COMPLEX
296 typedef Meta::make_list3<double, std::complex<double>,
297 Kokkos::complex<double>> supported_scalars;
298#else
299 typedef Meta::make_list1<double> supported_scalars;
300#endif
301};
302
303template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
304struct solver_supports_matrix<Cholmod,
305 KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
306 static const bool value = true;
307};
308
309} // end namespace Amesos2
310
311#endif // AMESOS2_CHOLMOD_DECL_HPP
Template for providing a mechanism to map function calls to the correct Solver function based on the ...
Provides access to interesting solver traits.
Amesos2 interface to the CHOLMOD package.
Definition Amesos2_Cholmod_decl.hpp:43
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:208
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition Amesos2_Cholmod_def.hpp:79
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using CHOLMOD.
Definition Amesos2_Cholmod_def.hpp:110
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition Amesos2_Cholmod_def.hpp:327
host_solve_array_t host_xValues_
Persisting 1D store for X.
Definition Amesos2_Cholmod_decl.hpp:231
int numericFactorization_impl()
CHOLMOD specific numeric factorization.
Definition Amesos2_Cholmod_def.hpp:153
host_ordinal_int_type_array host_col_ptr_int_view_
Stores the row indices of the nonzero entries.
Definition Amesos2_Cholmod_decl.hpp:224
static const char * name
Name of this solver interface.
Definition Amesos2_Cholmod_decl.hpp:50
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition Amesos2_Cholmod_def.hpp:319
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition Amesos2_Cholmod_def.hpp:441
host_size_int_type_array host_rows_int_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition Amesos2_Cholmod_decl.hpp:221
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition Amesos2_Cholmod_def.hpp:390
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_Cholmod_def.hpp:532
host_value_type_array host_nzvals_view_
Stores the values of the nonzero entries for CHOLMOD.
Definition Amesos2_Cholmod_decl.hpp:219
host_solve_array_t host_bValues_
Persisting 1D store for B.
Definition Amesos2_Cholmod_decl.hpp:234
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