18 #ifndef AMESOS2_SUPERLUMT_DEF_HPP
19 #define AMESOS2_SUPERLUMT_DEF_HPP
21 #include <Teuchos_Tuple.hpp>
22 #include <Teuchos_ParameterList.hpp>
23 #include <Teuchos_StandardParameterEntryValidators.hpp>
42 int sp_colorder(SuperMatrix*,
int*,superlumt_options_t*,SuperMatrix*);
62 template <
class Matrix,
class Vector>
64 Teuchos::RCP<Vector> X,
65 Teuchos::RCP<const Vector> B )
70 , is_contiguous_(true)
72 Teuchos::RCP<Teuchos::ParameterList> default_params
76 data_.options.lwork = 0;
80 data_.options.perm_r = data_.perm_r.getRawPtr();
81 data_.options.perm_c = data_.perm_c.getRawPtr();
86 data_.options.refact = SLUMT::NO;
87 data_.equed = SLUMT::NOEQUIL;
92 data_.AC.Store = NULL;
93 data_.BX.Store = NULL;
97 data_.stat.ops = NULL;
101 template <
class Matrix,
class Vector>
111 if ( data_.A.Store != NULL ){
113 SLUMT::D::Destroy_SuperMatrix_Store( &(data_.A) );
117 if( data_.AC.Store != NULL ){
118 SLUMT::D::Destroy_CompCol_Permuted( &(data_.AC) );
121 if ( data_.L.Store != NULL ){
122 SLUMT::D::Destroy_SuperNode_SCP( &(data_.L) );
123 SLUMT::D::Destroy_CompCol_NCP( &(data_.U) );
126 free( data_.options.etree );
127 free( data_.options.colcnt_h );
128 free( data_.options.part_super_h );
133 if ( data_.BX.Store != NULL ){
139 SLUMT::D::Destroy_SuperMatrix_Store( &(data_.BX) );
142 if ( data_.stat.ops != NULL )
143 SLUMT::D::StatFree( &(data_.stat) );
146 template<
class Matrix,
class Vector>
151 int perm_spec = data_.options.ColPerm;
152 if( perm_spec != SLUMT::MY_PERMC && this->root_ ){
153 #ifdef HAVE_AMESOS2_TIMERS
154 Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
157 SLUMT::S::get_perm_c(perm_spec, &(data_.A), data_.perm_c.getRawPtr());
166 template <
class Matrix,
class Vector>
174 data_.options.refact = SLUMT::NO;
176 if( this->status_.numericFactorizationDone() && this->root_ ){
181 SLUMT::D::Destroy_SuperNode_Matrix( &(data_.L) );
182 SLUMT::D::Destroy_CompCol_NCP( &(data_.U) );
183 data_.L.Store = NULL;
184 data_.U.Store = NULL;
191 template <
class Matrix,
class Vector>
197 #ifdef HAVE_AMESOS2_DEBUG
198 const int nprocs = data_.options.nprocs;
199 TEUCHOS_TEST_FOR_EXCEPTION( nprocs <= 0,
200 std::invalid_argument,
201 "The number of threads to spawn should be greater than 0." );
208 if( data_.options.fact == SLUMT::EQUILIBRATE ){
209 magnitude_type rowcnd, colcnd, amax;
212 function_map::gsequ(&(data_.A), data_.R.getRawPtr(),
213 data_.C.getRawPtr(), &rowcnd, &colcnd,
215 TEUCHOS_TEST_FOR_EXCEPTION( info != 0,
217 "SuperLU_MT gsequ returned with status " << info );
219 function_map::laqgs(&(data_.A), data_.R.getRawPtr(),
220 data_.C.getRawPtr(), rowcnd, colcnd,
221 amax, &(data_.equed));
223 data_.rowequ = (data_.equed == SLUMT::ROW) || (data_.equed == SLUMT::BOTH);
224 data_.colequ = (data_.equed == SLUMT::COL) || (data_.equed == SLUMT::BOTH);
226 data_.options.fact = SLUMT::DOFACT;
230 if( data_.AC.Store != NULL ){
231 SLUMT::D::Destroy_CompCol_Permuted( &(data_.AC) );
232 if( data_.options.refact == SLUMT::NO ){
233 free( data_.options.etree );
234 free( data_.options.colcnt_h );
235 free( data_.options.part_super_h );
237 data_.AC.Store = NULL;
241 SLUMT::sp_colorder(&(data_.A), data_.perm_c.getRawPtr(),
242 &(data_.options), &(data_.AC));
246 const int n = as<int>(this->globalNumCols_);
247 if( data_.stat.ops != NULL ){ SLUMT::D::StatFree( &(data_.stat) ); data_.stat.ops = NULL; }
248 SLUMT::D::StatAlloc(n, data_.options.nprocs, data_.options.panel_size,
249 data_.options.relax, &(data_.stat));
250 SLUMT::D::StatInit(n, data_.options.nprocs, &(data_.stat));
254 #ifdef HAVE_AMESOS2_TIMERS
255 Teuchos::TimeMonitor numFactTimer( this->timers_.numFactTime_ );
258 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
259 std::cout <<
"SuperLU_MT:: Before numeric factorization" << std::endl;
260 std::cout <<
"nzvals_ : " << nzvals_.toString() << std::endl;
261 std::cout <<
"rowind_ : " << rowind_.toString() << std::endl;
262 std::cout <<
"colptr_ : " << colptr_.toString() << std::endl;
265 function_map::gstrf(&(data_.options), &(data_.AC),
266 data_.perm_r.getRawPtr(), &(data_.L), &(data_.U),
267 &(data_.stat), &info);
271 this->setNnzLU( as<size_t>(((SLUMT::SCformat*)data_.L.Store)->nnz +
272 ((SLUMT::NCformat*)data_.U.Store)->nnz) );
276 const global_size_type info_st = as<global_size_type>(info);
277 TEUCHOS_TEST_FOR_EXCEPTION( (info_st > 0) && (info_st <= this->globalNumCols_),
279 "Factorization complete, but matrix is singular. Division by zero eminent");
280 TEUCHOS_TEST_FOR_EXCEPTION( (info_st > 0) && (info_st > this->globalNumCols_),
282 "Memory allocation failure in SuperLU_MT factorization");
286 data_.options.fact = SLUMT::FACTORED;
287 data_.options.refact = SLUMT::YES;
290 Teuchos::broadcast(*(this->getComm()),0,&info);
295 template <
class Matrix,
class Vector>
302 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
303 const size_t nrhs = X->getGlobalNumVectors();
305 Teuchos::Array<slu_type> bxvals_(ld_rhs * nrhs);
306 size_t ldbx_ = as<size_t>(ld_rhs);
309 #ifdef HAVE_AMESOS2_TIMERS
310 Teuchos::TimeMonitor convTimer( this->timers_.vecConvTime_ );
311 Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
314 if ( is_contiguous_ ==
true ) {
316 slu_type>::do_get(B, bxvals_(),
318 ROOTED, this->rowIndexBase_);
321 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
322 "NON_CONTIGUOUS_AND_ROOTED not supported.");
329 if( data_.BX.Store != NULL ){
330 SLUMT::D::Destroy_SuperMatrix_Store( &(data_.BX) );
331 data_.BX.Store = NULL;
335 #ifdef HAVE_AMESOS2_TIMERS
336 Teuchos::TimeMonitor convTimer( this->timers_.vecConvTime_ );
338 SLUMT::Dtype_t dtype = type_map::dtype;
339 function_map::create_Dense_Matrix(&(data_.BX), as<int>(ld_rhs), as<int>(nrhs),
340 bxvals_.getRawPtr(), as<int>(ldbx_),
341 SLUMT::SLU_DN, dtype, SLUMT::SLU_GE);
344 if( data_.options.trans == SLUMT::NOTRANS ){
347 Util::scale(bxvals_(), as<size_t>(ld_rhs), ldbx_, data_.R(),
348 SLUMT::slu_mt_mult<slu_type,magnitude_type>());
350 }
else if( data_.colequ ){
352 Util::scale(bxvals_(), as<size_t>(ld_rhs), ldbx_, data_.C(),
353 SLUMT::slu_mt_mult<slu_type,magnitude_type>());
358 #ifdef HAVE_AMESOS2_TIMERS
359 Teuchos::TimeMonitor solveTimer( this->timers_.solveTime_ );
362 function_map::gstrs(data_.options.trans, &(data_.L),
363 &(data_.U), data_.perm_r.getRawPtr(),
364 data_.perm_c.getRawPtr(), &(data_.BX),
365 &(data_.stat), &info);
370 Teuchos::broadcast(*(this->getComm()),0,&info);
372 TEUCHOS_TEST_FOR_EXCEPTION( info < 0,
374 "Argument " << -info <<
" to gstrs had an illegal value" );
377 if( data_.options.trans == SLUMT::NOTRANS ){
380 Util::scale(bxvals_(), as<size_t>(ld_rhs), ldbx_, data_.C(),
381 SLUMT::slu_mt_mult<slu_type,magnitude_type>());
383 }
else if( data_.rowequ ){
385 Util::scale(bxvals_(), as<size_t>(ld_rhs), ldbx_, data_.R(),
386 SLUMT::slu_mt_mult<slu_type,magnitude_type>());
391 #ifdef HAVE_AMESOS2_TIMERS
392 Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
395 if ( is_contiguous_ ==
true ) {
400 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
401 "NON_CONTIGUOUS_AND_ROOTED not supported.");
409 template <
class Matrix,
class Vector>
416 return( this->matrixA_->getGlobalNumRows() == this->matrixA_->getGlobalNumCols() );
420 template <
class Matrix,
class Vector>
426 using Teuchos::getIntegralValue;
427 using Teuchos::ParameterEntryValidator;
429 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
431 int default_nprocs = Kokkos::DefaultHostExecutionSpace().concurrency();
432 data_.options.nprocs = parameterList->get<
int>(
"nprocs", default_nprocs);
434 data_.options.trans = this->control_.useTranspose_ ? SLUMT::TRANS : SLUMT::NOTRANS;
436 if( parameterList->isParameter(
"trans") ){
437 RCP<const ParameterEntryValidator> trans_validator = valid_params->getEntry(
"trans").validator();
438 parameterList->getEntry(
"trans").setValidator(trans_validator);
440 data_.options.trans = getIntegralValue<SLUMT::trans_t>(*parameterList,
"trans");
443 data_.options.panel_size = parameterList->get<
int>(
"panel_size", SLUMT::D::sp_ienv(1));
445 data_.options.relax = parameterList->get<
int>(
"relax", SLUMT::D::sp_ienv(2));
447 const bool equil = parameterList->get<
bool>(
"Equil",
true);
448 data_.options.fact = equil ? SLUMT::EQUILIBRATE : SLUMT::DOFACT;
450 const bool symmetric_mode = parameterList->get<
bool>(
"SymmetricMode",
false);
451 data_.options.SymmetricMode = symmetric_mode ? SLUMT::YES : SLUMT::NO;
453 const bool print_stat = parameterList->get<
bool>(
"PrintStat",
false);
454 data_.options.PrintStat = print_stat ? SLUMT::YES : SLUMT::NO;
456 data_.options.diag_pivot_thresh = parameterList->get<
double>(
"diag_pivot_thresh", 1.0);
458 if( parameterList->isParameter(
"ColPerm") ){
459 RCP<const ParameterEntryValidator> colperm_validator = valid_params->getEntry(
"ColPerm").validator();
460 parameterList->getEntry(
"ColPerm").setValidator(colperm_validator);
462 data_.options.ColPerm = getIntegralValue<SLUMT::colperm_t>(*parameterList,
"ColPerm");
466 data_.options.usepr = SLUMT::NO;
468 if( parameterList->isParameter(
"IsContiguous") ){
469 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
474 template <
class Matrix,
class Vector>
475 Teuchos::RCP<const Teuchos::ParameterList>
479 using Teuchos::tuple;
480 using Teuchos::ParameterList;
481 using Teuchos::EnhancedNumberValidator;
482 using Teuchos::setStringToIntegralParameter;
483 using Teuchos::stringToIntegralParameterEntryValidator;
485 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
487 if( is_null(valid_params) ){
488 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
490 int default_nprocs = Kokkos::DefaultHostExecutionSpace().concurrency();
491 Teuchos::RCP<EnhancedNumberValidator<int> > nprocs_validator
492 = Teuchos::rcp(
new EnhancedNumberValidator<int>() );
493 nprocs_validator->setMin(default_nprocs);
494 pl->set(
"nprocs", default_nprocs,
"The number of processors to factorize with", nprocs_validator);
496 setStringToIntegralParameter<SLUMT::trans_t>(
"trans",
"NOTRANS",
497 "Solve for the transpose system or not",
498 tuple<string>(
"TRANS",
"NOTRANS",
"CONJ"),
499 tuple<string>(
"Solve with transpose",
500 "Do not solve with transpose",
501 "Solve with the conjugate transpose"),
502 tuple<SLUMT::trans_t>(SLUMT::TRANS,
507 Teuchos::RCP<EnhancedNumberValidator<int> > panel_size_validator
508 = Teuchos::rcp(
new EnhancedNumberValidator<int>() );
509 panel_size_validator->setMin(1);
510 pl->set(
"panel_size", SLUMT::D::sp_ienv(1),
511 "Specifies the number of consecutive columns to be treated as a unit of task.",
512 panel_size_validator);
514 Teuchos::RCP<EnhancedNumberValidator<int> > relax_validator
515 = Teuchos::rcp(
new EnhancedNumberValidator<int>() );
516 relax_validator->setMin(1);
517 pl->set(
"relax", SLUMT::D::sp_ienv(2),
518 "Specifies the number of columns to be grouped as a relaxed supernode",
521 pl->set(
"Equil",
true,
"Whether to equilibrate the system before solve");
523 Teuchos::RCP<EnhancedNumberValidator<double> > diag_pivot_thresh_validator
524 = Teuchos::rcp(
new EnhancedNumberValidator<double>(0.0, 1.0) );
525 pl->set(
"diag_pivot_thresh", 1.0,
526 "Specifies the threshold used for a diagonal entry to be an acceptable pivot",
527 diag_pivot_thresh_validator);
530 setStringToIntegralParameter<SLUMT::colperm_t>(
"ColPerm",
"COLAMD",
531 "Specifies how to permute the columns of the "
532 "matrix for sparsity preservation",
533 tuple<string>(
"NATURAL",
537 tuple<string>(
"Natural ordering",
538 "Minimum degree ordering on A^T + A",
539 "Minimum degree ordering on A^T A",
540 "Approximate minimum degree column ordering"),
541 tuple<SLUMT::colperm_t>(SLUMT::NATURAL,
542 SLUMT::MMD_AT_PLUS_A,
547 pl->set(
"SymmetricMode",
false,
"Specifies whether to use the symmetric mode");
552 pl->set(
"PrintStat",
false,
"Specifies whether to print the solver's statistics");
554 pl->set(
"IsContiguous",
true,
"Whether GIDs contiguous");
563 template <
class Matrix,
class Vector>
569 #ifdef HAVE_AMESOS2_TIMERS
570 Teuchos::TimeMonitor convTimer( this->timers_.mtxConvTime_ );
573 if( current_phase == SYMBFACT )
return false;
576 if( data_.A.Store != NULL ){
577 SLUMT::D::Destroy_SuperMatrix_Store( &(data_.A) );
578 data_.A.Store = NULL;
582 nzvals_.resize(this->globalNumNonZeros_);
583 rowind_.resize(this->globalNumNonZeros_);
584 colptr_.resize(this->globalNumCols_ + 1);
589 #ifdef HAVE_AMESOS2_TIMERS
590 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
594 if ( is_contiguous_ ==
true ) {
595 Util::get_ccs_helper<
597 nzvals_, rowind_, colptr_,
598 nnz_ret, ROOTED, ARBITRARY, this->rowIndexBase_);
601 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
602 "NON_CONTIGUOUS_AND_ROOTED not supported.");
607 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<int>(this->globalNumNonZeros_),
609 "rank=0 failed to get all nonzero values in getCcs()");
611 SLUMT::Dtype_t dtype = type_map::dtype;
612 function_map::create_CompCol_Matrix(&(data_.A),
613 as<int>(this->globalNumRows_),
614 as<int>(this->globalNumCols_),
620 dtype, SLUMT::SLU_GE);
622 TEUCHOS_TEST_FOR_EXCEPTION( data_.A.Store == NULL,
624 "Failed to allocate matrix store" );
631 template<
class Matrix,
class Vector>
637 #endif // AMESOS2_SUPERLUMT_DEF_HPP
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Return a const parameter list of all of the valid parameters that this->setParameterList(...) will accept.
Definition: Amesos2_SolverCore_def.hpp:524
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:71
void scale(ArrayView< Scalar1 > vals, size_t l, size_t ld, ArrayView< Scalar2 > s)
Scales a 1-D representation of a multivector.
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:31
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Superlumt_def.hpp:411
Amesos2 interface to the Multi-threaded version of SuperLU.
Definition: Amesos2_Superlumt_decl.hpp:43
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
SuperLU_MT specific solve.
Definition: Amesos2_Superlumt_def.hpp:297
global_size_type globalNumCols_
Number of global columns in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:445
super_type & setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶meterList) override
Set/update internal variables and solver options.
Definition: Amesos2_SolverCore_def.hpp:492
global_size_type globalNumRows_
Number of global rows in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:442
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using SuperLU_MT.
Definition: Amesos2_Superlumt_def.hpp:168
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:233
Utility functions for Amesos2.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Superlumt_def.hpp:476
Superlumt(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Initialize from Teuchos::RCP.
Definition: Amesos2_Superlumt_def.hpp:63
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Superlumt_def.hpp:148
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:42
int numericFactorization_impl()
SuperLU_MT specific numeric factorization.
Definition: Amesos2_Superlumt_def.hpp:193
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > ¶meterList)
Definition: Amesos2_Superlumt_def.hpp:422
~Superlumt()
Destructor.
Definition: Amesos2_Superlumt_def.hpp:102
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:339
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:142
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Superlumt_def.hpp:565