53 #ifndef AMESOS2_BASKER_DEF_HPP 54 #define AMESOS2_BASKER_DEF_HPP 56 #include <Teuchos_Tuple.hpp> 57 #include <Teuchos_ParameterList.hpp> 58 #include <Teuchos_StandardParameterEntryValidators.hpp> 66 template <
class Matrix,
class Vector>
67 Basker<Matrix,Vector>::Basker(
68 Teuchos::RCP<const Matrix> A,
69 Teuchos::RCP<Vector> X,
70 Teuchos::RCP<const Vector> B )
75 , is_contiguous_(true)
85 #ifdef HAVE_AMESOS2_KOKKOS 86 #ifdef KOKKOS_HAVE_OPENMP 91 typedef Kokkos::OpenMP Exe_Space;
92 #elif defined(KOKKOS_HAVE_SERIAL) 93 typedef Kokkos::Serial Exe_Space;
95 TEUCHOS_TEST_FOR_EXCEPTION(1 != 0,
97 "Amesos2_Basker Exception: Do not have supported Kokkos node type for Basker");
99 basker = new ::BaskerNS::BaskerTrilinosInterface<local_ordinal_type, slu_type, Exe_Space>();
100 basker->Options.no_pivot = BASKER_TRUE;
101 basker->Options.symmetric = BASKER_FALSE;
102 basker->Options.realloc = BASKER_FALSE;
103 basker->Options.verbose = BASKER_FALSE;
104 basker->Options.matching = BASKER_TRUE;
105 basker->Options.matching_type = 0;
106 basker->Options.btf = BASKER_TRUE;
107 basker->Options.amd_btf = BASKER_TRUE;
108 basker->Options.amd_dom = BASKER_TRUE;
109 basker->Options.transpose = BASKER_FALSE;
110 basker->Options.verbose_matrix_out = BASKER_FALSE;
111 num_threads = Kokkos::OpenMP::max_hardware_threads();
118 template <
class Matrix,
class Vector>
119 Basker<Matrix,Vector>::~Basker( )
122 #ifdef HAVE_AMESOS2_KOKKOS 130 template<
class Matrix,
class Vector>
136 #ifdef HAVE_AMESOS2_TIMERS 137 Teuchos::TimeMonitor preOrderTimer(this->
timers_.preOrderTime_);
144 template <
class Matrix,
class Vector>
156 basker->SetThreads(num_threads);
159 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG 160 std::cout <<
"Basker:: Before symbolic factorization" << std::endl;
161 std::cout <<
"nzvals_ : " <<
nzvals_.toString() << std::endl;
162 std::cout <<
"rowind_ : " <<
rowind_.toString() << std::endl;
163 std::cout <<
"colptr_ : " <<
colptr_.toString() << std::endl;
171 #ifndef HAVE_TEUCHOS_COMPLEX 172 bool case_check = ( (this->
matrixA_->getComm()->getRank() == 0) && (this->
matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
176 auto sp_rowptr = this->
matrixA_->returnRowPtr();
177 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
178 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
179 auto sp_colind = this->
matrixA_->returnColInd();
180 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
181 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
182 auto sp_values = this->
matrixA_->returnValues();
183 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
184 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
206 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
207 std::runtime_error,
"Error in Basker 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 <<
"Basker:: 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;
244 #ifndef HAVE_TEUCHOS_COMPLEX 245 bool case_check = ( (this->
matrixA_->getComm()->getRank() == 0) && (this->
matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
248 auto sp_rowptr = this->
matrixA_->returnRowPtr();
249 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
250 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
251 auto sp_colind = this->
matrixA_->returnColInd();
252 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
253 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
254 auto sp_values = this->
matrixA_->returnValues();
255 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
256 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
281 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
282 std::runtime_error,
"Error Basker Factor");
284 local_ordinal_type blnnz = local_ordinal_type(0);
285 local_ordinal_type bunnz = local_ordinal_type(0);
286 basker->GetLnnz(blnnz);
287 basker->GetUnnz(bunnz);
291 this->
setNnzLU( as<size_t>( blnnz + bunnz ) );
298 this->
setNnzLU( as<size_t>(basker.get_NnzLU() ) ) ;
306 Teuchos::broadcast(*(this->
matrixA_->getComm()), 0, &info);
310 TEUCHOS_TEST_FOR_EXCEPTION( (info == -1) ,
312 "Basker: Could not alloc space for L and U");
313 TEUCHOS_TEST_FOR_EXCEPTION( (info == -2),
315 "Basker: Could not alloc needed work space");
316 TEUCHOS_TEST_FOR_EXCEPTION( (info == -3) ,
318 "Basker: Could not alloc additional memory needed for L and U");
319 TEUCHOS_TEST_FOR_EXCEPTION( (info > 0) ,
321 "Basker: Zero pivot found at: " << info );
327 template <
class Matrix,
class Vector>
337 const global_size_type ld_rhs = this->
root_ ? X->getGlobalLength() : 0;
338 const size_t nrhs = X->getGlobalNumVectors();
340 #ifndef HAVE_TEUCHOS_COMPLEX 341 bool case_check = ( (this->
matrixA_->getComm()->getRank() == 0) && (this->
matrixA_->getComm()->getSize() == 1) && (nrhs == 1 ) && is_contiguous_ ) ;
344 #ifdef HAVE_AMESOS2_TIMERS 345 Teuchos::TimeMonitor solveTimer(this->
timers_.solveTime_);
348 auto sp_rowptr = this->
matrixA_->returnRowPtr();
349 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
350 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
351 auto sp_colind = this->
matrixA_->returnColInd();
352 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
353 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
354 auto sp_values = this->
matrixA_->returnValues();
355 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
356 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
359 TEUCHOS_TEST_FOR_EXCEPTION(b_vector ==
nullptr,
360 std::runtime_error,
"Amesos2 Runtime Error: b_vector returned null ");
362 TEUCHOS_TEST_FOR_EXCEPTION(x_vector ==
nullptr,
363 std::runtime_error,
"Amesos2 Runtime Error: x_vector returned null ");
367 #ifdef HAVE_AMESOS2_TIMERS 368 Teuchos::TimeMonitor solveTimer(this->
timers_.solveTime_);
372 ierr = basker->Solve(nrhs, b_vector, x_vector);
374 ierr = basker.solveMultiple(nrhs, b_vector, x_vector);
379 Teuchos::broadcast(*(this->
getComm()), 0, &ierr);
381 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
383 "Encountered zero diag element at: " << ierr);
384 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
386 "Could not alloc needed working memory for solve" );
392 const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
394 xvals_.resize(val_store_size);
395 bvals_.resize(val_store_size);
398 #ifdef HAVE_AMESOS2_TIMERS 399 Teuchos::TimeMonitor mvConvTimer(this->
timers_.vecConvTime_);
400 Teuchos::TimeMonitor redistTimer( this->
timers_.vecRedistTime_ );
403 if ( is_contiguous_ ==
true ) {
415 #ifdef HAVE_AMESOS2_TIMERS 416 Teuchos::TimeMonitor solveTimer(this->
timers_.solveTime_);
420 ierr = basker->Solve(nrhs,
bvals_.getRawPtr(),
423 ierr = basker.solveMultiple(nrhs,
bvals_.getRawPtr(),
xvals_.getRawPtr());
430 Teuchos::broadcast(*(this->
getComm()), 0, &ierr);
432 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
434 "Encountered zero diag element at: " << ierr);
435 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
437 "Could not alloc needed working memory for solve" );
440 #ifdef HAVE_AMESOS2_TIMERS 441 Teuchos::TimeMonitor redistTimer(this->
timers_.vecRedistTime_);
444 if ( is_contiguous_ ==
true ) {
463 template <
class Matrix,
class Vector>
472 template <
class Matrix,
class Vector>
477 using Teuchos::getIntegralValue;
478 using Teuchos::ParameterEntryValidator;
482 if(parameterList->isParameter(
"IsContiguous"))
484 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
488 if(parameterList->isParameter(
"num_threads"))
490 num_threads = parameterList->get<
int>(
"num_threads");
492 if(parameterList->isParameter(
"pivot"))
494 basker->Options.no_pivot = (!parameterList->get<
bool>(
"pivot"));
496 if(parameterList->isParameter(
"pivot_tol"))
498 basker->Options.pivot_tol = parameterList->get<
double>(
"pivot_tol");
500 if(parameterList->isParameter(
"symmetric"))
502 basker->Options.symmetric = parameterList->get<
bool>(
"symmetric");
504 if(parameterList->isParameter(
"realloc"))
506 basker->Options.realloc = parameterList->get<
bool>(
"realloc");
508 if(parameterList->isParameter(
"verbose"))
510 basker->Options.verbose = parameterList->get<
bool>(
"verbose");
512 if(parameterList->isParameter(
"verbose_matrix"))
514 basker->Options.verbose_matrix_out = parameterList->get<
bool>(
"verbose_matrix");
516 if(parameterList->isParameter(
"matching"))
518 basker->Options.matching = parameterList->get<
bool>(
"matching");
520 if(parameterList->isParameter(
"matching_type"))
522 basker->Options.matching_type =
523 (local_ordinal_type) parameterList->get<
int>(
"matching_type");
525 if(parameterList->isParameter(
"btf"))
527 basker->Options.btf = parameterList->get<
bool>(
"btf");
529 if(parameterList->isParameter(
"amd_btf"))
531 basker->Options.amd_btf = parameterList->get<
bool>(
"amd_btf");
533 if(parameterList->isParameter(
"amd_dom"))
535 basker->Options.amd_dom = parameterList->get<
bool>(
"amd_dom");
537 if(parameterList->isParameter(
"transpose"))
539 basker->Options.transpose = parameterList->get<
bool>(
"transpose");
545 template <
class Matrix,
class Vector>
546 Teuchos::RCP<const Teuchos::ParameterList>
549 using Teuchos::ParameterList;
551 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
555 if( is_null(valid_params) )
557 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
558 pl->set(
"IsContiguous",
true,
559 "Are GIDs contiguous");
560 pl->set(
"num_threads", 1,
561 "Number of threads");
562 pl->set(
"pivot",
false,
564 pl->set(
"pivot_tol", .0001,
565 "Tolerance before pivot, currently not used");
566 pl->set(
"symmetric",
false,
567 "Should Symbolic assume symmetric nonzero pattern");
568 pl->set(
"realloc" ,
false,
569 "Should realloc space if not enough");
570 pl->set(
"verbose",
false,
571 "Information about factoring");
572 pl->set(
"verbose_matrix",
false,
573 "Give Permuted Matrices");
574 pl->set(
"matching",
true,
575 "Use WC matching (Not Supported)");
576 pl->set(
"matching_type", 0,
577 "Type of WC matching (Not Supported)");
580 pl->set(
"amd_btf",
true,
581 "Use AMD on BTF blocks (Not Supported)");
582 pl->set(
"amd_dom",
true,
583 "Use CAMD on ND blocks (Not Supported)");
584 pl->set(
"transpose",
false,
585 "Solve the transpose A");
590 if( is_null(valid_params) ){
591 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
593 pl->set(
"IsContiguous",
true,
"Are GIDs contiguous");
594 pl->set(
"alnnz", 2,
"Approx number of nonzeros in L, default is 2*nnz(A)");
595 pl->set(
"aunnx", 2,
"Approx number of nonzeros in I, default is 2*nnz(U)");
603 template <
class Matrix,
class Vector>
608 if(current_phase == SOLVE)
return (
false);
610 #ifdef HAVE_AMESOS2_TIMERS 611 Teuchos::TimeMonitor convTimer(this->
timers_.mtxConvTime_);
618 #ifndef HAVE_TEUCHOS_COMPLEX 619 bool case_check = ( (this->
root_) && (this->
matrixA_->getComm()->getRank() == 0) && (this->
matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
636 local_ordinal_type nnz_ret = 0;
638 #ifdef HAVE_AMESOS2_TIMERS 639 Teuchos::TimeMonitor mtxRedistTimer( this->
timers_.mtxRedistTime_ );
642 if ( is_contiguous_ ==
true ) {
657 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->
globalNumNonZeros_),
659 "Amesos2_Basker loadA_impl: Did not get the expected number of non-zero vals");
663 #else // Not ShyLUBasker 672 local_ordinal_type nnz_ret = 0;
674 #ifdef HAVE_AMESOS2_TIMERS 675 Teuchos::TimeMonitor mtxRedistTimer( this->
timers_.mtxRedistTime_ );
678 if ( is_contiguous_ ==
true ) {
693 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->
globalNumNonZeros_),
695 "Amesos2_Basker loadA_impl: Did not get the expected number of non-zero vals");
702 template<
class Matrix,
class Vector>
708 #endif // AMESOS2_Basker_DEF_HPP Definition: basker.cpp:35
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
global_size_type globalNumCols_
Number of global columns in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:478
bool root_
If true, then this is the root processor.
Definition: Amesos2_SolverCore_decl.hpp:506
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Basker_def.hpp:547
global_size_type globalNumRows_
Number of global rows in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:475
Teuchos::Array< slu_type > bvals_
Persisting 1D store for B.
Definition: Amesos2_Basker_decl.hpp:194
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Basker_def.hpp:605
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:266
Definition: Amesos2_TypeDecl.hpp:143
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns a pointer to the Teuchos::Comm communicator with this operator.
Definition: Amesos2_SolverCore_decl.hpp:362
Teuchos::Array< local_ordinal_type > colptr_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Basker_decl.hpp:186
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
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:626
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Basker specific solve.
Definition: Amesos2_Basker_def.hpp:329
Amesos2 interface to the Baker package.
Definition: Amesos2_Basker_decl.hpp:73
Amesos2 Basker declarations.
Teuchos::Array< local_ordinal_type > rowind_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Basker_decl.hpp:184
Teuchos::Array< slu_type > xvals_
Persisting 1D store for X.
Definition: Amesos2_Basker_decl.hpp:192
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
Teuchos::Array< slu_type > nzvals_
Stores the values of the nonzero entries for Basker.
Definition: Amesos2_Basker_decl.hpp:182
global_size_type globalNumNonZeros_
Number of global non-zero values in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:481
void setNnzLU(size_t nnz)
Set the number of non-zero values in the and factors.
Definition: Amesos2_SolverCore_decl.hpp:451
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Basker_def.hpp:132
Definition: Amesos2_TypeDecl.hpp:127
Timers timers_
Various timing statistics.
Definition: Amesos2_SolverCore_decl.hpp:497
int numericFactorization_impl()
Basker specific numeric factorization.
Definition: Amesos2_Basker_def.hpp:219
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
Teuchos::RCP< const MatrixAdapter< Matrix > > matrixA_
The LHS operator.
Definition: Amesos2_SolverCore_decl.hpp:454
global_size_type rowIndexBase_
Index base of rowmap of matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:484
Definition: Amesos2_TypeDecl.hpp:128
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Basker_def.hpp:465