54 #ifndef AMESOS2_SHYLUBASKER_DEF_HPP
55 #define AMESOS2_SHYLUBASKER_DEF_HPP
57 #include <Teuchos_Tuple.hpp>
58 #include <Teuchos_ParameterList.hpp>
59 #include <Teuchos_StandardParameterEntryValidators.hpp>
67 template <
class Matrix,
class Vector>
68 ShyLUBasker<Matrix,Vector>::ShyLUBasker(
69 Teuchos::RCP<const Matrix> A,
70 Teuchos::RCP<Vector> X,
71 Teuchos::RCP<const Vector> B )
72 : SolverCore<Amesos2::ShyLUBasker,Matrix,Vector>(A, X, B)
76 , is_contiguous_(true)
83 #if defined(HAVE_AMESOS2_KOKKOS) && defined(KOKKOS_ENABLE_OPENMP)
88 typedef Kokkos::OpenMP Exe_Space;
90 ShyLUbasker = new ::BaskerNS::BaskerTrilinosInterface<local_ordinal_type, slu_type, Exe_Space>();
91 ShyLUbasker->Options.no_pivot = BASKER_TRUE;
92 ShyLUbasker->Options.symmetric = BASKER_FALSE;
93 ShyLUbasker->Options.realloc = BASKER_FALSE;
94 ShyLUbasker->Options.verbose = BASKER_FALSE;
95 ShyLUbasker->Options.matching = BASKER_TRUE;
96 ShyLUbasker->Options.matching_type = 0;
97 ShyLUbasker->Options.btf = BASKER_TRUE;
98 ShyLUbasker->Options.amd_btf = BASKER_TRUE;
99 ShyLUbasker->Options.amd_dom = BASKER_TRUE;
100 ShyLUbasker->Options.transpose = BASKER_FALSE;
101 ShyLUbasker->Options.verbose_matrix_out = BASKER_FALSE;
102 num_threads = Kokkos::OpenMP::max_hardware_threads();
104 TEUCHOS_TEST_FOR_EXCEPTION(1 != 0,
106 "Amesos2_ShyLUBasker Exception: Do not have supported Kokkos node type (OpenMP) enabled for ShyLUBasker");
111 template <
class Matrix,
class Vector>
112 ShyLUBasker<Matrix,Vector>::~ShyLUBasker( )
115 #if defined(HAVE_AMESOS2_KOKKOS) && defined(KOKKOS_ENABLE_OPENMP)
120 template <
class Matrix,
class Vector>
123 return (this->root_ && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_);
126 template<
class Matrix,
class Vector>
132 #ifdef HAVE_AMESOS2_TIMERS
133 Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
140 template <
class Matrix,
class Vector>
149 ShyLUbasker->SetThreads(num_threads);
151 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
152 std::cout <<
"ShyLUBasker:: Before symbolic factorization" << std::endl;
153 std::cout <<
"nzvals_ : " << nzvals_.toString() << std::endl;
154 std::cout <<
"rowind_ : " << rowind_.toString() << std::endl;
155 std::cout <<
"colptr_ : " << colptr_.toString() << std::endl;
163 if ( single_proc_optimization() ) {
166 auto sp_rowptr = this->matrixA_->returnRowPtr();
167 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
168 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
169 auto sp_colind = this->matrixA_->returnColInd();
170 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
171 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
172 #ifndef HAVE_TEUCHOS_COMPLEX
173 auto sp_values = this->matrixA_->returnValues();
177 using complex_type =
typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
178 complex_type * sp_values =
nullptr;
179 sp_values =
reinterpret_cast< complex_type *
> ( this->matrixA_->returnValues() );
181 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
182 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
185 info = ShyLUbasker->Symbolic(this->globalNumRows_,
186 this->globalNumCols_,
187 this->globalNumNonZeros_,
196 info = ShyLUbasker->Symbolic(this->globalNumRows_,
197 this->globalNumCols_,
198 this->globalNumNonZeros_,
201 nzvals_.getRawPtr());
203 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
204 std::runtime_error,
"Error in ShyLUBasker Symbolic");
213 template <
class Matrix,
class Vector>
222 #ifdef HAVE_AMESOS2_TIMERS
223 Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
226 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
227 std::cout <<
"ShyLUBasker:: Before numeric factorization" << std::endl;
228 std::cout <<
"nzvals_ : " << nzvals_.toString() << std::endl;
229 std::cout <<
"rowind_ : " << rowind_.toString() << std::endl;
230 std::cout <<
"colptr_ : " << colptr_.toString() << std::endl;
238 if ( single_proc_optimization() ) {
240 auto sp_rowptr = this->matrixA_->returnRowPtr();
241 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
242 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
243 auto sp_colind = this->matrixA_->returnColInd();
244 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
245 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
246 #ifndef HAVE_TEUCHOS_COMPLEX
247 auto sp_values = this->matrixA_->returnValues();
251 using complex_type =
typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
252 complex_type * sp_values =
nullptr;
253 sp_values =
reinterpret_cast< complex_type *
> ( this->matrixA_->returnValues() );
255 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
256 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
259 info = ShyLUbasker->Factor( this->globalNumRows_,
260 this->globalNumCols_,
261 this->globalNumNonZeros_,
269 info = ShyLUbasker->Factor(this->globalNumRows_,
270 this->globalNumCols_,
271 this->globalNumNonZeros_,
274 nzvals_.getRawPtr());
280 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
281 std::runtime_error,
"Error ShyLUBasker Factor");
283 local_ordinal_type blnnz = local_ordinal_type(0);
284 local_ordinal_type bunnz = local_ordinal_type(0);
285 ShyLUbasker->GetLnnz(blnnz);
286 ShyLUbasker->GetUnnz(bunnz);
290 this->setNnzLU( as<size_t>( blnnz + bunnz ) );
296 Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
300 TEUCHOS_TEST_FOR_EXCEPTION( (info == -1) ,
302 "ShyLUBasker: Could not alloc space for L and U");
303 TEUCHOS_TEST_FOR_EXCEPTION( (info == -2),
305 "ShyLUBasker: Could not alloc needed work space");
306 TEUCHOS_TEST_FOR_EXCEPTION( (info == -3) ,
308 "ShyLUBasker: Could not alloc additional memory needed for L and U");
309 TEUCHOS_TEST_FOR_EXCEPTION( (info > 0) ,
311 "ShyLUBasker: Zero pivot found at: " << info );
317 template <
class Matrix,
class Vector>
327 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
328 const size_t nrhs = X->getGlobalNumVectors();
330 if ( single_proc_optimization() && nrhs == 1 ) {
332 #ifdef HAVE_AMESOS2_TIMERS
333 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
336 #ifndef HAVE_TEUCHOS_COMPLEX
342 using complex_type =
typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
346 TEUCHOS_TEST_FOR_EXCEPTION(b_vector ==
nullptr,
347 std::runtime_error,
"Amesos2 Runtime Error: b_vector returned null ");
349 TEUCHOS_TEST_FOR_EXCEPTION(x_vector ==
nullptr,
350 std::runtime_error,
"Amesos2 Runtime Error: x_vector returned null ");
354 #ifdef HAVE_AMESOS2_TIMERS
355 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
357 ierr = ShyLUbasker->Solve(nrhs, b_vector, x_vector);
361 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
363 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
365 "Encountered zero diag element at: " << ierr);
366 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
368 "Could not alloc needed working memory for solve" );
373 const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
375 xvals_.resize(val_store_size);
376 bvals_.resize(val_store_size);
379 #ifdef HAVE_AMESOS2_TIMERS
380 Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
381 Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
384 if ( is_contiguous_ ==
true ) {
386 slu_type>::do_get(B, bvals_(), as<size_t>(ld_rhs), ROOTED, this->rowIndexBase_);
390 slu_type>::do_get(B, bvals_(), as<size_t>(ld_rhs), CONTIGUOUS_AND_ROOTED, this->rowIndexBase_);
396 #ifdef HAVE_AMESOS2_TIMERS
397 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
399 ierr = ShyLUbasker->Solve(nrhs, bvals_.getRawPtr(), xvals_.getRawPtr());
404 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
406 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
408 "Encountered zero diag element at: " << ierr);
409 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
411 "Could not alloc needed working memory for solve" );
414 #ifdef HAVE_AMESOS2_TIMERS
415 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
418 if ( is_contiguous_ ==
true ) {
428 CONTIGUOUS_AND_ROOTED);
437 template <
class Matrix,
class Vector>
442 return( this->globalNumRows_ == this->globalNumCols_ );
446 template <
class Matrix,
class Vector>
451 using Teuchos::getIntegralValue;
452 using Teuchos::ParameterEntryValidator;
454 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
456 if(parameterList->isParameter(
"IsContiguous"))
458 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
461 if(parameterList->isParameter(
"num_threads"))
463 num_threads = parameterList->get<
int>(
"num_threads");
465 if(parameterList->isParameter(
"pivot"))
467 ShyLUbasker->Options.no_pivot = (!parameterList->get<
bool>(
"pivot"));
469 if(parameterList->isParameter(
"pivot_tol"))
471 ShyLUbasker->Options.pivot_tol = parameterList->get<
double>(
"pivot_tol");
473 if(parameterList->isParameter(
"symmetric"))
475 ShyLUbasker->Options.symmetric = parameterList->get<
bool>(
"symmetric");
477 if(parameterList->isParameter(
"realloc"))
479 ShyLUbasker->Options.realloc = parameterList->get<
bool>(
"realloc");
481 if(parameterList->isParameter(
"verbose"))
483 ShyLUbasker->Options.verbose = parameterList->get<
bool>(
"verbose");
485 if(parameterList->isParameter(
"verbose_matrix"))
487 ShyLUbasker->Options.verbose_matrix_out = parameterList->get<
bool>(
"verbose_matrix");
489 if(parameterList->isParameter(
"matching"))
491 ShyLUbasker->Options.matching = parameterList->get<
bool>(
"matching");
493 if(parameterList->isParameter(
"matching_type"))
495 ShyLUbasker->Options.matching_type =
496 (local_ordinal_type) parameterList->get<
int>(
"matching_type");
498 if(parameterList->isParameter(
"btf"))
500 ShyLUbasker->Options.btf = parameterList->get<
bool>(
"btf");
502 if(parameterList->isParameter(
"amd_btf"))
504 ShyLUbasker->Options.amd_btf = parameterList->get<
bool>(
"amd_btf");
506 if(parameterList->isParameter(
"amd_dom"))
508 ShyLUbasker->Options.amd_dom = parameterList->get<
bool>(
"amd_dom");
510 if(parameterList->isParameter(
"transpose"))
512 ShyLUbasker->Options.transpose = parameterList->get<
bool>(
"transpose");
517 template <
class Matrix,
class Vector>
518 Teuchos::RCP<const Teuchos::ParameterList>
521 using Teuchos::ParameterList;
523 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
525 if( is_null(valid_params) )
527 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
528 pl->set(
"IsContiguous",
true,
529 "Are GIDs contiguous");
530 pl->set(
"num_threads", 1,
531 "Number of threads");
532 pl->set(
"pivot",
false,
534 pl->set(
"pivot_tol", .0001,
535 "Tolerance before pivot, currently not used");
536 pl->set(
"symmetric",
false,
537 "Should Symbolic assume symmetric nonzero pattern");
538 pl->set(
"realloc" ,
false,
539 "Should realloc space if not enough");
540 pl->set(
"verbose",
false,
541 "Information about factoring");
542 pl->set(
"verbose_matrix",
false,
543 "Give Permuted Matrices");
544 pl->set(
"matching",
true,
545 "Use WC matching (Not Supported)");
546 pl->set(
"matching_type", 0,
547 "Type of WC matching (Not Supported)");
550 pl->set(
"amd_btf",
true,
551 "Use AMD on BTF blocks (Not Supported)");
552 pl->set(
"amd_dom",
true,
553 "Use CAMD on ND blocks (Not Supported)");
554 pl->set(
"transpose",
false,
555 "Solve the transpose A");
562 template <
class Matrix,
class Vector>
567 if(current_phase == SOLVE)
return (
false);
569 #ifdef HAVE_AMESOS2_TIMERS
570 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
575 if ( single_proc_optimization() ) {
584 nzvals_.resize(this->globalNumNonZeros_);
585 rowind_.resize(this->globalNumNonZeros_);
586 colptr_.resize(this->globalNumCols_ + 1);
589 local_ordinal_type nnz_ret = 0;
591 #ifdef HAVE_AMESOS2_TIMERS
592 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
595 if ( is_contiguous_ ==
true ) {
598 ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
599 nnz_ret, ROOTED, ARBITRARY, this->rowIndexBase_);
604 ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
605 nnz_ret, CONTIGUOUS_AND_ROOTED, ARBITRARY, this->rowIndexBase_);
610 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
612 "Amesos2_ShyLUBasker loadA_impl: Did not get the expected number of non-zero vals");
620 template<
class Matrix,
class Vector>
626 #endif // AMESOS2_SHYLUBASKER_DEF_HPP
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
ShyLUBasker specific solve.
Definition: Amesos2_ShyLUBasker_def.hpp:319
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
Amesos2 interface to the Baker package.
Definition: Amesos2_ShyLUBasker_decl.hpp:76
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_ShyLUBasker_def.hpp:519
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:266
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_ShyLUBasker_def.hpp:128
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_ShyLUBasker_def.hpp:439
Helper struct for getting pointers to the MV data - only used when number of vectors = 1 and single M...
Definition: Amesos2_MultiVecAdapter_decl.hpp:218
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:654
Amesos2 ShyLUBasker declarations.
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_ShyLUBasker_def.hpp:564
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
int numericFactorization_impl()
ShyLUBasker specific numeric factorization.
Definition: Amesos2_ShyLUBasker_def.hpp:215
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:322
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176
bool single_proc_optimization() const
can we optimize size_type and ordinal_type for straight pass through, also check that is_contiguous_ ...
Definition: Amesos2_ShyLUBasker_def.hpp:122