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::TaskScheduler<HostSpaceType> SchedulerType;
100  typedef Kokkos::View<size_type*,HostSpaceType> size_type_array;
101  typedef Kokkos::View<ordinal_type*,HostSpaceType> ordinal_type_array;
102  typedef Kokkos::View<tacho_type*, HostSpaceType> value_type_array;
103 
105 
106 
113  TachoSolver(Teuchos::RCP<const Matrix> A,
114  Teuchos::RCP<Vector> X,
115  Teuchos::RCP<const Vector> B);
116 
117 
119  ~TachoSolver( );
120 
122 
124  std::string description() const;
125 
126 private:
127 
133  int preOrdering_impl();
134 
135 
144 
145 
152 
164  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
165  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
166 
167 
171  bool matrixShapeOK_impl() const;
172 
173 
176  void setParameters_impl(
177  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
178 
179 
186  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
187 
188 
197  bool loadA_impl(EPhase current_phase);
198 
199 
203  bool do_optimization() const;
204 
205  // struct holds all data necessary to make a tacho factorization or solve call
206  mutable struct TACHOData {
207  typename Tacho::Solver<tacho_type,SchedulerType> solver;
208 
209  // TODO: Implement the paramter options - confirm which we want and which have been implemented
210  // int num_kokkos_threads;
211  // int max_num_superblocks;
212  } data_;
213 
214  // The following Arrays are persisting storage arrays for A, X, and B
216  Teuchos::Array<tacho_type> nzvals_;
218  Teuchos::Array<ordinal_type> colind_;
220  Teuchos::Array<size_type> rowptr_;
221 
222  // TODO: Decide handling for CUDA - how to fail
223 #ifdef KOKKOS_ENABLE_OPENMP
224  typedef Kokkos::OpenMP DeviceSpaceType;
225 #else
226  typedef Kokkos::Serial DeviceSpaceType;
227 #endif
228  typedef typename Tacho::Solver<tacho_type,SchedulerType>::value_type_matrix
229  solve_array_t;
230 
231  // used as an internal workspace - possibly we can store this better in TACHOData
232  mutable solve_array_t workspace_;
233 }; // End class Tacho
234 
235 
236 // Specialize solver_traits struct for Tacho
237 template <>
238 struct solver_traits<TachoSolver> {
239 #ifdef HAVE_TEUCHOS_COMPLEX
240  typedef Meta::make_list4<float,
241  double,
242  std::complex<float>,
243  std::complex<double>
244  >supported_scalars;
245 #else
246  typedef Meta::make_list2<float,
247  double
248  >supported_scalars;
249 #endif
250 };
251 
252 } // end namespace Amesos2
253 
254 #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:220
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:218
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:216
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