Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Superlu_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_SUPERLU_DECL_HPP
20#define AMESOS2_SUPERLU_DECL_HPP
21
23#include "Amesos2_SolverCore.hpp"
25
26#if defined(KOKKOSKERNELS_ENABLE_SUPERNODAL_SPTRSV) && defined(KOKKOSKERNELS_ENABLE_TPL_SUPERLU)
27#include "KokkosKernels_Handle.hpp"
28#endif
29
30namespace Amesos2 {
31
32
40template <class Matrix,
41 class Vector>
42class Superlu : public SolverCore<Amesos2::Superlu, Matrix, Vector>
43{
44 friend class SolverCore<Amesos2::Superlu,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 typedef Superlu<Matrix,Vector> type;
53 typedef SolverCore<Amesos2::Superlu,Matrix,Vector> super_type;
54
55 // Since typedef's are not inheritted, go grab them
56 typedef typename super_type::scalar_type scalar_type;
57 typedef typename super_type::local_ordinal_type local_ordinal_type;
58 typedef typename super_type::global_ordinal_type global_ordinal_type;
59 typedef typename super_type::global_size_type global_size_type;
60
61 typedef TypeMap<Amesos2::Superlu,scalar_type> type_map;
62
63 /*
64 * The SuperLU interface will need two other typedef's, which are:
65 * - the superlu type that corresponds to scalar_type and
66 * - the corresponding type to use for magnitude
67 */
68 typedef typename type_map::type slu_type;
69 typedef typename type_map::convert_type slu_convert_type;
70 typedef typename type_map::magnitude_type magnitude_type;
71
72 typedef FunctionMap<Amesos2::Superlu,slu_type> function_map;
73
75
76
83 Superlu(Teuchos::RCP<const Matrix> A,
84 Teuchos::RCP<Vector> X,
85 Teuchos::RCP<const Vector> B);
86
87
89 ~Superlu( );
90
92
94 std::string description() const override;
95
96private:
97
103 int preOrdering_impl();
104
105
114
115
122
123
135 int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
136 const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
137
138
142 bool matrixShapeOK_impl() const;
143
144
179 const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
180
181
188 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
189
190
199 bool loadA_impl(EPhase current_phase);
200
205 void describe_impl(Teuchos::FancyOStream &out,
206 const Teuchos::EVerbosityLevel verbLevel) const;
207
208 typedef Kokkos::DefaultHostExecutionSpace HostExecSpaceType;
209
210 // struct holds all data necessary to make a superlu factorization or solve call
211 mutable struct SLUData {
212 SLU::SuperMatrix A, B, X, L, U; // matrix A in NCformat
213 SLU::SuperMatrix AC; // permuted matrix A in NCPformat
214
215 SLU::superlu_options_t options;
216 SLU::mem_usage_t mem_usage;
217#ifdef HAVE_AMESOS2_SUPERLU5_API
218 SLU::GlobalLU_t lu; // Use for gssvx and gsisx in SuperLU 5.0
219#endif
220 SLU::SuperLUStat_t stat;
221
222
223
224 typedef Kokkos::View<magnitude_type*, HostExecSpaceType> host_mag_array;
225 typedef Kokkos::View<int*, HostExecSpaceType> host_int_array;
226 host_mag_array berr;
227 host_mag_array ferr;
228 host_int_array perm_r;
229 host_int_array perm_c;
230 host_int_array etree;
231 host_mag_array R;
232 host_mag_array C;
233
234#if defined(KOKKOSKERNELS_ENABLE_SUPERNODAL_SPTRSV) && defined(KOKKOSKERNELS_ENABLE_TPL_SUPERLU)
235 host_int_array parents;
236#endif
237
238 char equed;
239 bool rowequ, colequ; // flags what type of equilibration
240 // has been performed
241 magnitude_type anorm, rcond; // condition number estimate
242
243 int relax;
244 int panel_size;
245 } data_;
246
247 typedef int size_type;
248 typedef int ordinal_type;
249 typedef Kokkos::View<size_type*, HostExecSpaceType> host_size_type_array;
250 typedef Kokkos::View<ordinal_type*, HostExecSpaceType> host_ordinal_type_array;
251 typedef Kokkos::View<slu_type*, HostExecSpaceType> host_value_type_array;
252
253 // The following Arrays are persisting storage arrays for A, X, and B
255 host_value_type_array host_nzvals_view_;
256 Teuchos::Array<slu_convert_type> convert_nzvals_; // copy to SuperLU native array before calling SuperLU
257
259 host_size_type_array host_rows_view_;
261 host_ordinal_type_array host_col_ptr_view_;
262
263 typedef typename Kokkos::View<slu_type**, Kokkos::LayoutLeft, HostExecSpaceType>
264 host_solve_array_t;
265
267 mutable host_solve_array_t host_xValues_;
268 mutable Teuchos::Array<slu_convert_type> convert_xValues_; // copy to SuperLU native array before calling SuperLU
269
271 mutable host_solve_array_t host_bValues_;
272 mutable Teuchos::Array<slu_convert_type> convert_bValues_; // copy to SuperLU native array before calling SuperLU
273
274#if defined(KOKKOSKERNELS_ENABLE_SUPERNODAL_SPTRSV) && defined(KOKKOSKERNELS_ENABLE_TPL_SUPERLU)
275 typedef Kokkos::DefaultExecutionSpace DeviceExecSpaceType;
276
277 #ifdef KOKKOS_ENABLE_CUDA
278 // solver will be UVM off even though Tpetra is CudaUVMSpace
279 typedef typename Kokkos::CudaSpace DeviceMemSpaceType;
280 #else
281 typedef typename DeviceExecSpaceType::memory_space DeviceMemSpaceType;
282 #endif
283
284 typedef Kokkos::View<slu_type**, Kokkos::LayoutLeft, DeviceMemSpaceType>
285 device_solve_array_t;
286 // For triangular solves we have both host and device versions of xValues and
287 // bValues because a parameter can turn it on or off.
288 mutable device_solve_array_t device_xValues_;
289 mutable device_solve_array_t device_bValues_;
290 typedef Kokkos::View<int*, DeviceMemSpaceType> device_int_array;
291 typedef Kokkos::View<magnitude_type*, DeviceMemSpaceType> device_mag_array;
292 device_int_array device_trsv_perm_r_;
293 device_int_array device_trsv_perm_c_;
294 device_mag_array device_trsv_R_;
295 device_mag_array device_trsv_C_;
296 mutable device_solve_array_t device_trsv_rhs_;
297 mutable device_solve_array_t device_trsv_sol_;
298 typedef KokkosKernels::Experimental::KokkosKernelsHandle <size_type, ordinal_type, slu_type,
299 DeviceExecSpaceType, DeviceMemSpaceType, DeviceMemSpaceType> kernel_handle_type;
300 mutable kernel_handle_type device_khL_;
301 mutable kernel_handle_type device_khU_;
302 /* parameters for SpTRSV */
303 bool sptrsv_invert_diag_;
304 bool sptrsv_invert_offdiag_;
305 bool sptrsv_u_in_csr_;
306 bool sptrsv_merge_supernodes_;
307 bool sptrsv_use_spmv_;
308#endif
309
310 /* Note: In the above, must use "Amesos2::Superlu" rather than
311 * "Superlu" because otherwise the compiler references the
312 * specialized type of the class, and not the templated type that is
313 * required for Amesos2::TypeMap
314 */
315
316 /* SuperLU can accept input in either compressed-row or
317 * compressed-column storage. We will store and pass matrices in
318 * *compressed-column* format.
319 */
320
321 /*
322 * Internal flag that is used for the numericFactorization_impl
323 * routine. If true, then the superlu gstrf routine should have
324 * SamePattern_SameRowPerm in its options. Otherwise, it should
325 * factor from scratch.
326 *
327 * This is somewhat of a kludge to get around the fact that the
328 * superlu routines all expect something different from the options
329 * struct. The big issue is that we don't want gstrf doing the
330 * symbolic factorization if it doesn't need to. On the other hand,
331 * we can't leave options.Fact set to SamePattern_SameRowPerm
332 * because the solver driver needs it to be set at FACTORED. But
333 * having it set at FACTORED upon re-entrance into
334 * numericFactorization prompts gstrf to redo the symbolic
335 * factorization.
336 */
337 bool same_symbolic_;
338 bool ILU_Flag_;
339
340 bool is_contiguous_;
341 bool use_triangular_solves_;
342
343 void triangular_solve_factor();
344
345 /* call metis before SuperLU */
346 bool use_metis_;
347 bool symmetrize_metis_;
348
349 public: // for GPU
350 void triangular_solve() const; // Only for internal use - public to support kernels
351}; // End class Superlu
352
353
354// Specialize solver_traits struct for SuperLU
355template <>
356struct solver_traits<Superlu> {
357#ifdef HAVE_TEUCHOS_COMPLEX
358 typedef Meta::make_list6<float, double,
359 std::complex<float>, std::complex<double>,
360 Kokkos::complex<float>, Kokkos::complex<double>>
361 supported_scalars;
362#else
363 typedef Meta::make_list2<float, double> supported_scalars;
364#endif
365};
366
367template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
368struct solver_supports_matrix<Superlu,
369 KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
370 static const bool value = true;
371};
372
373} // end namespace Amesos2
374
375#endif // AMESOS2_SUPERLU_DECL_HPP
Provides access to interesting solver traits.
Provides a mechanism to map function calls to the correct Solver function based on the scalar type of...
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers.
Definition Amesos2_SolverCore_decl.hpp:72
Amesos2 interface to the SuperLU package.
Definition Amesos2_Superlu_decl.hpp:43
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition Amesos2_Superlu_def.hpp:674
int numericFactorization_impl()
Superlu specific numeric factorization.
Definition Amesos2_Superlu_def.hpp:283
host_solve_array_t host_xValues_
Persisting 1D store for X.
Definition Amesos2_Superlu_decl.hpp:267
std::string description() const override
Returns a short description of this Solver.
Definition Amesos2_Superlu_def.hpp:117
host_ordinal_type_array host_col_ptr_view_
Stores the row indices of the nonzero entries.
Definition Amesos2_Superlu_decl.hpp:261
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition Amesos2_Superlu_def.hpp:171
static const char * name
Name of this solver interface.
Definition Amesos2_Superlu_decl.hpp:50
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition Amesos2_Superlu_def.hpp:793
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Superlu specific solve.
Definition Amesos2_Superlu_def.hpp:478
host_size_type_array host_rows_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition Amesos2_Superlu_decl.hpp:259
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Superlu.
Definition Amesos2_Superlu_def.hpp:196
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition Amesos2_Superlu_def.hpp:685
host_value_type_array host_nzvals_view_
Stores the values of the nonzero entries for SuperLU.
Definition Amesos2_Superlu_decl.hpp:255
host_solve_array_t host_bValues_
Persisting 1D store for B.
Definition Amesos2_Superlu_decl.hpp:271
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition Amesos2_Superlu_def.hpp:937
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_Superlu_def.hpp:1003
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