Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Tacho_decl.hpp
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
10#ifndef AMESOS2_TACHO_DECL_HPP
11#define AMESOS2_TACHO_DECL_HPP
12
13#include <Kokkos_Core.hpp>
14
16#include "Amesos2_SolverCore.hpp"
17#include "Amesos2_Tacho_FunctionMap.hpp"
18
19#include "Tacho.hpp"
20#include "Tacho_Solver.hpp"
21
22namespace Amesos2 {
23
31template <class Matrix,
32 class Vector>
33class TachoSolver : public SolverCore<Amesos2::TachoSolver, Matrix, Vector>
34{
35 friend class SolverCore<Amesos2::TachoSolver,Matrix,Vector>; // Give our base access
36 // to our private
37 // implementation funcs
38public:
39
41 static const char* name; // declaration. Initialization outside.
42
43 typedef TachoSolver<Matrix,Vector> type;
44 typedef SolverCore<Amesos2::TachoSolver,Matrix,Vector> super_type;
45
46 // Since typedef's are not inheritted, go grab them
47 typedef typename super_type::scalar_type scalar_type;
48 typedef typename super_type::local_ordinal_type local_ordinal_type;
49 typedef typename super_type::global_size_type global_size_type;
50
51 typedef TypeMap<Amesos2::TachoSolver,scalar_type> type_map;
52
53 /*
54 * The Tacho interface will need two other typedef's, which are:
55 * - the tacho type that corresponds to scalar_type and
56 * - the corresponding type to use for magnitude
57 */
58 typedef typename type_map::type tacho_type;
59 typedef typename type_map::magnitude_type magnitude_type;
60
61 typedef FunctionMap<Amesos2::TachoSolver,tacho_type> function_map;
62
63 // TODO - Not sure yet best place for organizing these typedefs
64 typedef Tacho::ordinal_type ordinal_type;
65 typedef Tacho::size_type size_type;
66
67 typedef Kokkos::DefaultExecutionSpace exec_space_type;
68 typedef Kokkos::DefaultHostExecutionSpace host_exec_space_type;
69
70 typedef typename
71 Tacho::UseThisDevice<exec_space_type>::device_type device_type;
72 typedef typename
73 Tacho::UseThisDevice<host_exec_space_type>::device_type host_device_type;
74
75 typedef Tacho::DummyTaskScheduler<exec_space_type> scheduler_type;
76
77 typedef Kokkos::View<size_type*, device_type> device_size_type_array;
78 typedef Kokkos::View<ordinal_type*, device_type> device_ordinal_type_array;
79 typedef Kokkos::View<tacho_type*, device_type> device_value_type_array;
80
81 // also work with host space - right now symbolic requires host space so we
82 // do everything in device space if source was device, then deep_copy
83 typedef Kokkos::View<size_type*, host_device_type> host_size_type_array;
84 typedef Kokkos::View<ordinal_type*, host_device_type> host_ordinal_type_array;
85
87
88
95 TachoSolver(Teuchos::RCP<const Matrix> A,
96 Teuchos::RCP<Vector> X,
97 Teuchos::RCP<const Vector> B);
98
99
101 ~TachoSolver( );
102
104
106 std::string description() const override;
107
108private:
109
115 int preOrdering_impl();
116
117
125public: // made this public for CUDA parallel_for usage
127
128private:
129
136
148 int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
149 const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
150
151
155 bool matrixShapeOK_impl() const;
156
157
160 void setParameters_impl(
161 const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
162
163
170 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
171
172
181 bool loadA_impl(EPhase current_phase);
182
183
188 void describe_impl(Teuchos::FancyOStream &out,
189 const Teuchos::EVerbosityLevel verbLevel) const;
190
191
195 bool do_optimization() const;
196
197 // struct holds all data necessary to make a tacho factorization or solve call
198 mutable struct TACHOData {
199 typename Tacho::Solver<tacho_type, scheduler_type> solver;
200
201 // TODO: Implement the paramter options - confirm which we want and which have been implemented
202 int method;
203 int variant;
204 int small_problem_threshold_size;
205 int streams;
206 bool verbose;
207 int dofs_per_node;
208 bool diag_shift;
209 bool pivot_pert;
210 bool team_on_user_stream;
211 // int num_kokkos_threads;
212 // int max_num_superblocks;
213 } data_;
214
215 typedef typename Tacho::Solver<tacho_type, scheduler_type>::value_type_matrix
216 device_solve_array_t;
217
218 // used as an internal workspace - possibly we can store this better in TACHOData
219 mutable device_solve_array_t workspace_;
220
221 // x and b for solve - only allocated first time
222 mutable device_solve_array_t xValues_;
223 mutable device_solve_array_t bValues_;
224
225 // numeric is on device
226 device_value_type_array device_nzvals_view_;
227
228 // symbolic is done on host for Tacho so store these versions as well
229 host_size_type_array host_row_ptr_view_;
230 host_ordinal_type_array host_cols_view_;
231}; // End class Tacho
232
233
234// Specialize solver_traits struct for Tacho
235template <>
236struct solver_traits<TachoSolver> {
237#ifdef HAVE_TEUCHOS_COMPLEX
238 typedef Meta::make_list6<float,
239 double,
240 std::complex<float>,
241 std::complex<double>,
242 Kokkos::complex<float>,
243 Kokkos::complex<double>
244 >supported_scalars;
245#else
246 typedef Meta::make_list2<float,
247 double
248 >supported_scalars;
249#endif
250};
251
252template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
253struct solver_supports_matrix<TachoSolver,
254 KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
255 static const bool value = true;
256};
257
258} // end namespace Amesos2
259
260#endif // AMESOS2_TACHO_DECL_HPP
Provides access to interesting solver traits.
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers.
Definition Amesos2_SolverCore_decl.hpp:72
Amesos2 interface to the Tacho package.
Definition Amesos2_Tacho_decl.hpp:34
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition Amesos2_Tacho_def.hpp:213
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition Amesos2_Tacho_def.hpp:264
int numericFactorization_impl()
Tacho specific numeric factorization.
Definition Amesos2_Tacho_def.hpp:103
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Tacho specific solve.
Definition Amesos2_Tacho_def.hpp:134
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition Amesos2_Tacho_def.hpp:293
std::string description() const override
Returns a short description of this Solver.
Definition Amesos2_Tacho_def.hpp:52
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition Amesos2_Tacho_def.hpp:299
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Tacho.
Definition Amesos2_Tacho_def.hpp:68
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_Tacho_def.hpp:368
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition Amesos2_Tacho_def.hpp:61
static const char * name
Name of this solver interface.
Definition Amesos2_Tacho_decl.hpp:41
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