Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Tacho_decl.hpp
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 Sivasankaran Rajamanickam (srajama@sandia.gov)
39//
40// ***********************************************************************
41//
42// @HEADER
43
44#ifndef AMESOS2_TACHO_DECL_HPP
45#define AMESOS2_TACHO_DECL_HPP
46
47#include <Kokkos_Core.hpp>
48
50#include "Amesos2_SolverCore.hpp"
51#include "Amesos2_Tacho_FunctionMap.hpp"
52
53#include "Tacho.hpp"
54#include "Tacho_Solver.hpp"
55
56namespace Amesos2 {
57
65template <class Matrix,
66 class Vector>
67class TachoSolver : public SolverCore<Amesos2::TachoSolver, Matrix, Vector>
68{
69 friend class SolverCore<Amesos2::TachoSolver,Matrix,Vector>; // Give our base access
70 // to our private
71 // implementation funcs
72public:
73
75 static const char* name; // declaration. Initialization outside.
76
77 typedef TachoSolver<Matrix,Vector> type;
78 typedef SolverCore<Amesos2::TachoSolver,Matrix,Vector> super_type;
79
80 // Since typedef's are not inheritted, go grab them
81 typedef typename super_type::scalar_type scalar_type;
82 typedef typename super_type::local_ordinal_type local_ordinal_type;
83 typedef typename super_type::global_size_type global_size_type;
84
85 typedef TypeMap<Amesos2::TachoSolver,scalar_type> type_map;
86
87 /*
88 * The Tacho interface will need two other typedef's, which are:
89 * - the tacho type that corresponds to scalar_type and
90 * - the corresponding type to use for magnitude
91 */
92 typedef typename type_map::type tacho_type;
93 typedef typename type_map::magnitude_type magnitude_type;
94
95 typedef FunctionMap<Amesos2::TachoSolver,tacho_type> function_map;
96
97 // TODO - Not sure yet best place for organizing these typedefs
98 typedef Tacho::ordinal_type ordinal_type;
99 typedef Tacho::size_type size_type;
100
101 typedef Kokkos::DefaultExecutionSpace exec_space_type;
102 typedef Kokkos::DefaultHostExecutionSpace host_exec_space_type;
103
104 typedef typename
105 Tacho::UseThisDevice<exec_space_type>::device_type device_type;
106 typedef typename
107 Tacho::UseThisDevice<host_exec_space_type>::device_type host_device_type;
108
109 typedef Tacho::DummyTaskScheduler<exec_space_type> scheduler_type;
110
111 typedef Kokkos::View<size_type*, device_type> device_size_type_array;
112 typedef Kokkos::View<ordinal_type*, device_type> device_ordinal_type_array;
113 typedef Kokkos::View<tacho_type*, device_type> device_value_type_array;
114
115 // also work with host space - right now symbolic requires host space so we
116 // do everything in device space if source was device, then deep_copy
117 typedef Kokkos::View<size_type*, host_device_type> host_size_type_array;
118 typedef Kokkos::View<ordinal_type*, host_device_type> host_ordinal_type_array;
119
121
122
129 TachoSolver(Teuchos::RCP<const Matrix> A,
130 Teuchos::RCP<Vector> X,
131 Teuchos::RCP<const Vector> B);
132
133
135 ~TachoSolver( );
136
138
140 std::string description() const;
141
142private:
143
149 int preOrdering_impl();
150
151
159public: // made this public for CUDA parallel_for usage
161
162private:
163
170
182 int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
183 const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
184
185
189 bool matrixShapeOK_impl() const;
190
191
194 void setParameters_impl(
195 const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
196
197
204 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
205
206
215 bool loadA_impl(EPhase current_phase);
216
217
221 bool do_optimization() const;
222
223 // struct holds all data necessary to make a tacho factorization or solve call
224 mutable struct TACHOData {
225 typename Tacho::Solver<tacho_type, scheduler_type> solver;
226
227 // TODO: Implement the paramter options - confirm which we want and which have been implemented
228 int method;
229 int variant;
230 // int num_kokkos_threads;
231 // int max_num_superblocks;
232 } data_;
233
234 typedef typename Tacho::Solver<tacho_type, scheduler_type>::value_type_matrix
235 device_solve_array_t;
236
237 // used as an internal workspace - possibly we can store this better in TACHOData
238 mutable device_solve_array_t workspace_;
239
240 // x and b for solve - only allocated first time
241 mutable device_solve_array_t xValues_;
242 mutable device_solve_array_t bValues_;
243
244 // numeric is on device
245 device_value_type_array device_nzvals_view_;
246
247 // symbolic is done on host for Tacho so store these versions as well
248 host_size_type_array host_row_ptr_view_;
249 host_ordinal_type_array host_cols_view_;
250}; // End class Tacho
251
252
253// Specialize solver_traits struct for Tacho
254template <>
255struct solver_traits<TachoSolver> {
256#ifdef HAVE_TEUCHOS_COMPLEX
257 typedef Meta::make_list6<float,
258 double,
259 std::complex<float>,
260 std::complex<double>,
261 Kokkos::complex<float>,
262 Kokkos::complex<double>
263 >supported_scalars;
264#else
265 typedef Meta::make_list2<float,
266 double
267 >supported_scalars;
268#endif
269};
270
271template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
272struct solver_supports_matrix<TachoSolver,
273 KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
274 static const bool value = true;
275};
276
277} // end namespace Amesos2
278
279#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:106
Amesos2 interface to the Tacho package.
Definition: Amesos2_Tacho_decl.hpp:68
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Tacho_def.hpp:222
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Tacho_def.hpp:258
int numericFactorization_impl()
Tacho specific numeric factorization.
Definition: Amesos2_Tacho_def.hpp:124
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:142
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition: Amesos2_Tacho_def.hpp:280
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_Tacho_def.hpp:79
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Tacho_def.hpp:286
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Tacho.
Definition: Amesos2_Tacho_def.hpp:95
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Tacho_def.hpp:88
static const char * name
Name of this solver interface.
Definition: Amesos2_Tacho_decl.hpp:75
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