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 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
103 num_threads = Kokkos::OpenMP::max_hardware_threads();
105 num_threads = Kokkos::OpenMP::impl_max_hardware_threads();
108 TEUCHOS_TEST_FOR_EXCEPTION(1 != 0,
110 "Amesos2_ShyLUBasker Exception: Do not have supported Kokkos node type (OpenMP) enabled for ShyLUBasker");
115 template <
class Matrix,
class Vector>
116 ShyLUBasker<Matrix,Vector>::~ShyLUBasker( )
119 #if defined(HAVE_AMESOS2_KOKKOS) && defined(KOKKOS_ENABLE_OPENMP)
124 template <
class Matrix,
class Vector>
127 return (this->root_ && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_);
130 template<
class Matrix,
class Vector>
136 #ifdef HAVE_AMESOS2_TIMERS
137 Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
144 template <
class Matrix,
class Vector>
153 ShyLUbasker->SetThreads(num_threads);
155 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
156 std::cout <<
"ShyLUBasker:: Before symbolic factorization" << std::endl;
157 std::cout <<
"nzvals_ : " << nzvals_.toString() << std::endl;
158 std::cout <<
"rowind_ : " << rowind_.toString() << std::endl;
159 std::cout <<
"colptr_ : " << colptr_.toString() << std::endl;
167 if ( single_proc_optimization() ) {
170 auto sp_rowptr = this->matrixA_->returnRowPtr();
171 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
172 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
173 auto sp_colind = this->matrixA_->returnColInd();
174 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
175 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
176 #ifndef HAVE_TEUCHOS_COMPLEX
177 auto sp_values = this->matrixA_->returnValues();
181 using complex_type =
typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
182 complex_type * sp_values =
nullptr;
183 sp_values =
reinterpret_cast< complex_type *
> ( this->matrixA_->returnValues() );
185 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
186 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
189 info = ShyLUbasker->Symbolic(this->globalNumRows_,
190 this->globalNumCols_,
191 this->globalNumNonZeros_,
200 info = ShyLUbasker->Symbolic(this->globalNumRows_,
201 this->globalNumCols_,
202 this->globalNumNonZeros_,
205 nzvals_.getRawPtr());
207 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
208 std::runtime_error,
"Error in ShyLUBasker Symbolic");
217 template <
class Matrix,
class Vector>
226 #ifdef HAVE_AMESOS2_TIMERS
227 Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
230 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
231 std::cout <<
"ShyLUBasker:: Before numeric factorization" << std::endl;
232 std::cout <<
"nzvals_ : " << nzvals_.toString() << std::endl;
233 std::cout <<
"rowind_ : " << rowind_.toString() << std::endl;
234 std::cout <<
"colptr_ : " << colptr_.toString() << std::endl;
242 if ( single_proc_optimization() ) {
244 auto sp_rowptr = this->matrixA_->returnRowPtr();
245 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
246 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
247 auto sp_colind = this->matrixA_->returnColInd();
248 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
249 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
250 #ifndef HAVE_TEUCHOS_COMPLEX
251 auto sp_values = this->matrixA_->returnValues();
255 using complex_type =
typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
256 complex_type * sp_values =
nullptr;
257 sp_values =
reinterpret_cast< complex_type *
> ( this->matrixA_->returnValues() );
259 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
260 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
263 info = ShyLUbasker->Factor( this->globalNumRows_,
264 this->globalNumCols_,
265 this->globalNumNonZeros_,
273 info = ShyLUbasker->Factor(this->globalNumRows_,
274 this->globalNumCols_,
275 this->globalNumNonZeros_,
278 nzvals_.getRawPtr());
284 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
285 std::runtime_error,
"Error ShyLUBasker Factor");
287 local_ordinal_type blnnz = local_ordinal_type(0);
288 local_ordinal_type bunnz = local_ordinal_type(0);
289 ShyLUbasker->GetLnnz(blnnz);
290 ShyLUbasker->GetUnnz(bunnz);
294 this->setNnzLU( as<size_t>( blnnz + bunnz ) );
300 Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
304 TEUCHOS_TEST_FOR_EXCEPTION( (info == -1) ,
306 "ShyLUBasker: Could not alloc space for L and U");
307 TEUCHOS_TEST_FOR_EXCEPTION( (info == -2),
309 "ShyLUBasker: Could not alloc needed work space");
310 TEUCHOS_TEST_FOR_EXCEPTION( (info == -3) ,
312 "ShyLUBasker: Could not alloc additional memory needed for L and U");
313 TEUCHOS_TEST_FOR_EXCEPTION( (info > 0) ,
315 "ShyLUBasker: Zero pivot found at: " << info );
321 template <
class Matrix,
class Vector>
331 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
332 const size_t nrhs = X->getGlobalNumVectors();
334 if ( single_proc_optimization() && nrhs == 1 ) {
336 #ifdef HAVE_AMESOS2_TIMERS
337 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
340 #ifndef HAVE_TEUCHOS_COMPLEX
346 using complex_type =
typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
350 TEUCHOS_TEST_FOR_EXCEPTION(b_vector ==
nullptr,
351 std::runtime_error,
"Amesos2 Runtime Error: b_vector returned null ");
353 TEUCHOS_TEST_FOR_EXCEPTION(x_vector ==
nullptr,
354 std::runtime_error,
"Amesos2 Runtime Error: x_vector returned null ");
358 #ifdef HAVE_AMESOS2_TIMERS
359 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
361 ierr = ShyLUbasker->Solve(nrhs, b_vector, x_vector);
365 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
367 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
369 "Encountered zero diag element at: " << ierr);
370 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
372 "Could not alloc needed working memory for solve" );
377 const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
379 xvals_.resize(val_store_size);
380 bvals_.resize(val_store_size);
383 #ifdef HAVE_AMESOS2_TIMERS
384 Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
385 Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
388 if ( is_contiguous_ ==
true ) {
390 slu_type>::do_get(B, bvals_(), as<size_t>(ld_rhs), ROOTED, this->rowIndexBase_);
394 slu_type>::do_get(B, bvals_(), as<size_t>(ld_rhs), CONTIGUOUS_AND_ROOTED, this->rowIndexBase_);
400 #ifdef HAVE_AMESOS2_TIMERS
401 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
403 ierr = ShyLUbasker->Solve(nrhs, bvals_.getRawPtr(), xvals_.getRawPtr());
408 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
410 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
412 "Encountered zero diag element at: " << ierr);
413 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
415 "Could not alloc needed working memory for solve" );
418 #ifdef HAVE_AMESOS2_TIMERS
419 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
422 if ( is_contiguous_ ==
true ) {
432 CONTIGUOUS_AND_ROOTED);
441 template <
class Matrix,
class Vector>
446 return( this->globalNumRows_ == this->globalNumCols_ );
450 template <
class Matrix,
class Vector>
455 using Teuchos::getIntegralValue;
456 using Teuchos::ParameterEntryValidator;
458 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
460 if(parameterList->isParameter(
"IsContiguous"))
462 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
465 if(parameterList->isParameter(
"num_threads"))
467 num_threads = parameterList->get<
int>(
"num_threads");
469 if(parameterList->isParameter(
"pivot"))
471 ShyLUbasker->Options.no_pivot = (!parameterList->get<
bool>(
"pivot"));
473 if(parameterList->isParameter(
"pivot_tol"))
475 ShyLUbasker->Options.pivot_tol = parameterList->get<
double>(
"pivot_tol");
477 if(parameterList->isParameter(
"symmetric"))
479 ShyLUbasker->Options.symmetric = parameterList->get<
bool>(
"symmetric");
481 if(parameterList->isParameter(
"realloc"))
483 ShyLUbasker->Options.realloc = parameterList->get<
bool>(
"realloc");
485 if(parameterList->isParameter(
"verbose"))
487 ShyLUbasker->Options.verbose = parameterList->get<
bool>(
"verbose");
489 if(parameterList->isParameter(
"verbose_matrix"))
491 ShyLUbasker->Options.verbose_matrix_out = parameterList->get<
bool>(
"verbose_matrix");
493 if(parameterList->isParameter(
"matching"))
495 ShyLUbasker->Options.matching = parameterList->get<
bool>(
"matching");
497 if(parameterList->isParameter(
"matching_type"))
499 ShyLUbasker->Options.matching_type =
500 (local_ordinal_type) parameterList->get<
int>(
"matching_type");
502 if(parameterList->isParameter(
"btf"))
504 ShyLUbasker->Options.btf = parameterList->get<
bool>(
"btf");
506 if(parameterList->isParameter(
"amd_btf"))
508 ShyLUbasker->Options.amd_btf = parameterList->get<
bool>(
"amd_btf");
510 if(parameterList->isParameter(
"amd_dom"))
512 ShyLUbasker->Options.amd_dom = parameterList->get<
bool>(
"amd_dom");
514 if(parameterList->isParameter(
"transpose"))
516 ShyLUbasker->Options.transpose = parameterList->get<
bool>(
"transpose");
521 template <
class Matrix,
class Vector>
522 Teuchos::RCP<const Teuchos::ParameterList>
525 using Teuchos::ParameterList;
527 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
529 if( is_null(valid_params) )
531 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
532 pl->set(
"IsContiguous",
true,
533 "Are GIDs contiguous");
534 pl->set(
"num_threads", 1,
535 "Number of threads");
536 pl->set(
"pivot",
false,
538 pl->set(
"pivot_tol", .0001,
539 "Tolerance before pivot, currently not used");
540 pl->set(
"symmetric",
false,
541 "Should Symbolic assume symmetric nonzero pattern");
542 pl->set(
"realloc" ,
false,
543 "Should realloc space if not enough");
544 pl->set(
"verbose",
false,
545 "Information about factoring");
546 pl->set(
"verbose_matrix",
false,
547 "Give Permuted Matrices");
548 pl->set(
"matching",
true,
549 "Use WC matching (Not Supported)");
550 pl->set(
"matching_type", 0,
551 "Type of WC matching (Not Supported)");
554 pl->set(
"amd_btf",
true,
555 "Use AMD on BTF blocks (Not Supported)");
556 pl->set(
"amd_dom",
true,
557 "Use CAMD on ND blocks (Not Supported)");
558 pl->set(
"transpose",
false,
559 "Solve the transpose A");
566 template <
class Matrix,
class Vector>
571 if(current_phase == SOLVE)
return (
false);
573 #ifdef HAVE_AMESOS2_TIMERS
574 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
579 if ( single_proc_optimization() ) {
588 nzvals_.resize(this->globalNumNonZeros_);
589 rowind_.resize(this->globalNumNonZeros_);
590 colptr_.resize(this->globalNumCols_ + 1);
593 local_ordinal_type nnz_ret = 0;
595 #ifdef HAVE_AMESOS2_TIMERS
596 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
599 if ( is_contiguous_ ==
true ) {
602 ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
603 nnz_ret, ROOTED, ARBITRARY, this->rowIndexBase_);
608 ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
609 nnz_ret, CONTIGUOUS_AND_ROOTED, ARBITRARY, this->rowIndexBase_);
614 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
616 "Amesos2_ShyLUBasker loadA_impl: Did not get the expected number of non-zero vals");
624 template<
class Matrix,
class Vector>
630 #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:323
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:523
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:132
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_ShyLUBasker_def.hpp:443
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:765
Amesos2 ShyLUBasker declarations.
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_ShyLUBasker_def.hpp:568
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
int numericFactorization_impl()
ShyLUBasker specific numeric factorization.
Definition: Amesos2_ShyLUBasker_def.hpp:219
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:344
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:126