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 
49 #include "Amesos2_SolverTraits.hpp"
50 #include "Amesos2_SolverCore.hpp"
51 #include "Amesos2_Tacho_FunctionMap.hpp"
52 
53 #include "Tacho.hpp"
54 #include "Tacho_Solver.hpp"
55 
56 namespace Amesos2 {
57 
65 template <class Matrix,
66  class Vector>
67 class 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
72 public:
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 Kokkos::TaskScheduler<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 
142 private:
143 
149  int preOrdering_impl();
150 
151 
159 public: // made this public for CUDA parallel_for usage
161 
162 private:
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 num_kokkos_threads;
229  // int max_num_superblocks;
230  } data_;
231 
232  typedef typename Tacho::Solver<tacho_type, scheduler_type>::value_type_matrix
233  device_solve_array_t;
234 
235  // used as an internal workspace - possibly we can store this better in TACHOData
236  mutable device_solve_array_t workspace_;
237 
238  // x and b for solve - only allocated first time
239  mutable device_solve_array_t xValues_;
240  mutable device_solve_array_t bValues_;
241 
242  // numeric is on device
243  device_value_type_array device_nzvals_view_;
244 
245  // symbolic is done on host for Tacho so store these versions as well
246  host_size_type_array host_row_ptr_view_;
247  host_ordinal_type_array host_cols_view_;
248 }; // End class Tacho
249 
250 
251 // Specialize solver_traits struct for Tacho
252 template <>
253 struct solver_traits<TachoSolver> {
254 #ifdef HAVE_TEUCHOS_COMPLEX
255  typedef Meta::make_list6<float,
256  double,
257  std::complex<float>,
258  std::complex<double>,
259  Kokkos::complex<float>,
260  Kokkos::complex<double>
261  >supported_scalars;
262 #else
263  typedef Meta::make_list2<float,
264  double
265  >supported_scalars;
266 #endif
267 };
268 
269 template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
270 struct solver_supports_matrix<TachoSolver,
271  KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
272  static const bool value = true;
273 };
274 
275 } // end namespace Amesos2
276 
277 #endif // AMESOS2_TACHO_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
Amesos2 interface to the Tacho package.
Definition: Amesos2_Tacho_decl.hpp:67
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Tacho.
Definition: Amesos2_Tacho_def.hpp:90
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_Tacho_def.hpp:74
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:509
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Tacho_def.hpp:204
int numericFactorization_impl()
Tacho specific numeric factorization.
Definition: Amesos2_Tacho_def.hpp:111
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Tacho_def.hpp:83
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Tacho_def.hpp:225
Interface to Amesos2 solver objects.
Definition: Amesos2_Solver_decl.hpp:78
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:76
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:125
Provides access to interesting solver traits.
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Tacho_def.hpp:250
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition: Amesos2_Tacho_def.hpp:244