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 )
71 : SolverCore<Amesos2::Basker,Matrix,Vector>(A, X, B)
75 , is_contiguous_(true)
82 template <
class Matrix,
class Vector>
83 Basker<Matrix,Vector>::~Basker( )
86 template <
class Matrix,
class Vector>
89 return (this->root_ && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_);
92 template<
class Matrix,
class Vector>
98 #ifdef HAVE_AMESOS2_TIMERS
99 Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
106 template <
class Matrix,
class Vector>
115 template <
class Matrix,
class Vector>
124 #ifdef HAVE_AMESOS2_TIMERS
125 Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
128 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
129 std::cout <<
"Basker:: Before numeric factorization" << std::endl;
130 std::cout <<
"nzvals_ : " << nzvals_.toString() << std::endl;
131 std::cout <<
"rowind_ : " << rowind_.toString() << std::endl;
132 std::cout <<
"colptr_ : " << colptr_.toString() << std::endl;
135 info = basker.factor(this->globalNumRows_, this->globalNumCols_, this->globalNumNonZeros_, colptr_.getRawPtr(), rowind_.getRawPtr(), nzvals_.getRawPtr());
139 this->setNnzLU( as<size_t>(basker.get_NnzLU() ) ) ;
145 Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
149 TEUCHOS_TEST_FOR_EXCEPTION( (info == -1) ,
151 "Basker: Could not alloc space for L and U");
152 TEUCHOS_TEST_FOR_EXCEPTION( (info == -2),
154 "Basker: Could not alloc needed work space");
155 TEUCHOS_TEST_FOR_EXCEPTION( (info == -3) ,
157 "Basker: Could not alloc additional memory needed for L and U");
158 TEUCHOS_TEST_FOR_EXCEPTION( (info > 0) ,
160 "Basker: Zero pivot found at: " << info );
166 template <
class Matrix,
class Vector>
176 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
177 const size_t nrhs = X->getGlobalNumVectors();
179 if ( single_proc_optimization() && nrhs == 1 ) {
181 #ifdef HAVE_AMESOS2_TIMERS
182 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
185 #ifndef HAVE_TEUCHOS_COMPLEX
191 using complex_type =
typename Util::getStdCplxType< magnitude_type, typename matrix_adapter_type::spmtx_vals_t >::type;
195 TEUCHOS_TEST_FOR_EXCEPTION(b_vector ==
nullptr,
196 std::runtime_error,
"Amesos2 Runtime Error: b_vector returned null ");
198 TEUCHOS_TEST_FOR_EXCEPTION(x_vector ==
nullptr,
199 std::runtime_error,
"Amesos2 Runtime Error: x_vector returned null ");
203 #ifdef HAVE_AMESOS2_TIMERS
204 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
206 ierr = basker.solveMultiple(nrhs, b_vector, x_vector);
210 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
212 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
214 "Encountered zero diag element at: " << ierr);
215 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
217 "Could not alloc needed working memory for solve" );
222 const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
224 xvals_.resize(val_store_size);
225 bvals_.resize(val_store_size);
228 #ifdef HAVE_AMESOS2_TIMERS
229 Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
230 Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
233 if ( is_contiguous_ ==
true ) {
235 slu_type>::do_get(B, bvals_(), as<size_t>(ld_rhs), ROOTED, this->rowIndexBase_);
239 slu_type>::do_get(B, bvals_(), as<size_t>(ld_rhs), CONTIGUOUS_AND_ROOTED, this->rowIndexBase_);
245 #ifdef HAVE_AMESOS2_TIMERS
246 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
249 ierr = basker.solveMultiple(nrhs, bvals_.getRawPtr(),xvals_.getRawPtr());
255 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
257 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
259 "Encountered zero diag element at: " << ierr);
260 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
262 "Could not alloc needed working memory for solve" );
265 #ifdef HAVE_AMESOS2_TIMERS
266 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
269 if ( is_contiguous_ ==
true ) {
279 CONTIGUOUS_AND_ROOTED);
288 template <
class Matrix,
class Vector>
293 return( this->globalNumRows_ == this->globalNumCols_ );
297 template <
class Matrix,
class Vector>
302 using Teuchos::getIntegralValue;
303 using Teuchos::ParameterEntryValidator;
305 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
307 if(parameterList->isParameter(
"IsContiguous"))
309 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
314 template <
class Matrix,
class Vector>
315 Teuchos::RCP<const Teuchos::ParameterList>
318 using Teuchos::ParameterList;
320 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
322 if( is_null(valid_params) ){
323 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
325 pl->set(
"IsContiguous",
true,
"Are GIDs contiguous");
326 pl->set(
"alnnz", 2,
"Approx number of nonzeros in L, default is 2*nnz(A)");
327 pl->set(
"aunnx", 2,
"Approx number of nonzeros in I, default is 2*nnz(U)");
334 template <
class Matrix,
class Vector>
339 if(current_phase == SOLVE)
return (
false);
341 #ifdef HAVE_AMESOS2_TIMERS
342 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
347 nzvals_.resize(this->globalNumNonZeros_);
348 rowind_.resize(this->globalNumNonZeros_);
349 colptr_.resize(this->globalNumCols_ + 1);
352 local_ordinal_type nnz_ret = 0;
354 #ifdef HAVE_AMESOS2_TIMERS
355 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
358 if ( is_contiguous_ ==
true ) {
361 ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
362 nnz_ret, ROOTED, ARBITRARY, this->rowIndexBase_);
367 ::do_get(this->matrixA_.ptr(), nzvals_(), rowind_(), colptr_(),
368 nnz_ret, CONTIGUOUS_AND_ROOTED, ARBITRARY, this->rowIndexBase_);
373 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
375 "Amesos2_Basker loadA_impl: Did not get the expected number of non-zero vals");
381 template<
class Matrix,
class Vector>
387 #endif // AMESOS2_Basker_DEF_HPP
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Basker_def.hpp:336
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:266
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Basker_def.hpp:316
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 interface to the Baker package.
Definition: Amesos2_Basker_decl.hpp:73
Amesos2 Basker declarations.
bool single_proc_optimization() const
can we optimize size_type and ordinal_type for straight pass through, also check that is_contiguous_ ...
Definition: Amesos2_Basker_def.hpp:88
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_Basker_def.hpp:290
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Basker_def.hpp:94
int numericFactorization_impl()
Basker specific numeric factorization.
Definition: Amesos2_Basker_def.hpp:117
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
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:168