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 "Amesos2_SolverTraits.hpp"
48 #include "Amesos2_SolverCore.hpp"
49 #include "Amesos2_Tacho_FunctionMap.hpp"
50 
51 #include "Tacho.hpp"
52 #include "Tacho_Solver.hpp"
53 
54 namespace Amesos2 {
55 
63 template <class Matrix,
64  class Vector>
65 class TachoSolver : public SolverCore<Amesos2::TachoSolver, Matrix, Vector>
66 {
67  friend class SolverCore<Amesos2::TachoSolver,Matrix,Vector>; // Give our base access
68  // to our private
69  // implementation funcs
70 public:
71 
73  static const char* name; // declaration. Initialization outside.
74 
75  typedef TachoSolver<Matrix,Vector> type;
76  typedef SolverCore<Amesos2::TachoSolver,Matrix,Vector> super_type;
77 
78  // Since typedef's are not inheritted, go grab them
79  typedef typename super_type::scalar_type scalar_type;
80  typedef typename super_type::local_ordinal_type local_ordinal_type;
81  typedef typename super_type::global_size_type global_size_type;
82 
83  typedef TypeMap<Amesos2::TachoSolver,scalar_type> type_map;
84 
85  /*
86  * The Tacho interface will need two other typedef's, which are:
87  * - the tacho type that corresponds to scalar_type and
88  * - the corresponding type to use for magnitude
89  */
90  typedef typename type_map::type tacho_type;
91  typedef typename type_map::magnitude_type magnitude_type;
92 
93  typedef FunctionMap<Amesos2::TachoSolver,tacho_type> function_map;
94 
95  // TODO - Not sure yet best place for organizing these typedefs
96  typedef Tacho::ordinal_type ordinal_type;
97  typedef Tacho::size_type size_type;
98  typedef Kokkos::DefaultHostExecutionSpace HostSpaceType;
99  typedef Kokkos::View<size_type*,HostSpaceType> size_type_array;
100  typedef Kokkos::View<ordinal_type*,HostSpaceType> ordinal_type_array;
101  typedef Kokkos::View<tacho_type*, HostSpaceType> value_type_array;
102 
104 
105 
112  TachoSolver(Teuchos::RCP<const Matrix> A,
113  Teuchos::RCP<Vector> X,
114  Teuchos::RCP<const Vector> B);
115 
116 
118  ~TachoSolver( );
119 
121 
123  std::string description() const;
124 
125 private:
126 
132  int preOrdering_impl();
133 
134 
143 
144 
151 
163  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
164  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
165 
166 
170  bool matrixShapeOK_impl() const;
171 
172 
175  void setParameters_impl(
176  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
177 
178 
185  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
186 
187 
196  bool loadA_impl(EPhase current_phase);
197 
198 
202  bool do_optimization() const;
203 
204  // struct holds all data necessary to make a tacho factorization or solve call
205  mutable struct TACHOData {
206  typename Tacho::Solver<tacho_type,HostSpaceType> solver;
207 
208  // TODO: Implement the paramter options - confirm which we want and which have been implemented
209  // int num_kokkos_threads;
210  // int max_num_superblocks;
211  } data_;
212 
213  // The following Arrays are persisting storage arrays for A, X, and B
215  Teuchos::Array<tacho_type> nzvals_;
217  Teuchos::Array<ordinal_type> colind_;
219  Teuchos::Array<size_type> rowptr_;
220 
221  // TODO: Decide handling for CUDA - how to fail
222 #ifdef KOKKOS_ENABLE_OPENMP
223  typedef Kokkos::OpenMP DeviceSpaceType;
224 #else
225  typedef Kokkos::Serial DeviceSpaceType;
226 #endif
227  typedef typename Tacho::Solver<tacho_type,DeviceSpaceType>::value_type_matrix
228  solve_array_t;
229 
230  // used as an internal workspace - possibly we can store this better in TACHOData
231  mutable solve_array_t workspace_;
232 }; // End class Tacho
233 
234 
235 // Specialize solver_traits struct for Tacho
236 template <>
237 struct solver_traits<TachoSolver> {
238 #ifdef HAVE_TEUCHOS_COMPLEX
239  typedef Meta::make_list4<float,
240  double,
241  std::complex<float>,
242  std::complex<double>
243  >supported_scalars;
244 #else
245  typedef Meta::make_list2<float,
246  double
247  >supported_scalars;
248 #endif
249 };
250 
251 } // end namespace Amesos2
252 
253 #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:65
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Tacho.
Definition: Amesos2_Tacho_def.hpp:93
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
Teuchos::Array< size_type > rowptr_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Tacho_decl.hpp:219
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_Tacho_def.hpp:77
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:509
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:70
Teuchos::Array< ordinal_type > colind_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Tacho_decl.hpp:217
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Tacho_def.hpp:267
int numericFactorization_impl()
Tacho specific numeric factorization.
Definition: Amesos2_Tacho_def.hpp:168
Teuchos::Array< tacho_type > nzvals_
Stores the values of the nonzero entries for Tacho.
Definition: Amesos2_Tacho_decl.hpp:215
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Tacho_def.hpp:86
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Tacho_def.hpp:288
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:198
Provides access to interesting solver traits.
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Tacho_def.hpp:313
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition: Amesos2_Tacho_def.hpp:307