Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Superludist_decl.hpp
Go to the documentation of this file.
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 Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
53 #ifndef AMESOS2_SUPERLUDIST_DECL_HPP
54 #define AMESOS2_SUPERLUDIST_DECL_HPP
55 
56 #include "Amesos2_SolverTraits.hpp"
57 #include "Amesos2_SolverCore.hpp"
59 
60 namespace Amesos2 {
61 
62 
88 template <class Matrix,
89  class Vector>
90 class Superludist : public SolverCore<Amesos2::Superludist, Matrix, Vector>
91 {
92  friend class SolverCore<Amesos2::Superludist,Matrix,Vector>; // Give our base access
93  // to our private
94  // implementation funcs
95 public:
96 
98  static const char* name; // declaration. Initialization outside.
99 
100  typedef Superludist<Matrix,Vector> type;
101  typedef SolverCore<Amesos2::Superludist,Matrix,Vector> super_type;
102 
103  typedef Matrix matrix_type;
104  typedef Vector vector_type;
105 
106  // Since typedef's are not inheritted, go grab them
107  typedef typename super_type::scalar_type scalar_type;
108  typedef typename super_type::local_ordinal_type local_ordinal_type;
109  typedef typename super_type::global_ordinal_type global_ordinal_type;
110  typedef typename super_type::global_size_type global_size_type;
111  typedef typename super_type::node_type node_type;
112 
113  typedef TypeMap<Amesos2::Superludist,scalar_type> type_map;
114 
115  typedef typename type_map::type slu_type;
116  typedef typename type_map::magnitude_type magnitude_type;
117 
118  typedef FunctionMap<Amesos2::Superludist,slu_type> function_map;
119 
120  typedef Kokkos::DefaultHostExecutionSpace HostExecSpaceType;
121  typedef Kokkos::View<SLUD::int_t*, HostExecSpaceType> host_size_type_array;
122  typedef Kokkos::View<SLUD::int_t*, HostExecSpaceType> host_ordinal_type_array;
123  typedef Kokkos::View<slu_type*, HostExecSpaceType> host_value_type_array;
124 
126 
127 
134  Superludist(Teuchos::RCP<const Matrix> A,
135  Teuchos::RCP<Vector> X,
136  Teuchos::RCP<const Vector> B);
137 
138 
140  ~Superludist( );
141 
143 
144 private:
145 
152  void computeRowPermutationLargeDiagMC64(SLUD::SuperMatrix& GA);
153 
160  int preOrdering_impl();
161 
162 
171 
172 
183 
184 
196  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
197  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
198 
199 
205  bool matrixShapeOK_impl() const;
206 
207 
229  /*
230  * The following options could be supported in the future:
231  *
232  * <li> \c "Equil" : { \c "YES" | \c "NO" } or, equivalently, { \c true | \c false }.
233  * Specifies whether the solver to equilibrate the matrix before solving.</li>
234  * <li> \c "IterRefine" : { \c "NO" | \c "SINGLE" | \c "DOUBLE" | \c "EXTRA"
235  * }. Specifies whether to perform iterative refinement, and in
236  * what precision to compute the residual. (Not currently supported)</li>
237  */
238  void setParameters_impl(
239  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
240 
241 
248  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
249 
250 
263  void get_default_grid_size(int nprocs, SLUD::int_t& nprow, SLUD::int_t& npcol) const;
264 
265 
280  bool loadA_impl(EPhase current_phase);
281 
282 
283  // struct holds all data necessary to make a superlu factorization or solve call
284  mutable struct SLUData {
285  SLUD::SuperMatrix A;
286  SLUD::SuperMatrix AC;
287  typename type_map::LUstruct_t LU;
288  SLUD::Glu_freeable_t glu_freeable;
289 
293  int domains;
294  MPI_Comm symb_comm;
295  SLUD::int_t *sizes, *fstVtxSep; // memory allocated by get_perm_c_parmetis
296  SLUD::Pslu_freeable_t pslu_freeable;
297 
298  SLUD::amesos2_superlu_dist_options_t options;
299  SLUD::amesos2_superlu_dist_mem_usage_t mem_usage;
300  SLUD::gridinfo_t grid;
301  MPI_Comm mat_comm;
302  typename type_map::LUstruct_t lu;
303  SLUD::SuperLUStat_t stat;
304  typename type_map::SOLVEstruct_t solve_struct;
305 
306  Teuchos::Array<magnitude_type> berr;
307  Teuchos::Array<magnitude_type> ferr;
308 
309  // Pick up data type specific ScalePermstruct_t
310  typename type_map::ScalePermstruct_t scale_perm; // R, C, perm_r, and perm_c found in here
311 
312  Teuchos::Array<magnitude_type> R, C; // equilibration scalings
313  Teuchos::Array<magnitude_type> R1, C1; // row-permutation scalings
314  Teuchos::Array<SLUD::int_t> perm_r, perm_c;
315 
316  SLUD::DiagScale_t equed;
317  bool rowequ, colequ;
318  magnitude_type rowcnd, colcnd, amax;
319  int largediag_mc64_job; // job id for LargeDiag_MC64 row permutation
320  } data_;
321 
322  // The following Arrays are persisting storage arrays for A, X, and B
324  host_value_type_array nzvals_view_;
326  host_ordinal_type_array colind_view_;
328  host_size_type_array rowptr_view_;
330  mutable Teuchos::Array<slu_type> bvals_;
332  mutable Teuchos::Array<slu_type> xvals_;
333 
335  bool in_grid_;
336  bool same_symbolic_;
337  bool force_symbfact_;
338  mutable bool same_solve_struct_; // may be modified in solve_impl, but still `logically const'
339 
341  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,
342  global_ordinal_type,
343  node_type> > superlu_rowmap_;
344 
345  bool is_contiguous_;
346 
347 }; // End class Superludist
348 
349 
350 // Specialize the solver_traits template for SuperLU_DIST
351 template <>
352 struct solver_traits<Superludist> {
353 #if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
354  typedef Meta::make_list3<double, std::complex<double>, SLUD::Z::doublecomplex> supported_scalars;
355 #else
356  typedef Meta::make_list1<double> supported_scalars;
357 #endif
358 };
359 
360 } // end namespace Amesos2
361 
362 #endif // AMESOS2_SUPERLUDIST_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
void computeRowPermutationLargeDiagMC64(SLUD::SuperMatrix &GA)
Compute the row permutation for option LargeDiag-MC64.
Definition: Amesos2_Superludist_def.hpp:337
Amesos2 interface to the distributed memory version of SuperLU.
Definition: Amesos2_Superludist_decl.hpp:90
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_Superludist_def.hpp:823
host_value_type_array nzvals_view_
Stores the values of the nonzero entries for SuperLU_DIST.
Definition: Amesos2_Superludist_decl.hpp:324
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Superludist_def.hpp:900
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Superludist_def.hpp:392
host_size_type_array rowptr_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Superludist_decl.hpp:328
Provides a mechanism to map function calls to the correct Solver function based on the scalar type of...
std::string name() const override
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:759
Teuchos::Array< slu_type > bvals_
1D store for B values
Definition: Amesos2_Superludist_decl.hpp:330
Interface to Amesos2 solver objects.
Definition: Amesos2_Solver_decl.hpp:78
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Superludist_def.hpp:814
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:76
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > superlu_rowmap_
Maps rows of the matrix to processors in the SuperLU_DIST processor grid.
Definition: Amesos2_Superludist_decl.hpp:343
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using SuperLU_DIST.
Definition: Amesos2_Superludist_def.hpp:448
Provides access to interesting solver traits.
void get_default_grid_size(int nprocs, SLUD::int_t &nprow, SLUD::int_t &npcol) const
Definition: Amesos2_Superludist_def.hpp:986
bool in_grid_
true if this processor is in SuperLU_DISTS&#39;s 2D process grid
Definition: Amesos2_Superludist_decl.hpp:335
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
SuperLU_DIST specific solve.
Definition: Amesos2_Superludist_def.hpp:648
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal solver structures.
Definition: Amesos2_Superludist_def.hpp:1011
host_ordinal_type_array colind_view_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Superludist_decl.hpp:326
Teuchos::Array< slu_type > xvals_
1D store for X values
Definition: Amesos2_Superludist_decl.hpp:332
int numericFactorization_impl()
SuperLU_DIST specific numeric factorization.
Definition: Amesos2_Superludist_def.hpp:497