53 #ifndef AMESOS2_SUPERLU_DEF_HPP 54 #define AMESOS2_SUPERLU_DEF_HPP 56 #include <Teuchos_Tuple.hpp> 57 #include <Teuchos_ParameterList.hpp> 58 #include <Teuchos_StandardParameterEntryValidators.hpp> 66 template <
class Matrix,
class Vector>
68 Teuchos::RCP<const Matrix> A,
69 Teuchos::RCP<Vector> X,
70 Teuchos::RCP<const Vector> B )
76 SLU::set_default_options(&(data_.options));
78 data_.options.PrintStat = SLU::NO;
80 SLU::StatInit(&(data_.stat));
88 data_.relax = SLU::sp_ienv(2);
89 data_.panel_size = SLU::sp_ienv(1);
100 template <
class Matrix,
class Vector>
108 SLU::StatFree( &(data_.stat) ) ;
111 if ( data_.A.Store != NULL ){
112 SLU::Destroy_SuperMatrix_Store( &(data_.A) );
116 if ( data_.L.Store != NULL ){
117 SLU::Destroy_SuperNode_Matrix( &(data_.L) );
118 SLU::Destroy_CompCol_Matrix( &(data_.U) );
122 template<
class Matrix,
class Vector>
134 int permc_spec = data_.options.ColPerm;
135 if ( permc_spec != SLU::MY_PERMC && this->
root_ ){
136 #ifdef HAVE_AMESOS2_TIMERS 137 Teuchos::TimeMonitor preOrderTimer(this->
timers_.preOrderTime_);
140 SLU::get_perm_c(permc_spec, &(data_.A), data_.perm_c.getRawPtr());
147 template <
class Matrix,
class Vector>
162 same_symbolic_ =
false;
163 data_.options.Fact = SLU::DOFACT;
169 template <
class Matrix,
class Vector>
178 if ( !same_symbolic_ && data_.L.Store != NULL ){
179 SLU::Destroy_SuperNode_Matrix( &(data_.L) );
180 SLU::Destroy_CompCol_Matrix( &(data_.U) );
181 data_.L.Store = NULL;
182 data_.U.Store = NULL;
185 if( same_symbolic_ ) data_.options.Fact = SLU::SamePattern_SameRowPerm;
190 #ifdef HAVE_AMESOS2_DEBUG 191 TEUCHOS_TEST_FOR_EXCEPTION( data_.A.ncol != as<int>(this->globalNumCols_),
193 "Error in converting to SuperLU SuperMatrix: wrong number of global columns." );
194 TEUCHOS_TEST_FOR_EXCEPTION( data_.A.nrow != as<int>(this->globalNumRows_),
196 "Error in converting to SuperLU SuperMatrix: wrong number of global rows." );
199 if( data_.options.Equil == SLU::YES ){
200 magnitude_type rowcnd, colcnd, amax;
204 function_map::gsequ(&(data_.A), data_.R.getRawPtr(),
205 data_.C.getRawPtr(), &rowcnd, &colcnd,
207 TEUCHOS_TEST_FOR_EXCEPTION( info2 != 0,
209 "SuperLU gsequ returned with status " << info2 );
212 function_map::laqgs(&(data_.A), data_.R.getRawPtr(),
213 data_.C.getRawPtr(), rowcnd, colcnd,
214 amax, &(data_.equed));
223 SLU::sp_preorder(&(data_.options), &(data_.A), data_.perm_c.getRawPtr(),
224 data_.etree.getRawPtr(), &(data_.AC));
227 #ifdef HAVE_AMESOS2_TIMERS 228 Teuchos::TimeMonitor numFactTimer(this->
timers_.numFactTime_);
231 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG 232 std::cout <<
"Superlu:: Before numeric factorization" << std::endl;
233 std::cout <<
"nzvals_ : " <<
nzvals_.toString() << std::endl;
234 std::cout <<
"rowind_ : " <<
rowind_.toString() << std::endl;
235 std::cout <<
"colptr_ : " <<
colptr_.toString() << std::endl;
238 function_map::gstrf(&(data_.options), &(data_.AC),
239 data_.relax, data_.panel_size, data_.etree.getRawPtr(),
240 NULL, 0, data_.perm_c.getRawPtr(), data_.perm_r.getRawPtr(),
241 &(data_.L), &(data_.U), &(data_.stat), &info);
244 SLU::Destroy_CompCol_Permuted( &(data_.AC) );
247 this->
setNnzLU( as<size_t>(((SLU::SCformat*)data_.L.Store)->nnz +
248 ((SLU::NCformat*)data_.U.Store)->nnz) );
252 Teuchos::broadcast(*(this->
matrixA_->getComm()), 0, &info);
254 global_size_type info_st = as<global_size_type>(info);
255 TEUCHOS_TEST_FOR_EXCEPTION( (info_st > 0) && (info_st <= this->
globalNumCols_),
257 "Factorization complete, but matrix is singular. Division by zero eminent");
258 TEUCHOS_TEST_FOR_EXCEPTION( (info_st > 0) && (info_st > this->globalNumCols_),
260 "Memory allocation failure in Superlu factorization");
262 data_.options.Fact = SLU::FACTORED;
263 same_symbolic_ =
true;
269 template <
class Matrix,
class Vector>
276 const global_size_type ld_rhs = this->
root_ ? X->getGlobalLength() : 0;
277 const size_t nrhs = X->getGlobalNumVectors();
279 const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
280 Teuchos::Array<slu_type> xValues(val_store_size);
281 Teuchos::Array<slu_type> bValues(val_store_size);
284 #ifdef HAVE_AMESOS2_TIMERS 285 Teuchos::TimeMonitor mvConvTimer(this->
timers_.vecConvTime_);
286 Teuchos::TimeMonitor redistTimer( this->
timers_.vecRedistTime_ );
289 slu_type>::do_get(B, bValues(),
296 magnitude_type rpg, rcond;
298 data_.ferr.resize(nrhs);
299 data_.berr.resize(nrhs);
302 #ifdef HAVE_AMESOS2_TIMERS 303 Teuchos::TimeMonitor mvConvTimer(this->
timers_.vecConvTime_);
305 SLU::Dtype_t dtype = type_map::dtype;
306 int i_ld_rhs = as<int>(ld_rhs);
307 function_map::create_Dense_Matrix(&(data_.B), i_ld_rhs, as<int>(nrhs),
308 bValues.getRawPtr(), i_ld_rhs,
309 SLU::SLU_DN, dtype, SLU::SLU_GE);
310 function_map::create_Dense_Matrix(&(data_.X), i_ld_rhs, as<int>(nrhs),
311 xValues.getRawPtr(), i_ld_rhs,
312 SLU::SLU_DN, dtype, SLU::SLU_GE);
319 #ifdef HAVE_AMESOS2_TIMERS 320 Teuchos::TimeMonitor solveTimer(this->
timers_.solveTime_);
323 function_map::gssvx(&(data_.options), &(data_.A),
324 data_.perm_c.getRawPtr(), data_.perm_r.getRawPtr(), data_.etree.getRawPtr(),
325 &(data_.equed), data_.R.getRawPtr(), data_.C.getRawPtr(), &(data_.L),
326 &(data_.U), NULL, 0, &(data_.B), &(data_.X), &rpg, &rcond,
327 data_.ferr.getRawPtr(), data_.berr.getRawPtr(), &(data_.mem_usage),
328 &(data_.stat), &ierr);
332 SLU::Destroy_SuperMatrix_Store( &(data_.X) );
333 SLU::Destroy_SuperMatrix_Store( &(data_.B) );
334 data_.X.Store = NULL;
335 data_.B.Store = NULL;
339 Teuchos::broadcast(*(this->
getComm()), 0, &ierr);
341 global_size_type ierr_st = as<global_size_type>(ierr);
342 TEUCHOS_TEST_FOR_EXCEPTION( ierr < 0,
343 std::invalid_argument,
344 "Argument " << -ierr <<
" to SuperLU xgssvx had illegal value" );
345 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0 && ierr_st <= this->
globalNumCols_,
347 "Factorization complete, but U is exactly singular" );
348 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0 && ierr_st > this->globalNumCols_ + 1,
350 "SuperLU allocated " << ierr - this->globalNumCols_ <<
" bytes of " 351 "memory before allocation failure occured." );
355 #ifdef HAVE_AMESOS2_TIMERS 356 Teuchos::TimeMonitor redistTimer(this->
timers_.vecRedistTime_);
370 template <
class Matrix,
class Vector>
377 return( this->
matrixA_->getGlobalNumRows() == this->
matrixA_->getGlobalNumCols() );
381 template <
class Matrix,
class Vector>
386 using Teuchos::getIntegralValue;
387 using Teuchos::ParameterEntryValidator;
391 data_.options.Trans = this->
control_.useTranspose_ ? SLU::TRANS : SLU::NOTRANS;
393 if( parameterList->isParameter(
"Trans") ){
394 RCP<const ParameterEntryValidator> trans_validator = valid_params->getEntry(
"Trans").validator();
395 parameterList->getEntry(
"Trans").setValidator(trans_validator);
397 data_.options.Trans = getIntegralValue<SLU::trans_t>(*parameterList,
"Trans");
400 if( parameterList->isParameter(
"IterRefine") ){
401 RCP<const ParameterEntryValidator> refine_validator = valid_params->getEntry(
"IterRefine").validator();
402 parameterList->getEntry(
"IterRefine").setValidator(refine_validator);
404 data_.options.IterRefine = getIntegralValue<SLU::IterRefine_t>(*parameterList,
"IterRefine");
407 if( parameterList->isParameter(
"ColPerm") ){
408 RCP<const ParameterEntryValidator> colperm_validator = valid_params->getEntry(
"ColPerm").validator();
409 parameterList->getEntry(
"ColPerm").setValidator(colperm_validator);
411 data_.options.ColPerm = getIntegralValue<SLU::colperm_t>(*parameterList,
"ColPerm");
414 data_.options.DiagPivotThresh = parameterList->get<
double>(
"DiagPivotThresh", 1.0);
416 bool equil = parameterList->get<
bool>(
"Equil",
true);
417 data_.options.Equil = equil ? SLU::YES : SLU::NO;
419 bool symmetric_mode = parameterList->get<
bool>(
"SymmetricMode",
false);
420 data_.options.SymmetricMode = symmetric_mode ? SLU::YES : SLU::NO;
424 template <
class Matrix,
class Vector>
425 Teuchos::RCP<const Teuchos::ParameterList>
429 using Teuchos::tuple;
430 using Teuchos::ParameterList;
431 using Teuchos::EnhancedNumberValidator;
432 using Teuchos::setStringToIntegralParameter;
433 using Teuchos::stringToIntegralParameterEntryValidator;
435 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
437 if( is_null(valid_params) ){
438 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
440 setStringToIntegralParameter<SLU::trans_t>(
"Trans",
"NOTRANS",
441 "Solve for the transpose system or not",
442 tuple<string>(
"TRANS",
"NOTRANS",
"CONJ"),
443 tuple<string>(
"Solve with transpose",
444 "Do not solve with transpose",
445 "Solve with the conjugate transpose"),
446 tuple<SLU::trans_t>(SLU::TRANS,
451 setStringToIntegralParameter<SLU::IterRefine_t>(
"IterRefine",
"NOREFINE",
452 "Type of iterative refinement to use",
453 tuple<string>(
"NOREFINE",
"SLU_SINGLE",
"SLU_DOUBLE"),
454 tuple<string>(
"Do not use iterative refinement",
455 "Do single iterative refinement",
456 "Do double iterative refinement"),
457 tuple<SLU::IterRefine_t>(SLU::NOREFINE,
463 setStringToIntegralParameter<SLU::colperm_t>(
"ColPerm",
"COLAMD",
464 "Specifies how to permute the columns of the " 465 "matrix for sparsity preservation",
466 tuple<string>(
"NATURAL",
"MMD_AT_PLUS_A",
467 "MMD_ATA",
"COLAMD"),
468 tuple<string>(
"Natural ordering",
469 "Minimum degree ordering on A^T + A",
470 "Minimum degree ordering on A^T A",
471 "Approximate minimum degree column ordering"),
472 tuple<SLU::colperm_t>(SLU::NATURAL,
478 Teuchos::RCP<EnhancedNumberValidator<double> > diag_pivot_thresh_validator
479 = Teuchos::rcp(
new EnhancedNumberValidator<double>(0.0, 1.0) );
480 pl->set(
"DiagPivotThresh", 1.0,
481 "Specifies the threshold used for a diagonal entry to be an acceptable pivot",
482 diag_pivot_thresh_validator);
484 pl->set(
"Equil",
true,
"Whether to equilibrate the system before solve");
486 pl->set(
"SymmetricMode",
false,
487 "Specifies whether to use the symmetric mode. " 488 "Gives preference to diagonal pivots and uses " 489 "an (A^T + A)-based column permutation.");
498 template <
class Matrix,
class Vector>
504 #ifdef HAVE_AMESOS2_TIMERS 505 Teuchos::TimeMonitor convTimer(this->
timers_.mtxConvTime_);
509 if( current_phase == SYMBFACT )
return false;
512 if( data_.A.Store != NULL ){
513 SLU::Destroy_SuperMatrix_Store( &(data_.A) );
514 data_.A.Store = NULL;
526 #ifdef HAVE_AMESOS2_TIMERS 527 Teuchos::TimeMonitor mtxRedistTimer( this->
timers_.mtxRedistTime_ );
532 "Row and column maps have different indexbase ");
542 SLU::Dtype_t dtype = type_map::dtype;
547 "Did not get the expected number of non-zero vals");
549 function_map::create_CompCol_Matrix( &(data_.A),
550 this->globalNumRows_, this->globalNumCols_,
555 SLU::SLU_NC, dtype, SLU::SLU_GE);
562 template<
class Matrix,
class Vector>
568 #endif // AMESOS2_SUPERLU_DEF_HPP Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
Teuchos::Array< slu_type > nzvals_
Stores the values of the nonzero entries for SuperLU.
Definition: Amesos2_Superlu_decl.hpp:250
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Superlu_def.hpp:500
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
Teuchos::Array< int > colptr_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Superlu_decl.hpp:254
int numericFactorization_impl()
Superlu specific numeric factorization.
Definition: Amesos2_Superlu_def.hpp:171
global_size_type columnIndexBase_
Index base of column map of matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:485
global_size_type globalNumCols_
Number of global columns in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:476
~Superlu()
Destructor.
Definition: Amesos2_Superlu_def.hpp:101
Teuchos::Array< int > rowind_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Superlu_decl.hpp:252
bool root_
If true, then this is the root processor.
Definition: Amesos2_SolverCore_decl.hpp:504
global_size_type globalNumRows_
Number of global rows in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:473
Amesos2 Superlu declarations.
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Superlu_def.hpp:372
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:243
Definition: Amesos2_TypeDecl.hpp:134
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
Control control_
Parameters for solving.
Definition: Amesos2_SolverCore_decl.hpp:492
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Superlu_def.hpp:426
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:575
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:271
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns a pointer to the Teuchos::Comm communicator with this operator.
Definition: Amesos2_SolverCore_decl.hpp:360
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
global_size_type globalNumNonZeros_
Number of global non-zero values in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:479
void setNnzLU(size_t nnz)
Set the number of non-zero values in the and factors.
Definition: Amesos2_SolverCore_decl.hpp:449
Definition: Amesos2_TypeDecl.hpp:119
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > ¶meterList)
Definition: Amesos2_Superlu_def.hpp:383
Timers timers_
Various timing statistics.
Definition: Amesos2_SolverCore_decl.hpp:495
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Superlu_def.hpp:124
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:292
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:175
Teuchos::RCP< const MatrixAdapter< Matrix > > matrixA_
The LHS operator.
Definition: Amesos2_SolverCore_decl.hpp:452
global_size_type rowIndexBase_
Index base of rowmap of matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:482
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Superlu.
Definition: Amesos2_Superlu_def.hpp:149
Amesos2 interface to the SuperLU package.
Definition: Amesos2_Superlu_decl.hpp:73