44 #ifndef AMESOS2_UMFPACK_DEF_HPP
45 #define AMESOS2_UMFPACK_DEF_HPP
47 #include <Teuchos_Tuple.hpp>
48 #include <Teuchos_ParameterList.hpp>
49 #include <Teuchos_StandardParameterEntryValidators.hpp>
52 #include "Amesos2_Umfpack_decl.hpp"
57 template <
class Matrix,
class Vector>
59 Teuchos::RCP<const Matrix> A,
60 Teuchos::RCP<Vector> X,
61 Teuchos::RCP<const Vector> B )
66 , is_contiguous_(true)
68 data_.Symbolic = NULL;
73 template <
class Matrix,
class Vector>
76 if (data_.Symbolic) function_map::umfpack_free_symbolic (&data_.Symbolic);
77 if (data_.Numeric) function_map::umfpack_free_numeric (&data_.Numeric);
80 template <
class Matrix,
class Vector>
84 std::ostringstream oss;
85 oss <<
"Umfpack solver interface";
89 template<
class Matrix,
class Vector>
97 template <
class Matrix,
class Vector>
103 if (data_.Symbolic) {
104 function_map::umfpack_free_symbolic(&(data_.Symbolic));
107 function_map::umfpack_defaults(data_.Control);
109 status = function_map::umfpack_symbolic(
110 this->globalNumRows_,this->globalNumCols_,
111 &(this->colptr_[0]), &(this->rowind_[0]),
112 &(this->nzvals_[0]), &(data_.Symbolic), data_.Control, data_.Info);
119 template <
class Matrix,
class Vector>
125 if(!data_.Symbolic) {
126 symbolicFactorization_impl();
129 function_map::umfpack_defaults(data_.Control);
132 function_map::umfpack_free_numeric(&(data_.Numeric));
135 status = function_map::umfpack_numeric(
137 &(this->rowind_[0]), &(this->nzvals_[0]), data_.Symbolic,
138 &(data_.Numeric), data_.Control, data_.Info);
143 template <
class Matrix,
class Vector>
150 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
151 const size_t nrhs = X->getGlobalNumVectors();
153 const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
154 Teuchos::Array<umfpack_type> xValues(val_store_size);
155 Teuchos::Array<umfpack_type> bValues(val_store_size);
158 #ifdef HAVE_AMESOS2_TIMERS
159 Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
160 Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
162 if ( is_contiguous_ ==
true ) {
164 umfpack_type>::do_get(B, bValues(),
167 this->rowIndexBase_);
171 umfpack_type>::do_get(B, bValues(),
173 CONTIGUOUS_AND_ROOTED,
174 this->rowIndexBase_);
178 int UmfpackRequest = this->control_.useTranspose_ ? UMFPACK_At : UMFPACK_A;
184 #ifdef HAVE_AMESOS2_TIMER
185 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
187 if (data_.Symbolic) {
188 function_map::umfpack_free_symbolic(&(data_.Symbolic));
192 int i_ld_rhs = as<int>(ld_rhs);
194 for(
size_t j = 0 ; j < nrhs; j++) {
195 int status = function_map::umfpack_solve(
197 &(this->colptr_[0]), &(this->rowind_[0]), &(this->nzvals_[0]),
198 &xValues.getRawPtr()[j*i_ld_rhs],
199 &bValues.getRawPtr()[j*i_ld_rhs],
200 data_.Numeric, data_.Control, data_.Info);
211 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
213 TEUCHOS_TEST_FOR_EXCEPTION( ierr != 0, std::runtime_error,
214 "umfpack_solve has error code: " << ierr );
218 #ifdef HAVE_AMESOS2_TIMERS
219 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
222 if ( is_contiguous_ ==
true ) {
227 this->rowIndexBase_);
233 CONTIGUOUS_AND_ROOTED,
234 this->rowIndexBase_);
242 template <
class Matrix,
class Vector>
249 return( this->matrixA_->getGlobalNumRows() == this->matrixA_->getGlobalNumCols() );
253 template <
class Matrix,
class Vector>
258 using Teuchos::getIntegralValue;
259 using Teuchos::ParameterEntryValidator;
261 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
263 if( parameterList->isParameter(
"IsContiguous") ){
264 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
269 template <
class Matrix,
class Vector>
270 Teuchos::RCP<const Teuchos::ParameterList>
273 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
275 if( is_null(valid_params) ){
276 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
278 pl->set(
"IsContiguous",
true,
"Whether GIDs contiguous");
287 template <
class Matrix,
class Vector>
291 if(current_phase == SOLVE) {
295 #ifdef HAVE_AMESOS2_TIMERS
296 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
301 nzvals_.resize(this->globalNumNonZeros_);
302 rowind_.resize(this->globalNumNonZeros_);
303 colptr_.resize(this->globalNumCols_ + 1);
308 #ifdef HAVE_AMESOS2_TIMERS
309 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
312 TEUCHOS_TEST_FOR_EXCEPTION( this->rowIndexBase_ != this->columnIndexBase_,
314 "Row and column maps have different indexbase ");
315 if ( is_contiguous_ ==
true ) {
318 nzvals_(), rowind_(),
322 this->rowIndexBase_);
326 nzvals_(), rowind_(),
328 CONTIGUOUS_AND_ROOTED,
330 this->rowIndexBase_);
338 template<
class Matrix,
class Vector>
344 #endif // AMESOS2_UMFPACK_DEF_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Umfpack_def.hpp:244
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Umfpack_def.hpp:271
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Umfpack.
Definition: Amesos2_Umfpack_def.hpp:99
Umfpack(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Initialize from Teuchos::RCP.
Definition: Amesos2_Umfpack_def.hpp:58
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Umfpack specific solve.
Definition: Amesos2_Umfpack_def.hpp:145
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:266
Utility functions for Amesos2.
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Umfpack_def.hpp:289
int numericFactorization_impl()
Umfpack specific numeric factorization.
Definition: Amesos2_Umfpack_def.hpp:121
Amesos2 interface to the Umfpack package.
Definition: Amesos2_Umfpack_decl.hpp:63
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:654
~Umfpack()
Destructor.
Definition: Amesos2_Umfpack_def.hpp:74
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Umfpack_def.hpp:91
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_Umfpack_def.hpp:82
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
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