Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Superlu_def.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_SUPERLU_DEF_HPP
54 #define AMESOS2_SUPERLU_DEF_HPP
55 
56 #include <Teuchos_Tuple.hpp>
57 #include <Teuchos_ParameterList.hpp>
58 #include <Teuchos_StandardParameterEntryValidators.hpp>
59 
61 #include "Amesos2_Superlu_decl.hpp"
62 
63 namespace Amesos2 {
64 
65 
66 template <class Matrix, class Vector>
68  Teuchos::RCP<const Matrix> A,
69  Teuchos::RCP<Vector> X,
70  Teuchos::RCP<const Vector> B )
71  : SolverCore<Amesos2::Superlu,Matrix,Vector>(A, X, B)
72  , nzvals_() // initialize to empty arrays
73  , rowind_()
74  , colptr_()
75 {
76  // ilu_set_default_options is called later in set parameter list if required.
77  // This is not the ideal way, but the other option to always call
78  // ilu_set_default_options here and assuming it won't have any side effect
79  // in the TPL is more dangerous. It is not a good idea to rely on external
80  // libraries' internal "features".
81  SLU::set_default_options(&(data_.options));
82  // Override some default options
83  data_.options.PrintStat = SLU::NO;
84 
85  SLU::StatInit(&(data_.stat));
86 
87  data_.perm_r.resize(this->globalNumRows_);
88  data_.perm_c.resize(this->globalNumCols_);
89  data_.etree.resize(this->globalNumCols_);
90  data_.R.resize(this->globalNumRows_);
91  data_.C.resize(this->globalNumCols_);
92 
93  data_.relax = SLU::sp_ienv(2); // Query optimal relax param from superlu
94  data_.panel_size = SLU::sp_ienv(1); // Query optimal panel size
95 
96  data_.equed = 'N'; // No equilibration
97  data_.A.Store = NULL;
98  data_.L.Store = NULL;
99  data_.U.Store = NULL;
100  data_.X.Store = NULL;
101  data_.B.Store = NULL;
102 
103  ILU_Flag_=false; // default: turn off ILU
104 }
105 
106 
107 template <class Matrix, class Vector>
109 {
110  /* Free Superlu data_types
111  * - Matrices
112  * - Vectors
113  * - Stat object
114  */
115  SLU::StatFree( &(data_.stat) ) ;
116 
117  // Storage is initialized in numericFactorization_impl()
118  if ( data_.A.Store != NULL ){
119  SLU::Destroy_SuperMatrix_Store( &(data_.A) );
120  }
121 
122  // only root allocated these SuperMatrices.
123  if ( data_.L.Store != NULL ){ // will only be true for this->root_
124  SLU::Destroy_SuperNode_Matrix( &(data_.L) );
125  SLU::Destroy_CompCol_Matrix( &(data_.U) );
126  }
127 }
128 
129 template <class Matrix, class Vector>
130 std::string
132 {
133  std::ostringstream oss;
134  oss << "SuperLU solver interface";
135  if (ILU_Flag_) {
136  oss << ", \"ILUTP\" : {";
137  oss << "drop tol = " << data_.options.ILU_DropTol;
138  oss << ", fill factor = " << data_.options.ILU_FillFactor;
139  oss << ", fill tol = " << data_.options.ILU_FillTol;
140  switch(data_.options.ILU_MILU) {
141  case SLU::SMILU_1 :
142  oss << ", MILU 1";
143  break;
144  case SLU::SMILU_2 :
145  oss << ", MILU 2";
146  break;
147  case SLU::SMILU_3 :
148  oss << ", MILU 3";
149  break;
150  case SLU::SILU :
151  default:
152  oss << ", regular ILU";
153  }
154  switch(data_.options.ILU_Norm) {
155  case SLU::ONE_NORM :
156  oss << ", 1-norm";
157  break;
158  case SLU::TWO_NORM :
159  oss << ", 2-norm";
160  break;
161  case SLU::INF_NORM :
162  default:
163  oss << ", infinity-norm";
164  }
165  oss << "}";
166  } else {
167  oss << ", direct solve";
168  }
169  return oss.str();
170  /*
171 
172  // ILU parameters
173  if( parameterList->isParameter("RowPerm") ){
174  RCP<const ParameterEntryValidator> rowperm_validator = valid_params->getEntry("RowPerm").validator();
175  parameterList->getEntry("RowPerm").setValidator(rowperm_validator);
176  data_.options.RowPerm = getIntegralValue<SLU::rowperm_t>(*parameterList, "RowPerm");
177  }
178 
179 
180  */
181 }
182 
183 template<class Matrix, class Vector>
184 int
186 {
187  /*
188  * Get column permutation vector perm_c[], according to permc_spec:
189  * permc_spec = NATURAL: natural ordering
190  * permc_spec = MMD_AT_PLUS_A: minimum degree on structure of A'+A
191  * permc_spec = MMD_ATA: minimum degree on structure of A'*A
192  * permc_spec = COLAMD: approximate minimum degree column ordering
193  * permc_spec = MY_PERMC: the ordering already supplied in perm_c[]
194  */
195  int permc_spec = data_.options.ColPerm;
196  if ( permc_spec != SLU::MY_PERMC && this->root_ ){
197 #ifdef HAVE_AMESOS2_TIMERS
198  Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
199 #endif
200 
201  SLU::get_perm_c(permc_spec, &(data_.A), data_.perm_c.getRawPtr());
202  }
203 
204  return(0);
205 }
206 
207 
208 template <class Matrix, class Vector>
209 int
211 {
212  /*
213  * SuperLU performs symbolic factorization and numeric factorization
214  * together, but does leave some options for reusing symbolic
215  * structures that have been created on previous factorizations. If
216  * our Amesos2 user calls this function, that is an indication that
217  * the symbolic structure of the matrix is no longer valid, and
218  * SuperLU should do the factorization from scratch.
219  *
220  * This can be accomplished by setting the options.Fact flag to
221  * DOFACT, as well as setting our own internal flag to false.
222  */
223  same_symbolic_ = false;
224  data_.options.Fact = SLU::DOFACT;
225 
226  return(0);
227 }
228 
229 
230 template <class Matrix, class Vector>
231 int
233 {
234  using Teuchos::as;
235 
236  // Cleanup old L and U matrices if we are not reusing a symbolic
237  // factorization. Stores and other data will be allocated in gstrf.
238  // Only rank 0 has valid pointers
239  if ( !same_symbolic_ && data_.L.Store != NULL ){
240  SLU::Destroy_SuperNode_Matrix( &(data_.L) );
241  SLU::Destroy_CompCol_Matrix( &(data_.U) );
242  data_.L.Store = NULL;
243  data_.U.Store = NULL;
244  }
245 
246  if( same_symbolic_ ) data_.options.Fact = SLU::SamePattern_SameRowPerm;
247 
248  int info = 0;
249  if ( this->root_ ){
250 
251 #ifdef HAVE_AMESOS2_DEBUG
252  TEUCHOS_TEST_FOR_EXCEPTION( data_.A.ncol != as<int>(this->globalNumCols_),
253  std::runtime_error,
254  "Error in converting to SuperLU SuperMatrix: wrong number of global columns." );
255  TEUCHOS_TEST_FOR_EXCEPTION( data_.A.nrow != as<int>(this->globalNumRows_),
256  std::runtime_error,
257  "Error in converting to SuperLU SuperMatrix: wrong number of global rows." );
258 #endif
259 
260  if( data_.options.Equil == SLU::YES ){
261  magnitude_type rowcnd, colcnd, amax;
262  int info2 = 0;
263 
264  // calculate row and column scalings
265  function_map::gsequ(&(data_.A), data_.R.getRawPtr(),
266  data_.C.getRawPtr(), &rowcnd, &colcnd,
267  &amax, &info2);
268  TEUCHOS_TEST_FOR_EXCEPTION
269  (info2 < 0, std::runtime_error,
270  "SuperLU's gsequ function returned with status " << info2 << " < 0."
271  " This means that argument " << (-info2) << " given to the function"
272  " had an illegal value.");
273  if (info2 > 0) {
274  if (info2 <= data_.A.nrow) {
275  TEUCHOS_TEST_FOR_EXCEPTION
276  (true, std::runtime_error, "SuperLU's gsequ function returned with "
277  "info = " << info2 << " > 0, and info <= A.nrow = " << data_.A.nrow
278  << ". This means that row " << info2 << " of A is exactly zero.");
279  }
280  else if (info2 > data_.A.ncol) {
281  TEUCHOS_TEST_FOR_EXCEPTION
282  (true, std::runtime_error, "SuperLU's gsequ function returned with "
283  "info = " << info2 << " > 0, and info > A.ncol = " << data_.A.ncol
284  << ". This means that column " << (info2 - data_.A.nrow) << " of "
285  "A is exactly zero.");
286  }
287  else {
288  TEUCHOS_TEST_FOR_EXCEPTION
289  (true, std::runtime_error, "SuperLU's gsequ function returned "
290  "with info = " << info2 << " > 0, but its value is not in the "
291  "range permitted by the documentation. This should never happen "
292  "(it appears to be SuperLU's fault).");
293  }
294  }
295 
296  // apply row and column scalings if necessary
297  function_map::laqgs(&(data_.A), data_.R.getRawPtr(),
298  data_.C.getRawPtr(), rowcnd, colcnd,
299  amax, &(data_.equed));
300 
301  // // check what types of equilibration was actually done
302  // data_.rowequ = (data_.equed == 'R') || (data_.equed == 'B');
303  // data_.colequ = (data_.equed == 'C') || (data_.equed == 'B');
304  }
305 
306  // Apply the column permutation computed in preOrdering. Place the
307  // column-permuted matrix in AC
308  SLU::sp_preorder(&(data_.options), &(data_.A), data_.perm_c.getRawPtr(),
309  data_.etree.getRawPtr(), &(data_.AC));
310 
311  { // Do factorization
312 #ifdef HAVE_AMESOS2_TIMERS
313  Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
314 #endif
315 
316 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
317  std::cout << "Superlu:: Before numeric factorization" << std::endl;
318  std::cout << "nzvals_ : " << nzvals_.toString() << std::endl;
319  std::cout << "rowind_ : " << rowind_.toString() << std::endl;
320  std::cout << "colptr_ : " << colptr_.toString() << std::endl;
321 #endif
322 
323  if(ILU_Flag_==false) {
324  function_map::gstrf(&(data_.options), &(data_.AC),
325  data_.relax, data_.panel_size, data_.etree.getRawPtr(),
326  NULL, 0, data_.perm_c.getRawPtr(), data_.perm_r.getRawPtr(),
327  &(data_.L), &(data_.U), &(data_.stat), &info);
328  }
329  else {
330  function_map::gsitrf(&(data_.options), &(data_.AC),
331  data_.relax, data_.panel_size, data_.etree.getRawPtr(),
332  NULL, 0, data_.perm_c.getRawPtr(), data_.perm_r.getRawPtr(),
333  &(data_.L), &(data_.U), &(data_.stat), &info);
334  }
335 
336  }
337  // Cleanup. AC data will be alloc'd again for next factorization (if at all)
338  SLU::Destroy_CompCol_Permuted( &(data_.AC) );
339 
340  // Set the number of non-zero values in the L and U factors
341  this->setNnzLU( as<size_t>(((SLU::SCformat*)data_.L.Store)->nnz +
342  ((SLU::NCformat*)data_.U.Store)->nnz) );
343  }
344 
345  /* All processes should have the same error code */
346  Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
347 
348  global_size_type info_st = as<global_size_type>(info);
349  TEUCHOS_TEST_FOR_EXCEPTION( (info_st > 0) && (info_st <= this->globalNumCols_),
350  std::runtime_error,
351  "Factorization complete, but matrix is singular. Division by zero eminent");
352  TEUCHOS_TEST_FOR_EXCEPTION( (info_st > 0) && (info_st > this->globalNumCols_),
353  std::runtime_error,
354  "Memory allocation failure in Superlu factorization");
355 
356  data_.options.Fact = SLU::FACTORED;
357  same_symbolic_ = true;
358 
359  return(info);
360 }
361 
362 
363 template <class Matrix, class Vector>
364 int
366  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const
367 {
368  using Teuchos::as;
369 
370  const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
371  const size_t nrhs = X->getGlobalNumVectors();
372 
373  const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
374  Teuchos::Array<slu_type> xValues(val_store_size);
375  Teuchos::Array<slu_type> bValues(val_store_size);
376 
377  { // Get values from RHS B
378 #ifdef HAVE_AMESOS2_TIMERS
379  Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
380  Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
381 #endif
383  slu_type>::do_get(B, bValues(),
384  as<size_t>(ld_rhs),
385  ROOTED, this->rowIndexBase_);
386  }
387 
388  int ierr = 0; // returned error code
389 
390  magnitude_type rpg, rcond;
391  if ( this->root_ ) {
392  data_.ferr.resize(nrhs);
393  data_.berr.resize(nrhs);
394 
395  {
396 #ifdef HAVE_AMESOS2_TIMERS
397  Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
398 #endif
399  SLU::Dtype_t dtype = type_map::dtype;
400  int i_ld_rhs = as<int>(ld_rhs);
401  function_map::create_Dense_Matrix(&(data_.B), i_ld_rhs, as<int>(nrhs),
402  bValues.getRawPtr(), i_ld_rhs,
403  SLU::SLU_DN, dtype, SLU::SLU_GE);
404  function_map::create_Dense_Matrix(&(data_.X), i_ld_rhs, as<int>(nrhs),
405  xValues.getRawPtr(), i_ld_rhs,
406  SLU::SLU_DN, dtype, SLU::SLU_GE);
407  }
408 
409  // Note: the values of B and X (after solution) are adjusted
410  // appropriately within gssvx for row and column scalings.
411 
412  { // Do solve!
413 #ifdef HAVE_AMESOS2_TIMERS
414  Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
415 #endif
416 
417  if(ILU_Flag_==false) {
418  function_map::gssvx(&(data_.options), &(data_.A),
419  data_.perm_c.getRawPtr(), data_.perm_r.getRawPtr(),
420  data_.etree.getRawPtr(), &(data_.equed), data_.R.getRawPtr(),
421  data_.C.getRawPtr(), &(data_.L), &(data_.U), NULL, 0, &(data_.B),
422  &(data_.X), &rpg, &rcond, data_.ferr.getRawPtr(),
423  data_.berr.getRawPtr(), &(data_.mem_usage), &(data_.stat), &ierr);
424  }
425  else {
426  function_map::gsisx(&(data_.options), &(data_.A),
427  data_.perm_c.getRawPtr(), data_.perm_r.getRawPtr(),
428  data_.etree.getRawPtr(), &(data_.equed), data_.R.getRawPtr(),
429  data_.C.getRawPtr(), &(data_.L), &(data_.U), NULL, 0, &(data_.B),
430  &(data_.X), &rpg, &rcond, &(data_.mem_usage), &(data_.stat), &ierr);
431  }
432 
433  }
434 
435  // Cleanup X and B stores
436  SLU::Destroy_SuperMatrix_Store( &(data_.X) );
437  SLU::Destroy_SuperMatrix_Store( &(data_.B) );
438  data_.X.Store = NULL;
439  data_.B.Store = NULL;
440  }
441 
442  /* All processes should have the same error code */
443  Teuchos::broadcast(*(this->getComm()), 0, &ierr);
444 
445  global_size_type ierr_st = as<global_size_type>(ierr);
446  TEUCHOS_TEST_FOR_EXCEPTION( ierr < 0,
447  std::invalid_argument,
448  "Argument " << -ierr << " to SuperLU xgssvx had illegal value" );
449  TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0 && ierr_st <= this->globalNumCols_,
450  std::runtime_error,
451  "Factorization complete, but U is exactly singular" );
452  TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0 && ierr_st > this->globalNumCols_ + 1,
453  std::runtime_error,
454  "SuperLU allocated " << ierr - this->globalNumCols_ << " bytes of "
455  "memory before allocation failure occured." );
456 
457  /* Update X's global values */
458  {
459 #ifdef HAVE_AMESOS2_TIMERS
460  Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
461 #endif
462 
464  MultiVecAdapter<Vector>,slu_type>::do_put(X, xValues(),
465  as<size_t>(ld_rhs),
466  ROOTED, this->rowIndexBase_);
467  }
468 
469 
470  return(ierr);
471 }
472 
473 
474 template <class Matrix, class Vector>
475 bool
477 {
478  // The Superlu factorization routines can handle square as well as
479  // rectangular matrices, but Superlu can only apply the solve routines to
480  // square matrices, so we check the matrix for squareness.
481  return( this->matrixA_->getGlobalNumRows() == this->matrixA_->getGlobalNumCols() );
482 }
483 
484 
485 template <class Matrix, class Vector>
486 void
487 Superlu<Matrix,Vector>::setParameters_impl(const Teuchos::RCP<Teuchos::ParameterList> & parameterList )
488 {
489  using Teuchos::RCP;
490  using Teuchos::getIntegralValue;
491  using Teuchos::ParameterEntryValidator;
492 
493  RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
494 
495  ILU_Flag_ = parameterList->get<bool>("ILU_Flag",false);
496  if (ILU_Flag_) {
497  SLU::ilu_set_default_options(&(data_.options));
498  // Override some default options
499  data_.options.PrintStat = SLU::NO;
500  }
501 
502  data_.options.Trans = this->control_.useTranspose_ ? SLU::TRANS : SLU::NOTRANS;
503  // The SuperLU transpose option can override the Amesos2 option
504  if( parameterList->isParameter("Trans") ){
505  RCP<const ParameterEntryValidator> trans_validator = valid_params->getEntry("Trans").validator();
506  parameterList->getEntry("Trans").setValidator(trans_validator);
507 
508  data_.options.Trans = getIntegralValue<SLU::trans_t>(*parameterList, "Trans");
509  }
510 
511  if( parameterList->isParameter("IterRefine") ){
512  RCP<const ParameterEntryValidator> refine_validator = valid_params->getEntry("IterRefine").validator();
513  parameterList->getEntry("IterRefine").setValidator(refine_validator);
514 
515  data_.options.IterRefine = getIntegralValue<SLU::IterRefine_t>(*parameterList, "IterRefine");
516  }
517 
518  if( parameterList->isParameter("ColPerm") ){
519  RCP<const ParameterEntryValidator> colperm_validator = valid_params->getEntry("ColPerm").validator();
520  parameterList->getEntry("ColPerm").setValidator(colperm_validator);
521 
522  data_.options.ColPerm = getIntegralValue<SLU::colperm_t>(*parameterList, "ColPerm");
523  }
524 
525  data_.options.DiagPivotThresh = parameterList->get<double>("DiagPivotThresh", 1.0);
526 
527  bool equil = parameterList->get<bool>("Equil", true);
528  data_.options.Equil = equil ? SLU::YES : SLU::NO;
529 
530  bool symmetric_mode = parameterList->get<bool>("SymmetricMode", false);
531  data_.options.SymmetricMode = symmetric_mode ? SLU::YES : SLU::NO;
532 
533  // ILU parameters
534  if( parameterList->isParameter("RowPerm") ){
535  RCP<const ParameterEntryValidator> rowperm_validator = valid_params->getEntry("RowPerm").validator();
536  parameterList->getEntry("RowPerm").setValidator(rowperm_validator);
537  data_.options.RowPerm = getIntegralValue<SLU::rowperm_t>(*parameterList, "RowPerm");
538  }
539 
540  /*if( parameterList->isParameter("ILU_DropRule") ) {
541  RCP<const ParameterEntryValidator> droprule_validator = valid_params->getEntry("ILU_DropRule").validator();
542  parameterList->getEntry("ILU_DropRule").setValidator(droprule_validator);
543  data_.options.ILU_DropRule = getIntegralValue<SLU::rule_t>(*parameterList, "ILU_DropRule");
544  }*/
545 
546  data_.options.ILU_DropTol = parameterList->get<double>("ILU_DropTol", 0.0001);
547 
548  data_.options.ILU_FillFactor = parameterList->get<double>("ILU_FillFactor", 10.0);
549 
550  if( parameterList->isParameter("ILU_Norm") ) {
551  RCP<const ParameterEntryValidator> norm_validator = valid_params->getEntry("ILU_Norm").validator();
552  parameterList->getEntry("ILU_Norm").setValidator(norm_validator);
553  data_.options.ILU_Norm = getIntegralValue<SLU::norm_t>(*parameterList, "ILU_Norm");
554  }
555 
556  if( parameterList->isParameter("ILU_MILU") ) {
557  RCP<const ParameterEntryValidator> milu_validator = valid_params->getEntry("ILU_MILU").validator();
558  parameterList->getEntry("ILU_MILU").setValidator(milu_validator);
559  data_.options.ILU_MILU = getIntegralValue<SLU::milu_t>(*parameterList, "ILU_MILU");
560  }
561 
562  data_.options.ILU_FillTol = parameterList->get<double>("ILU_FillTol", 0.01);
563 
564 }
565 
566 
567 template <class Matrix, class Vector>
568 Teuchos::RCP<const Teuchos::ParameterList>
570 {
571  using std::string;
572  using Teuchos::tuple;
573  using Teuchos::ParameterList;
574  using Teuchos::EnhancedNumberValidator;
575  using Teuchos::setStringToIntegralParameter;
576  using Teuchos::stringToIntegralParameterEntryValidator;
577 
578  static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
579 
580  if( is_null(valid_params) ){
581  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
582 
583  setStringToIntegralParameter<SLU::trans_t>("Trans", "NOTRANS",
584  "Solve for the transpose system or not",
585  tuple<string>("TRANS","NOTRANS","CONJ"),
586  tuple<string>("Solve with transpose",
587  "Do not solve with transpose",
588  "Solve with the conjugate transpose"),
589  tuple<SLU::trans_t>(SLU::TRANS,
590  SLU::NOTRANS,
591  SLU::CONJ),
592  pl.getRawPtr());
593 
594  setStringToIntegralParameter<SLU::IterRefine_t>("IterRefine", "NOREFINE",
595  "Type of iterative refinement to use",
596  tuple<string>("NOREFINE", "SLU_SINGLE", "SLU_DOUBLE"),
597  tuple<string>("Do not use iterative refinement",
598  "Do single iterative refinement",
599  "Do double iterative refinement"),
600  tuple<SLU::IterRefine_t>(SLU::NOREFINE,
601  SLU::SLU_SINGLE,
602  SLU::SLU_DOUBLE),
603  pl.getRawPtr());
604 
605  // Note: MY_PERMC not yet supported
606  setStringToIntegralParameter<SLU::colperm_t>("ColPerm", "COLAMD",
607  "Specifies how to permute the columns of the "
608  "matrix for sparsity preservation",
609  tuple<string>("NATURAL", "MMD_AT_PLUS_A",
610  "MMD_ATA", "COLAMD"),
611  tuple<string>("Natural ordering",
612  "Minimum degree ordering on A^T + A",
613  "Minimum degree ordering on A^T A",
614  "Approximate minimum degree column ordering"),
615  tuple<SLU::colperm_t>(SLU::NATURAL,
616  SLU::MMD_AT_PLUS_A,
617  SLU::MMD_ATA,
618  SLU::COLAMD),
619  pl.getRawPtr());
620 
621  Teuchos::RCP<EnhancedNumberValidator<double> > diag_pivot_thresh_validator
622  = Teuchos::rcp( new EnhancedNumberValidator<double>(0.0, 1.0) );
623  pl->set("DiagPivotThresh", 1.0,
624  "Specifies the threshold used for a diagonal entry to be an acceptable pivot",
625  diag_pivot_thresh_validator); // partial pivoting
626 
627  pl->set("Equil", true, "Whether to equilibrate the system before solve");
628 
629  pl->set("SymmetricMode", false,
630  "Specifies whether to use the symmetric mode. "
631  "Gives preference to diagonal pivots and uses "
632  "an (A^T + A)-based column permutation.");
633 
634  // ILU parameters
635 
636  setStringToIntegralParameter<SLU::rowperm_t>("RowPerm", "LargeDiag",
637  "Type of row permutation strategy to use",
638  tuple<string>("NOROWPERM","LargeDiag","MY_PERMR"),
639  tuple<string>("Use natural ordering",
640  "Use weighted bipartite matching algorithm",
641  "Use the ordering given in perm_r input"),
642  tuple<SLU::rowperm_t>(SLU::NOROWPERM,
643  SLU::LargeDiag,
644  SLU::MY_PERMR),
645  pl.getRawPtr());
646 
647  /*setStringToIntegralParameter<SLU::rule_t>("ILU_DropRule", "DROP_BASIC",
648  "Type of dropping strategy to use",
649  tuple<string>("DROP_BASIC","DROP_PROWS",
650  "DROP_COLUMN","DROP_AREA",
651  "DROP_DYNAMIC","DROP_INTERP"),
652  tuple<string>("ILUTP(t)","ILUTP(p,t)",
653  "Variant of ILUTP(p,t) for j-th column",
654  "Variant of ILUTP to control memory",
655  "Dynamically adjust threshold",
656  "Compute second dropping threshold by interpolation"),
657  tuple<SLU::rule_t>(SLU::DROP_BASIC,SLU::DROP_PROWS,SLU::DROP_COLUMN,
658  SLU::DROP_AREA,SLU::DROP_DYNAMIC,SLU::DROP_INTERP),
659  pl.getRawPtr());*/
660 
661  pl->set("ILU_DropTol", 0.0001, "ILUT drop tolerance");
662 
663  pl->set("ILU_FillFactor", 10.0, "ILUT fill factor");
664 
665  setStringToIntegralParameter<SLU::norm_t>("ILU_Norm", "INF_NORM",
666  "Type of norm to use",
667  tuple<string>("ONE_NORM","TWO_NORM","INF_NORM"),
668  tuple<string>("1-norm","2-norm","inf-norm"),
669  tuple<SLU::norm_t>(SLU::ONE_NORM,SLU::TWO_NORM,SLU::INF_NORM),
670  pl.getRawPtr());
671 
672  setStringToIntegralParameter<SLU::milu_t>("ILU_MILU", "SILU",
673  "Type of modified ILU to use",
674  tuple<string>("SILU","SMILU_1","SMILU_2","SMILU_3"),
675  tuple<string>("Regular ILU","MILU 1","MILU 2","MILU 3"),
676  tuple<SLU::milu_t>(SLU::SILU,SLU::SMILU_1,SLU::SMILU_2,
677  SLU::SMILU_3),
678  pl.getRawPtr());
679 
680  pl->set("ILU_FillTol", 0.01, "ILUT fill tolerance");
681 
682  pl->set("ILU_Flag", false, "ILU flag: if true, run ILU routines");
683 
684  valid_params = pl;
685  }
686 
687  return valid_params;
688 }
689 
690 
691 template <class Matrix, class Vector>
692 bool
694 {
695  using Teuchos::as;
696 
697 #ifdef HAVE_AMESOS2_TIMERS
698  Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
699 #endif
700 
701  // SuperLU does not need the matrix at symbolicFactorization()
702  if( current_phase == SYMBFACT ) return false;
703 
704  // Cleanup old store memory if it's non-NULL (should only ever be non-NULL at root_)
705  if( data_.A.Store != NULL ){
706  SLU::Destroy_SuperMatrix_Store( &(data_.A) );
707  data_.A.Store = NULL;
708  }
709 
710  // Only the root image needs storage allocated
711  if( this->root_ ){
712  nzvals_.resize(this->globalNumNonZeros_);
713  rowind_.resize(this->globalNumNonZeros_);
714  colptr_.resize(this->globalNumCols_ + 1);
715  }
716 
717  int nnz_ret = 0;
718  {
719 #ifdef HAVE_AMESOS2_TIMERS
720  Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
721 #endif
722 
723  TEUCHOS_TEST_FOR_EXCEPTION( this->rowIndexBase_ != this->columnIndexBase_,
724  std::runtime_error,
725  "Row and column maps have different indexbase ");
727  MatrixAdapter<Matrix>,slu_type,int,int>::do_get(this->matrixA_.ptr(),
728  nzvals_(), rowind_(),
729  colptr_(), nnz_ret, ROOTED,
730  ARBITRARY,
731  this->rowIndexBase_);
732  }
733 
734  // Get the SLU data type for this type of matrix
735  SLU::Dtype_t dtype = type_map::dtype;
736 
737  if( this->root_ ){
738  TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<int>(this->globalNumNonZeros_),
739  std::runtime_error,
740  "Did not get the expected number of non-zero vals");
741 
742  function_map::create_CompCol_Matrix( &(data_.A),
743  this->globalNumRows_, this->globalNumCols_,
744  nnz_ret,
745  nzvals_.getRawPtr(),
746  rowind_.getRawPtr(),
747  colptr_.getRawPtr(),
748  SLU::SLU_NC, dtype, SLU::SLU_GE);
749  }
750 
751  return true;
752 }
753 
754 
755 template<class Matrix, class Vector>
756 const char* Superlu<Matrix,Vector>::name = "SuperLU";
757 
758 
759 } // end namespace Amesos2
760 
761 #endif // AMESOS2_SUPERLU_DEF_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Superlu specific solve.
Definition: Amesos2_Superlu_def.hpp:365
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Superlu_def.hpp:693
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
int numericFactorization_impl()
Superlu specific numeric factorization.
Definition: Amesos2_Superlu_def.hpp:232
global_size_type globalNumCols_
Number of global columns in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:479
~Superlu()
Destructor.
Definition: Amesos2_Superlu_def.hpp:108
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Superlu_def.hpp:569
global_size_type globalNumRows_
Number of global rows in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:476
Amesos2 Superlu declarations.
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:243
Definition: Amesos2_TypeDecl.hpp:142
Superlu(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Initialize from Teuchos::RCP.
Definition: Amesos2_Superlu_def.hpp:67
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:580
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_Superlu_def.hpp:131
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Superlu_def.hpp:476
Definition: Amesos2_TypeDecl.hpp:127
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_Superlu_def.hpp:487
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Superlu_def.hpp:185
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:296
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:175
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Superlu.
Definition: Amesos2_Superlu_def.hpp:210
Amesos2 interface to the SuperLU package.
Definition: Amesos2_Superlu_decl.hpp:73