52 #ifndef AMESOS2_KLU2_DEF_HPP 53 #define AMESOS2_KLU2_DEF_HPP 55 #include <Teuchos_Tuple.hpp> 56 #include <Teuchos_ParameterList.hpp> 57 #include <Teuchos_StandardParameterEntryValidators.hpp> 65 template <
class Matrix,
class Vector>
67 Teuchos::RCP<const Matrix> A,
68 Teuchos::RCP<Vector> X,
69 Teuchos::RCP<const Vector> B )
75 , is_contiguous_(true)
77 ::KLU2::klu_defaults<slu_type, local_ordinal_type> (&(data_.common_)) ;
78 data_.symbolic_ = NULL;
79 data_.numeric_ = NULL;
86 template <
class Matrix,
class Vector>
94 if (data_.symbolic_ != NULL)
95 ::KLU2::klu_free_symbolic<slu_type, local_ordinal_type>
96 (&(data_.symbolic_), &(data_.common_)) ;
97 if (data_.numeric_ != NULL)
98 ::KLU2::klu_free_numeric<slu_type, local_ordinal_type>
99 (&(data_.numeric_), &(data_.common_)) ;
112 template<
class Matrix,
class Vector>
118 #ifdef HAVE_AMESOS2_TIMERS 119 Teuchos::TimeMonitor preOrderTimer(this->
timers_.preOrderTime_);
126 template <
class Matrix,
class Vector>
130 if (data_.symbolic_ != NULL) {
131 ::KLU2::klu_free_symbolic<slu_type, local_ordinal_type>
132 (&(data_.symbolic_), &(data_.common_)) ;
135 #ifndef HAVE_TEUCHOS_COMPLEX 136 bool single_process_optim_check = ( (this->
matrixA_->getComm()->getRank() == 0) && (this->
matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
137 if ( single_process_optim_check ) {
139 auto sp_rowptr = this->
matrixA_->returnRowPtr();
140 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
141 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
142 auto sp_colind = this->
matrixA_->returnColInd();
143 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
144 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
145 auto sp_values = this->
matrixA_->returnValues();
146 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
147 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
152 Teuchos::Array< local_ordinal_type > sp_rowptr_with_common_type( this->
globalNumRows_ + 1 );
155 sp_rowptr_with_common_type[i] = sp_rowptr[i];
158 data_.symbolic_ = ::KLU2::klu_analyze<slu_type, local_ordinal_type>
159 ((local_ordinal_type)this->
globalNumCols_, sp_rowptr_with_common_type.getRawPtr(),
160 sp_colind, &(data_.common_)) ;
165 data_.symbolic_ = ::KLU2::klu_analyze<slu_type, local_ordinal_type>
167 rowind_.getRawPtr(), &(data_.common_)) ;
175 template <
class Matrix,
class Vector>
189 #ifdef HAVE_AMESOS2_TIMERS 190 Teuchos::TimeMonitor numFactTimer(this->
timers_.numFactTime_);
193 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG 194 std::cout <<
"KLU2:: Before numeric factorization" << std::endl;
195 std::cout <<
"nzvals_ : " <<
nzvals_.toString() << std::endl;
196 std::cout <<
"rowind_ : " <<
rowind_.toString() << std::endl;
197 std::cout <<
"colptr_ : " <<
colptr_.toString() << std::endl;
200 if (data_.numeric_ != NULL) {
201 ::KLU2::klu_free_numeric<slu_type, local_ordinal_type>
202 (&(data_.numeric_), &(data_.common_)) ;
205 #ifndef HAVE_TEUCHOS_COMPLEX 206 bool single_process_optim_check = ( (this->
matrixA_->getComm()->getRank() == 0) && (this->
matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
207 if ( single_process_optim_check ) {
209 auto sp_rowptr = this->
matrixA_->returnRowPtr();
210 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
211 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
212 auto sp_colind = this->
matrixA_->returnColInd();
213 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
214 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
215 auto sp_values = this->
matrixA_->returnValues();
216 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
217 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
222 Teuchos::Array< local_ordinal_type > sp_rowptr_with_common_type( this->
globalNumRows_ + 1 );
225 sp_rowptr_with_common_type[i] = sp_rowptr[i];
228 data_.numeric_ = ::KLU2::klu_factor<slu_type, local_ordinal_type>
229 (sp_rowptr_with_common_type.getRawPtr(), sp_colind, sp_values,
230 data_.symbolic_, &(data_.common_)) ;
236 data_.numeric_ = ::KLU2::klu_factor<slu_type, local_ordinal_type>
238 data_.symbolic_, &(data_.common_)) ;
243 this->
setNnzLU( as<size_t>((data_.numeric_)->lnz) + as<size_t>((data_.numeric_)->unz) );
249 Teuchos::broadcast(*(this->
matrixA_->getComm()), 0, &info);
267 template <
class Matrix,
class Vector>
276 const global_size_type ld_rhs = this->
root_ ? X->getGlobalLength() : 0;
277 const size_t nrhs = X->getGlobalNumVectors();
279 bool single_process_optim_check =
false;
280 #ifndef HAVE_TEUCHOS_COMPLEX 281 single_process_optim_check = ( (this->
matrixA_->getComm()->getRank() == 0) && (this->
matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
282 if ( single_process_optim_check && (nrhs == 1) ) {
283 #ifdef HAVE_AMESOS2_TIMERS 284 Teuchos::TimeMonitor solveTimer(this->
timers_.solveTime_);
287 auto sp_rowptr = this->
matrixA_->returnRowPtr();
288 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
289 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
290 auto sp_colind = this->
matrixA_->returnColInd();
291 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
292 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
293 auto sp_values = this->
matrixA_->returnValues();
294 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
295 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
298 TEUCHOS_TEST_FOR_EXCEPTION(b_vector ==
nullptr,
299 std::runtime_error,
"Amesos2 Runtime Error: b_vector returned null ");
301 TEUCHOS_TEST_FOR_EXCEPTION(x_vector ==
nullptr,
302 std::runtime_error,
"Amesos2 Runtime Error: x_vector returned null ");
309 ::KLU2::klu_tsolve2<slu_type, local_ordinal_type>
310 (data_.symbolic_, data_.numeric_,
312 (local_ordinal_type)nrhs,
313 b_vector, x_vector, &(data_.common_)) ;
316 ::KLU2::klu_solve2<slu_type, local_ordinal_type>
317 (data_.symbolic_, data_.numeric_,
319 (local_ordinal_type)nrhs,
320 b_vector, x_vector, &(data_.common_)) ;
324 Teuchos::broadcast(*(this->
getComm()), 0, &ierr);
330 const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
331 Teuchos::Array<slu_type> bValues(val_store_size);
334 #ifdef HAVE_AMESOS2_TIMERS 335 Teuchos::TimeMonitor mvConvTimer(this->
timers_.vecConvTime_);
336 Teuchos::TimeMonitor redistTimer( this->
timers_.vecRedistTime_ );
338 if ( is_contiguous_ ==
true ) {
340 slu_type>::do_get(B, bValues(),
346 slu_type>::do_get(B, bValues(),
355 #ifdef HAVE_AMESOS2_TIMERS 356 Teuchos::TimeMonitor solveTimer(this->
timers_.solveTime_);
363 if ( single_process_optim_check ==
true ) {
364 ::KLU2::klu_tsolve<slu_type, local_ordinal_type>
365 (data_.symbolic_, data_.numeric_,
367 (local_ordinal_type)nrhs,
368 bValues.getRawPtr(), &(data_.common_)) ;
371 ::KLU2::klu_solve<slu_type, local_ordinal_type>
372 (data_.symbolic_, data_.numeric_,
374 (local_ordinal_type)nrhs,
375 bValues.getRawPtr(), &(data_.common_)) ;
383 if ( single_process_optim_check ==
true ) {
384 ::KLU2::klu_solve<slu_type, local_ordinal_type>
385 (data_.symbolic_, data_.numeric_,
387 (local_ordinal_type)nrhs,
388 bValues.getRawPtr(), &(data_.common_)) ;
391 ::KLU2::klu_tsolve<slu_type, local_ordinal_type>
392 (data_.symbolic_, data_.numeric_,
394 (local_ordinal_type)nrhs,
395 bValues.getRawPtr(), &(data_.common_)) ;
402 Teuchos::broadcast(*(this->
getComm()), 0, &ierr);
419 #ifdef HAVE_AMESOS2_TIMERS 420 Teuchos::TimeMonitor redistTimer(this->
timers_.vecRedistTime_);
423 if ( is_contiguous_ ==
true ) {
442 template <
class Matrix,
class Vector>
449 return( this->
matrixA_->getGlobalNumRows() == this->
matrixA_->getGlobalNumCols() );
453 template <
class Matrix,
class Vector>
458 using Teuchos::getIntegralValue;
459 using Teuchos::ParameterEntryValidator;
465 if( parameterList->isParameter(
"Trans") ){
466 RCP<const ParameterEntryValidator> trans_validator = valid_params->getEntry(
"Trans").validator();
467 parameterList->getEntry(
"Trans").setValidator(trans_validator);
469 transFlag_ = getIntegralValue<int>(*parameterList,
"Trans");
472 if( parameterList->isParameter(
"IsContiguous") ){
473 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
478 template <
class Matrix,
class Vector>
479 Teuchos::RCP<const Teuchos::ParameterList>
483 using Teuchos::tuple;
484 using Teuchos::ParameterList;
485 using Teuchos::setStringToIntegralParameter;
487 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
489 if( is_null(valid_params) )
491 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
493 pl->set(
"Equil",
true,
"Whether to equilibrate the system before solve, does nothing now");
494 pl->set(
"IsContiguous",
true,
"Whether GIDs contiguous");
496 setStringToIntegralParameter<int>(
"Trans",
"NOTRANS",
497 "Solve for the transpose system or not",
498 tuple<string>(
"NOTRANS",
"TRANS",
"CONJ"),
499 tuple<string>(
"Solve with transpose",
500 "Do not solve with transpose",
501 "Solve with the conjugate transpose"),
511 template <
class Matrix,
class Vector>
517 if(current_phase == SOLVE)
return(
false);
519 #ifndef HAVE_TEUCHOS_COMPLEX 520 bool single_process_optim_check = ( (this->
matrixA_->getComm()->getRank() == 0) && (this->
matrixA_->getComm()->getSize() == 1) && is_contiguous_ ) ;
521 if ( single_process_optim_check ) {
528 #ifdef HAVE_AMESOS2_TIMERS 529 Teuchos::TimeMonitor convTimer(this->
timers_.mtxConvTime_);
539 local_ordinal_type nnz_ret = 0;
541 #ifdef HAVE_AMESOS2_TIMERS 542 Teuchos::TimeMonitor mtxRedistTimer( this->
timers_.mtxRedistTime_ );
545 if ( is_contiguous_ ==
true ) {
561 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->
globalNumNonZeros_),
563 "Did not get the expected number of non-zero vals");
572 template<
class Matrix,
class Vector>
578 #endif // AMESOS2_KLU2_DEF_HPP Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
Teuchos::Array< slu_type > nzvals_
Stores the values of the nonzero entries for KLU2.
Definition: Amesos2_KLU2_decl.hpp:230
KLU2(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Initialize from Teuchos::RCP.
Definition: Amesos2_KLU2_def.hpp:66
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
Amesos2 KLU2 declarations.
global_size_type globalNumCols_
Number of global columns in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:478
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_KLU2_def.hpp:480
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_KLU2_def.hpp:513
bool root_
If true, then this is the root processor.
Definition: Amesos2_SolverCore_decl.hpp:506
global_size_type globalNumRows_
Number of global rows in matrixA_.
Definition: Amesos2_SolverCore_decl.hpp:475
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:266
~KLU2()
Destructor.
Definition: Amesos2_KLU2_def.hpp:87
Definition: Amesos2_TypeDecl.hpp:143
Control control_
Parameters for solving.
Definition: Amesos2_SolverCore_decl.hpp:494
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
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
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > ¶meterList)
Definition: Amesos2_KLU2_def.hpp:455
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using KLU2.
Definition: Amesos2_KLU2_def.hpp:128
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:626
Definition: Amesos2_KLU2_FunctionMap.hpp:67
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_KLU2_def.hpp:114
Teuchos::Array< local_ordinal_type > rowind_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_KLU2_decl.hpp:232
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
KLU2 specific solve.
Definition: Amesos2_KLU2_def.hpp:269
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_KLU2_def.hpp:444
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
int numericFactorization_impl()
KLU2 specific numeric factorization.
Definition: Amesos2_KLU2_def.hpp:177
Teuchos::Array< local_ordinal_type > colptr_
Stores the row indices of the nonzero entries.
Definition: Amesos2_KLU2_decl.hpp:234
Amesos2 interface to the KLU2 package.
Definition: Amesos2_KLU2_decl.hpp:72
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 transFlag_
Definition: Amesos2_KLU2_decl.hpp:243
Definition: Amesos2_TypeDecl.hpp:127
Timers timers_
Various timing statistics.
Definition: Amesos2_SolverCore_decl.hpp:497
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