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 
122 
123 
130  Superludist(Teuchos::RCP<const Matrix> A,
131  Teuchos::RCP<Vector> X,
132  Teuchos::RCP<const Vector> B);
133 
134 
136  ~Superludist( );
137 
139 
140 private:
141 
148  int preOrdering_impl();
149 
150 
159 
160 
171 
172 
184  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
185  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
186 
187 
193  bool matrixShapeOK_impl() const;
194 
195 
217  /*
218  * The following options could be supported in the future:
219  *
220  * <li> \c "Equil" : { \c "YES" | \c "NO" } or, equivalently, { \c true | \c false }.
221  * Specifies whether the solver to equilibrate the matrix before solving.</li>
222  * <li> \c "IterRefine" : { \c "NO" | \c "SINGLE" | \c "DOUBLE" | \c "EXTRA"
223  * }. Specifies whether to perform iterative refinement, and in
224  * what precision to compute the residual. (Not currently supported)</li>
225  */
226  void setParameters_impl(
227  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
228 
229 
236  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
237 
238 
251  void get_default_grid_size(int nprocs, SLUD::int_t& nprow, SLUD::int_t& npcol) const;
252 
253 
268  bool loadA_impl(EPhase current_phase);
269 
270 
271  // struct holds all data necessary to make a superlu factorization or solve call
272  mutable struct SLUData {
273  SLUD::SuperMatrix A;
274  SLUD::SuperMatrix AC;
275  typename type_map::LUstruct_t LU;
276  SLUD::Glu_freeable_t glu_freeable;
277 
281  int domains;
282  MPI_Comm symb_comm;
283  SLUD::int_t *sizes, *fstVtxSep; // memory allocated by get_perm_c_parmetis
284  SLUD::Pslu_freeable_t pslu_freeable;
285 
286  SLUD::amesos2_superlu_dist_options_t options;
287  SLUD::amesos2_superlu_dist_mem_usage_t mem_usage;
288  SLUD::gridinfo_t grid;
289  MPI_Comm mat_comm;
290  typename type_map::LUstruct_t lu;
291  SLUD::SuperLUStat_t stat;
292  typename type_map::SOLVEstruct_t solve_struct;
293 
294  Teuchos::Array<magnitude_type> berr;
295  Teuchos::Array<magnitude_type> ferr;
296 
297  // Pick up data type specific ScalePermstruct_t
298  typename type_map::ScalePermstruct_t scale_perm; // R, C, perm_r, and perm_c found in here
299 
300  Teuchos::Array<magnitude_type> R, C; // equilibration scalings
301  Teuchos::Array<magnitude_type> R1, C1; // row-permutation scalings
302  Teuchos::Array<SLUD::int_t> perm_r, perm_c;
303 
304  SLUD::DiagScale_t equed;
305  bool rowequ, colequ;
306  magnitude_type rowcnd, colcnd, amax;
307  } data_;
308 
309  // The following Arrays are persisting storage arrays for A, X, and B
311  Teuchos::Array<slu_type> nzvals_;
313  Teuchos::Array<SLUD::int_t> colind_;
315  Teuchos::Array<SLUD::int_t> rowptr_;
317  mutable Teuchos::Array<slu_type> bvals_;
319  mutable Teuchos::Array<slu_type> xvals_;
320 
322  bool in_grid_;
323  bool same_symbolic_;
324  mutable bool same_solve_struct_; // may be modified in solve_impl, but still `logically const'
325 
327  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,
328  global_ordinal_type,
329  node_type> > superlu_rowmap_;
330 
331  bool is_contiguous_;
332 
333 }; // End class Superludist
334 
335 
336 // Specialize the solver_traits template for SuperLU_DIST
337 template <>
338 struct solver_traits<Superludist> {
339 #if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
340  typedef Meta::make_list3<double, std::complex<double>, SLUD::Z::doublecomplex> supported_scalars;
341 #else
342  typedef Meta::make_list1<double> supported_scalars;
343 #endif
344 };
345 
346 } // end namespace Amesos2
347 
348 #endif // AMESOS2_SUPERLUDIST_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 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:639
Teuchos::Array< slu_type > nzvals_
Stores the values of the nonzero entries for SuperLU_DIST.
Definition: Amesos2_Superludist_decl.hpp:311
Teuchos::Array< SLUD::int_t > rowptr_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Superludist_decl.hpp:315
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:509
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Superludist_def.hpp:713
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71
Teuchos::Array< SLUD::int_t > colind_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Superludist_decl.hpp:313
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Superludist_def.hpp:331
Provides a mechanism to map function calls to the correct Solver function based on the scalar type of...
Teuchos::Array< slu_type > bvals_
1D store for B values
Definition: Amesos2_Superludist_decl.hpp:317
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:630
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:329
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using SuperLU_DIST.
Definition: Amesos2_Superludist_def.hpp:386
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:783
bool in_grid_
true if this processor is in SuperLU_DISTS&#39;s 2D process grid
Definition: Amesos2_Superludist_decl.hpp:322
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:492
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal solver structures.
Definition: Amesos2_Superludist_def.hpp:808
Teuchos::Array< slu_type > xvals_
1D store for X values
Definition: Amesos2_Superludist_decl.hpp:319
int numericFactorization_impl()
SuperLU_DIST specific numeric factorization.
Definition: Amesos2_Superludist_def.hpp:418