52 #ifndef AMESOS2_SUPERLUDIST_DEF_HPP
53 #define AMESOS2_SUPERLUDIST_DEF_HPP
55 #include <Teuchos_Tuple.hpp>
56 #include <Teuchos_StandardParameterEntryValidators.hpp>
57 #include <Teuchos_DefaultMpiComm.hpp>
67 template <
class Matrix,
class Vector>
69 Teuchos::RCP<Vector> X,
70 Teuchos::RCP<const Vector> B)
83 int nprocs = this->
getComm()->getSize();
84 SLUD::int_t nprow, npcol;
86 data_.mat_comm =
dynamic_cast<const Teuchos::MpiComm<int>*
>(this->
matrixA_->getComm().getRawPtr())->getRawMpiComm()->operator()();
87 SLUD::superlu_gridinit(data_.mat_comm, nprow, npcol, &(data_.grid));
95 Teuchos::RCP<Teuchos::ParameterList> default_params
100 data_.options.Fact = SLUD::DOFACT;
101 data_.equed = SLUD::NOEQUIL;
102 data_.options.SolveInitialized = SLUD::NO;
103 data_.options.RefineInitialized = SLUD::NO;
104 data_.rowequ =
false;
105 data_.colequ =
false;
113 data_.symb_comm = MPI_COMM_NULL;
114 int color = MPI_UNDEFINED;
115 int my_rank = this->
rank_;
121 data_.domains = (int) ( pow(2.0, floor(log10((
double)nprow*npcol)/log10(2.0))) );
123 if( this->
rank_ < data_.domains ) color = 0;
124 MPI_Comm_split (data_.mat_comm, color, my_rank, &(data_.symb_comm));
132 if( this->
rank_ < nprow * npcol ){
138 = Tpetra::createWeightedContigMapWithNode<local_ordinal_type,
140 node_type>(my_weight,
143 Kokkos::DefaultNode::getDefaultNode());
152 data_.A.Store = NULL;
153 function_map::LUstructInit(this->globalNumRows_, this->
globalNumCols_, &(data_.lu));
154 SLUD::PStatInit(&(data_.stat));
157 data_.scale_perm.perm_r = data_.perm_r.getRawPtr();
158 data_.scale_perm.perm_c = data_.perm_c.getRawPtr();
162 template <
class Matrix,
class Vector>
174 if ( this->status_.getNumPreOrder() > 0 ){
176 free( data_.fstVtxSep );
181 if( data_.A.Store != NULL ){
182 SLUD::Destroy_SuperMatrix_Store_dist( &(data_.A) );
186 if ( this->status_.getNumNumericFact() > 0 ){
187 function_map::Destroy_LU(this->globalNumRows_, &(data_.grid), &(data_.lu));
189 function_map::LUstructFree(&(data_.lu));
195 if ( this->status_.symbolicFactorizationDone() &&
196 !this->status_.numericFactorizationDone() ){
197 if ( data_.pslu_freeable.xlsub != NULL ){
198 free( data_.pslu_freeable.xlsub );
199 free( data_.pslu_freeable.lsub );
201 if ( data_.pslu_freeable.xusub != NULL ){
202 free( data_.pslu_freeable.xusub );
203 free( data_.pslu_freeable.usub );
205 if ( data_.pslu_freeable.supno_loc != NULL ){
206 free( data_.pslu_freeable.supno_loc );
207 free( data_.pslu_freeable.xsup_beg_loc );
208 free( data_.pslu_freeable.xsup_end_loc );
210 free( data_.pslu_freeable.globToLoc );
213 SLUD::PStatFree( &(data_.stat) ) ;
218 if ( data_.options.SolveInitialized == SLUD::YES )
219 function_map::SolveFinalize(&(data_.options), &(data_.solve_struct));
221 SLUD::superlu_gridexit(&(data_.grid));
225 if ( data_.symb_comm != MPI_COMM_NULL ) MPI_Comm_free(&(data_.symb_comm));
228 template<
class Matrix,
class Vector>
237 SLUD::int_t slu_rows_ub = Teuchos::as<SLUD::int_t>(this->globalNumRows_);
238 for( SLUD::int_t i = 0; i < slu_rows_ub; ++i ) data_.perm_r[i] = i;
248 if( this->status_.getNumPreOrder() > 0 ){
250 free( data_.fstVtxSep );
252 #ifdef HAVE_AMESOS2_TIMERS
253 Teuchos::TimeMonitor preOrderTime( this->timers_.preOrderTime_ );
257 info = SLUD::get_perm_c_parmetis( &(data_.A),
258 data_.perm_r.getRawPtr(), data_.perm_c.getRawPtr(),
259 data_.grid.nprow * data_.grid.npcol, data_.domains,
260 &(data_.sizes), &(data_.fstVtxSep),
261 &(data_.grid), &(data_.symb_comm) );
263 TEUCHOS_TEST_FOR_EXCEPTION( info > 0.0,
265 "SuperLU_DIST pre-ordering ran out of memory after allocating "
266 << info <<
" bytes of memory" );
278 template <
class Matrix,
class Vector>
286 #ifdef HAVE_AMESOS2_TIMERS
287 Teuchos::TimeMonitor symFactTime( this->timers_.symFactTime_ );
291 info = SLUD::symbfact_dist((data_.grid.nprow) * (data_.grid.npcol),
292 data_.domains, &(data_.A), data_.perm_c.getRawPtr(),
293 data_.perm_r.getRawPtr(), data_.sizes,
294 data_.fstVtxSep, &(data_.pslu_freeable),
295 &(data_.grid.comm), &(data_.symb_comm),
298 TEUCHOS_TEST_FOR_EXCEPTION( info > 0.0,
300 "SuperLU_DIST symbolic factorization ran out of memory after"
301 " allocating " << info <<
" bytes of memory" );
303 same_symbolic_ =
false;
304 same_solve_struct_ =
false;
310 template <
class Matrix,
class Vector>
329 size_t nnz_loc = ((SLUD::NRformat_loc*)data_.A.Store)->nnz_loc;
330 for(
size_t i = 0; i < nnz_loc; ++i ) colind_[i] = data_.perm_c[colind_[i]];
333 if( same_symbolic_ ){
338 function_map::pdistribute(SLUD::SamePattern_SameRowPerm,
339 as<SLUD::int_t>(this->globalNumRows_),
340 &(data_.A), &(data_.scale_perm),
341 &(data_.glu_freeable), &(data_.lu),
344 function_map::dist_psymbtonum(SLUD::DOFACT,
345 as<SLUD::int_t>(this->globalNumRows_),
346 &(data_.A), &(data_.scale_perm),
347 &(data_.pslu_freeable), &(data_.lu),
352 double anorm = function_map::plangs((
char *)
"I", &(data_.A), &(data_.grid));
356 #ifdef HAVE_AMESOS2_TIMERS
357 Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
360 function_map::gstrf(&(data_.options), this->globalNumRows_,
361 this->globalNumCols_, anorm, &(data_.lu),
362 &(data_.grid), &(data_.stat), &info);
366 TEUCHOS_TEST_FOR_EXCEPTION( info > 0,
368 "L and U factors have been computed but U("
369 << info <<
"," << info <<
") is exactly zero "
370 "(i.e. U is singular)");
377 data_.options.Fact = SLUD::FACTORED;
378 same_symbolic_ =
true;
384 template <
class Matrix,
class Vector>
393 const size_t local_len_rhs = superlu_rowmap_->getNodeNumElements();
394 const global_size_type nrhs = X->getGlobalNumVectors();
395 const global_ordinal_type first_global_row_b = superlu_rowmap_->getMinGlobalIndex();
398 bvals_.resize(nrhs * local_len_rhs);
399 xvals_.resize(nrhs * local_len_rhs);
405 #ifdef HAVE_AMESOS2_TIMERS
406 Teuchos::TimeMonitor convTimer(this->timers_.vecConvTime_);
416 #ifdef HAVE_AMESOS2_TIMERS
417 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
423 copy_helper::do_get(B,
426 Teuchos::ptrInArg(*superlu_rowmap_));
447 if( !same_solve_struct_ ){
448 if( data_.options.SolveInitialized == SLUD::YES ){
449 function_map::SolveFinalize(&(data_.options), &(data_.solve_struct));
451 function_map::SolveInit(&(data_.options), &(data_.A), data_.perm_r.getRawPtr(),
452 data_.perm_c.getRawPtr(), as<SLUD::int_t>(nrhs), &(data_.lu),
453 &(data_.grid), &(data_.solve_struct));
457 same_solve_struct_ =
true;
462 #ifdef HAVE_AMESOS2_TIMERS
463 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
466 function_map::gstrs(as<SLUD::int_t>(this->globalNumRows_), &(data_.lu),
467 &(data_.scale_perm), &(data_.grid), bvals_.getRawPtr(),
468 as<SLUD::int_t>(local_len_rhs), as<SLUD::int_t>(first_global_row_b),
469 as<SLUD::int_t>(local_len_rhs), as<int>(nrhs),
470 &(data_.solve_struct), &(data_.stat), &ierr);
473 TEUCHOS_TEST_FOR_EXCEPTION( ierr < 0,
475 "Argument " << -ierr <<
" to gstrs had an illegal value" );
490 #ifdef HAVE_AMESOS2_TIMERS
491 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
493 SLUD::int_t ld = as<SLUD::int_t>(local_len_rhs);
494 function_map::permute_Dense_Matrix(as<SLUD::int_t>(first_global_row_b),
495 as<SLUD::int_t>(local_len_rhs),
496 data_.solve_struct.row_to_proc,
497 data_.solve_struct.inv_perm_c,
498 bvals_.getRawPtr(), ld,
499 xvals_.getRawPtr(), ld,
507 #ifdef HAVE_AMESOS2_TIMERS
508 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
512 put_helper::do_put(X,
515 Teuchos::ptrInArg(*superlu_rowmap_));
522 template <
class Matrix,
class Vector>
527 return( this->globalNumRows_ == this->globalNumCols_ );
531 template <
class Matrix,
class Vector>
537 using Teuchos::getIntegralValue;
538 using Teuchos::ParameterEntryValidator;
540 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
542 if( parameterList->isParameter(
"npcol") || parameterList->isParameter(
"nprow") ){
543 TEUCHOS_TEST_FOR_EXCEPTION( !(parameterList->isParameter(
"nprow") &&
544 parameterList->isParameter(
"npcol")),
545 std::invalid_argument,
546 "nprow and npcol must be set together" );
548 SLUD::int_t nprow = parameterList->template get<SLUD::int_t>(
"nprow");
549 SLUD::int_t npcol = parameterList->template get<SLUD::int_t>(
"npcol");
551 TEUCHOS_TEST_FOR_EXCEPTION( nprow * npcol > this->getComm()->getSize(),
552 std::invalid_argument,
553 "nprow and npcol combination invalid" );
555 if( (npcol != data_.grid.npcol) || (nprow != data_.grid.nprow) ){
557 SLUD::superlu_gridexit(&(data_.grid));
559 SLUD::superlu_gridinit(data_.mat_comm, nprow, npcol, &(data_.grid));
563 TEUCHOS_TEST_FOR_EXCEPTION( this->control_.useTranspose_,
564 std::invalid_argument,
565 "SuperLU_DIST does not support solving the tranpose system" );
567 data_.options.Trans = SLUD::NOTRANS;
572 data_.options.Equil = SLUD::NO;
574 if( parameterList->isParameter(
"ColPerm") ){
575 RCP<const ParameterEntryValidator> colperm_validator = valid_params->getEntry(
"ColPerm").validator();
576 parameterList->getEntry(
"ColPerm").setValidator(colperm_validator);
578 data_.options.ColPerm = getIntegralValue<SLUD::colperm_t>(*parameterList,
"ColPerm");
585 data_.options.RowPerm = SLUD::NOROWPERM;
594 data_.options.IterRefine = SLUD::NOREFINE;
596 bool replace_tiny = parameterList->get<
bool>(
"ReplaceTinyPivot",
true);
597 data_.options.ReplaceTinyPivot = replace_tiny ? SLUD::YES : SLUD::NO;
601 template <
class Matrix,
class Vector>
602 Teuchos::RCP<const Teuchos::ParameterList>
606 using Teuchos::tuple;
607 using Teuchos::ParameterList;
608 using Teuchos::EnhancedNumberValidator;
609 using Teuchos::setStringToIntegralParameter;
610 using Teuchos::stringToIntegralParameterEntryValidator;
612 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
614 if( is_null(valid_params) ){
615 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
617 Teuchos::RCP<EnhancedNumberValidator<SLUD::int_t> > col_row_validator
618 = Teuchos::rcp(
new EnhancedNumberValidator<SLUD::int_t>() );
619 col_row_validator->setMin(1);
621 pl->set(
"npcol", data_.grid.npcol,
622 "Number of columns in the processor grid. "
623 "Must be set with nprow", col_row_validator);
624 pl->set(
"nprow", data_.grid.nprow,
625 "Number of rows in the SuperLU_DIST processor grid. "
626 "Must be set together with npcol", col_row_validator);
629 setStringToIntegralParameter<SLUD::trans_t>(
"Trans",
"NOTRANS",
630 "Solve for the transpose system or not",
631 tuple<string>(
"NOTRANS"),
632 tuple<string>(
"Do not solve with transpose"),
633 tuple<SLUD::trans_t>(SLUD::NOTRANS),
649 pl->set(
"ReplaceTinyPivot",
true,
650 "Specifies whether to replace tiny diagonals during LU factorization");
652 setStringToIntegralParameter<SLUD::colperm_t>(
"ColPerm",
"PARMETIS",
653 "Specifies how to permute the columns of the "
654 "matrix for sparsity preservation",
655 tuple<string>(
"NATURAL",
"PARMETIS"),
656 tuple<string>(
"Natural ordering",
657 "ParMETIS ordering on A^T + A"),
658 tuple<SLUD::colperm_t>(SLUD::NATURAL,
669 template <
class Matrix,
class Vector>
673 SLUD::int_t& npcol)
const {
674 TEUCHOS_TEST_FOR_EXCEPTION( nprocs < 1,
675 std::invalid_argument,
676 "Number of MPI processes must be at least 1" );
677 SLUD::int_t c, r = 1;
678 while( r*r <= nprocs ) r++;
681 while( (r--)*c != nprocs ){
687 if( r > 1 || nprocs < 9){
694 template <
class Matrix,
class Vector>
698 using Teuchos::Array;
699 using Teuchos::ArrayView;
700 using Teuchos::ptrInArg;
705 #ifdef HAVE_AMESOS2_TIMERS
706 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
710 if( data_.A.Store != NULL ){
711 SLUD::Destroy_SuperMatrix_Store_dist( &(data_.A) );
712 data_.A.Store = NULL;
715 Teuchos::RCP<const MatrixAdapter<Matrix> > redist_mat
716 = this->matrixA_->get(ptrInArg(*superlu_rowmap_));
718 int_t l_nnz, l_rows, g_rows, g_cols, fst_global_row;
719 l_nnz = as<int_t>(redist_mat->getLocalNNZ());
720 l_rows = as<int_t>(redist_mat->getLocalNumRows());
721 g_rows = as<int_t>(redist_mat->getGlobalNumRows());
723 fst_global_row = as<int_t>(superlu_rowmap_->getMinGlobalIndex());
725 nzvals_.resize(l_nnz);
726 colind_.resize(l_nnz);
727 rowptr_.resize(l_rows + 1);
731 #ifdef HAVE_AMESOS2_TIMERS
732 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
737 slu_type, int_t, int_t >::do_get(redist_mat.ptr(),
738 nzvals_(), colind_(), rowptr_(),
740 ptrInArg(*superlu_rowmap_),
744 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != l_nnz,
746 "Did not get the expected number of non-zero vals");
749 SLUD::Dtype_t dtype = type_map::dtype;
752 function_map::create_CompRowLoc_Matrix(&(data_.A),
754 l_nnz, l_rows, fst_global_row,
759 dtype, SLUD::SLU_GE);
766 template<
class Matrix,
class Vector>
772 #endif // AMESOS2_SUPERLUDIST_DEF_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
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
Similar to get_ccs_helper , but used to get a CRS representation of the given matrix.
Definition: Amesos2_Util.hpp:586
global_size_type globalNumCols_
Number of global columns in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:476
Superludist(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Initialize from Teuchos::RCP.
Definition: Amesos2_Superludist_def.hpp:68
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > ¶meterList)
Definition: Amesos2_Superludist_def.hpp:533
global_size_type globalNumRows_
Number of global rows in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:473
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:243
Utility functions for Amesos2.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Superludist_def.hpp:603
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a const parameter list of all of the valid parameters that this->setParameterList(...) will accept.
Definition: Amesos2_SolverCore_def.hpp:307
Provides definition of SuperLU_DIST types as well as conversions and type traits. ...
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Superludist_def.hpp:230
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
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Superludist_def.hpp:524
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:327
~Superludist()
Destructor.
Definition: Amesos2_Superludist_def.hpp:163
super_type & setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶meterList)
Set/update internal variables and solver options.
Definition: Amesos2_SolverCore_def.hpp:275
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using SuperLU_DIST.
Definition: Amesos2_Superludist_def.hpp:280
int rank_
The MPI rank of this image.
Definition: Amesos2_SolverCore_decl.hpp:501
void get_default_grid_size(int nprocs, SLUD::int_t &nprow, SLUD::int_t &npcol) const
Definition: Amesos2_Superludist_def.hpp:671
bool in_grid_
true if this processor is in SuperLU_DISTS's 2D process grid
Definition: Amesos2_Superludist_decl.hpp:320
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:292
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:386
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:175
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal solver structures.
Definition: Amesos2_Superludist_def.hpp:696
Teuchos::RCP< const MatrixAdapter< Matrix > > matrixA_
The LHS operator.
Definition: Amesos2_SolverCore_decl.hpp:452
int numericFactorization_impl()
SuperLU_DIST specific numeric factorization.
Definition: Amesos2_Superludist_def.hpp:312