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
57#include "Amesos2_SolverCore.hpp"
59
60#if defined(KOKKOSKERNELS_ENABLE_SUPERNODAL_SPTRSV) && defined(KOKKOSKERNELS_ENABLE_TPL_CHOLMOD)
61#include "KokkosKernels_Handle.hpp"
62#endif
63
64namespace Amesos2 {
65
66
74template <class Matrix,
75 class Vector>
76class Cholmod : public SolverCore<Amesos2::Cholmod, Matrix, Vector>
77{
78 friend class SolverCore<Amesos2::Cholmod,Matrix,Vector>; // Give our base access
79 // to our private
80 // implementation funcs
81public:
82
84 static const char* name; // declaration. Initialization outside.
85
86 using type = Cholmod<Matrix,Vector>;
87 using super_type = SolverCore<Amesos2::Cholmod,Matrix,Vector>;
88
89 // Since using's are not inheritted, go grab them
90 using scalar_type = typename super_type::scalar_type;
91 using local_ordinal_type = typename super_type::local_ordinal_type;
92 using global_ordinal_type = typename super_type::global_ordinal_type;
93 using global_size_type = typename super_type::global_size_type;
94 using node_type = typename super_type::node_type;
95
96 using type_map = TypeMap<Amesos2::Cholmod,scalar_type>;
97
98 /*
99 * The CHOLMOD interface will need two other using's, which are:
100 * - the CHOLMOD type that corresponds to scalar_type and
101 * - the corresponding type to use for magnitude
102 */
103 using chol_type = typename type_map::type;
104 using magnitude_type = typename type_map::magnitude_type;
105
106 using function_map = FunctionMap<Amesos2::Cholmod,chol_type>;
107
109
110
117 Cholmod(Teuchos::RCP<const Matrix> A,
118 Teuchos::RCP<Vector> X,
119 Teuchos::RCP<const Vector> B);
120
121
123 ~Cholmod( );
124
126
127private:
128
132 int preOrdering_impl();
133
134
143
144
151
152
164 int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
165 const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
166
167
171 bool matrixShapeOK_impl() const;
172
190 const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
191
192
199 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
200
201
210 bool loadA_impl(EPhase current_phase);
211
212
213 // struct holds all data necessary to make a cholmod factorization or solve call
214 mutable struct CholData {
215 cholmod_sparse A;
216 cholmod_dense x, b;
217 cholmod_dense *Y, *E;
218 cholmod_factor *L;
219 cholmod_common c;
220 } data_;
221
222 typedef Kokkos::DefaultHostExecutionSpace HostExecSpaceType;
223 typedef typename HostExecSpaceType::memory_space HostMemSpaceType;
224
225 // use_cholmod_int_type controls whether we use CHOLMOD_INT or CHOLMOD_LONG.
226 // To preserve a simple interface for the user where this can be picked
227 // simply by setting a parameter, we prepare both types of arrays and just
228 // one will actually be used.
229 typedef int size_int_type;
230 typedef int ordinal_int_type;
231
232 typedef long size_long_type;
233 typedef long ordinal_long_type;
234
235 typedef Kokkos::View<size_long_type*, HostExecSpaceType> host_size_long_type_array;
236 typedef Kokkos::View<ordinal_long_type*, HostExecSpaceType> host_ordinal_long_type_array;
237
238 typedef Kokkos::View<size_int_type*, HostExecSpaceType> host_size_int_type_array;
239 typedef Kokkos::View<ordinal_int_type*, HostExecSpaceType> host_ordinal_int_type_array;
240
241 typedef Kokkos::View<chol_type*, HostExecSpaceType> host_value_type_array;
242
243 // The following Views are persisting storage arrays for A, X, and B
245 host_value_type_array host_nzvals_view_;
247 host_size_int_type_array host_rows_int_view_;
248 host_size_long_type_array host_rows_long_view_;
250 host_ordinal_int_type_array host_col_ptr_int_view_;
251 host_ordinal_long_type_array host_col_ptr_long_view_;
252
253 typedef typename Kokkos::View<chol_type**, Kokkos::LayoutLeft, HostExecSpaceType>
254 host_solve_array_t;
255
257 mutable host_solve_array_t host_xValues_;
258
260 mutable host_solve_array_t host_bValues_;
261
262#if defined(KOKKOSKERNELS_ENABLE_SUPERNODAL_SPTRSV) && defined(KOKKOSKERNELS_ENABLE_TPL_CHOLMOD)
263
264 using DeviceExecSpaceType= Kokkos::DefaultExecutionSpace;
265
266 #ifdef KOKKOS_ENABLE_CUDA
267 // solver will be UVM off even though Tpetra is CudaUVMSpace
268 using DeviceMemSpaceType = typename Kokkos::CudaSpace;
269 #elif KOKKOS_ENABLE_HIP
270 // same as above, make the solver UVM off
271 using DeviceMemSpaceType = typename Kokkos::Experimental::HIPSpace;
272 #else
273 using DeviceMemSpaceType = typename DeviceExecSpaceType::memory_space;
274 #endif
275
276 typedef Kokkos::View<chol_type**, Kokkos::LayoutLeft, DeviceMemSpaceType>
277 device_solve_array_t;
278 // For triangular solves we have both host and device versions of xValues and
279 // bValues because a parameter can turn it on or off.
280 mutable device_solve_array_t device_xValues_;
281 mutable device_solve_array_t device_bValues_;
282 typedef Kokkos::View<int*, HostMemSpaceType> host_int_array;
283 typedef Kokkos::View<int*, DeviceMemSpaceType> device_int_array;
284 host_int_array host_trsv_etree_;
285 host_int_array host_trsv_perm_;
286 device_int_array device_trsv_perm_;
287 mutable device_solve_array_t device_trsv_rhs_;
288 mutable device_solve_array_t device_trsv_sol_;
289 typedef KokkosKernels::Experimental::KokkosKernelsHandle <size_int_type, ordinal_int_type, chol_type,
290 DeviceExecSpaceType, DeviceMemSpaceType, DeviceMemSpaceType> kernel_handle_int_type;
291 typedef KokkosKernels::Experimental::KokkosKernelsHandle <size_long_type, ordinal_long_type, chol_type,
292 DeviceExecSpaceType, DeviceMemSpaceType, DeviceMemSpaceType> kernel_handle_long_type;
293 mutable kernel_handle_int_type device_int_khL_;
294 mutable kernel_handle_int_type device_int_khU_;
295 mutable kernel_handle_long_type device_long_khL_;
296 mutable kernel_handle_long_type device_long_khU_;
297#endif
298
299 bool firstsolve;
300
301 // Used as a hack around cholmod doing ordering and symfact together
302 bool skip_symfact;
303
304 Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > map;
305
306 bool is_contiguous_;
307 bool use_triangular_solves_;
308 bool use_cholmod_int_type_; // controls if Cholmod is int or long
309
310 void triangular_solve_symbolic();
311 void triangular_solve_numeric();
312
313public: // for GPU
314 void triangular_solve() const; // Only for internal use - public to support kernels
315}; // End class Cholmod
316
317template <>
318struct solver_traits<Cholmod> {
319
320// Cholmod does not yet support float.
321#ifdef HAVE_TEUCHOS_COMPLEX
322 typedef Meta::make_list3<double, std::complex<double>,
323 Kokkos::complex<double>> supported_scalars;
324#else
325 typedef Meta::make_list1<double> supported_scalars;
326#endif
327};
328
329template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
330struct solver_supports_matrix<Cholmod,
331 KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
332 static const bool value = true;
333};
334
335} // end namespace Amesos2
336
337#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:77
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:242
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Cholmod_def.hpp:113
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using CHOLMOD.
Definition: Amesos2_Cholmod_def.hpp:144
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_Cholmod_def.hpp:361
host_solve_array_t host_xValues_
Persisting 1D store for X.
Definition: Amesos2_Cholmod_decl.hpp:257
int numericFactorization_impl()
CHOLMOD specific numeric factorization.
Definition: Amesos2_Cholmod_def.hpp:187
host_ordinal_int_type_array host_col_ptr_int_view_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Cholmod_decl.hpp:250
static const char * name
Name of this solver interface.
Definition: Amesos2_Cholmod_decl.hpp:84
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Cholmod_def.hpp:353
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Cholmod_def.hpp:475
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:247
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Cholmod_def.hpp:424
host_value_type_array host_nzvals_view_
Stores the values of the nonzero entries for CHOLMOD.
Definition: Amesos2_Cholmod_decl.hpp:245
host_solve_array_t host_bValues_
Persisting 1D store for B.
Definition: Amesos2_Cholmod_decl.hpp:260
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