44 #ifndef AMESOS2_TACHO_DEF_HPP
45 #define AMESOS2_TACHO_DEF_HPP
47 #include <Teuchos_Tuple.hpp>
48 #include <Teuchos_ParameterList.hpp>
49 #include <Teuchos_StandardParameterEntryValidators.hpp>
52 #include "Amesos2_Tacho_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 )
70 template <
class Matrix,
class Vector>
75 template <
class Matrix,
class Vector>
79 std::ostringstream oss;
80 oss <<
"Tacho solver interface";
84 template<
class Matrix,
class Vector>
91 template <
class Matrix,
class Vector>
97 size_type_array row_ptr;
98 ordinal_type_array cols;
101 if(do_optimization()) {
103 typedef typename MatrixAdapter<Matrix>::spmtx_ptr_t row_ptr_t;
104 typedef typename MatrixAdapter<Matrix>::spmtx_idx_t col_ind_t;
105 row_ptr_t sp_rowptr = this->matrixA_->returnRowPtr();
106 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr ==
nullptr,
107 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null");
108 col_ind_t sp_colind = this->matrixA_->returnColInd();
109 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind ==
nullptr,
110 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null");
127 if(std::is_same<size_type,
typename std::remove_pointer<row_ptr_t>::type>::value) {
130 row_ptr = size_type_array((size_type*)sp_rowptr, this->globalNumRows_ + 1);
133 row_ptr = size_type_array(
"r", this->globalNumRows_ + 1);
134 for(global_size_type n = 0; n < this->globalNumRows_ + 1; ++n) {
135 row_ptr(n) =
static_cast<size_type
>(sp_rowptr[n]);
139 if(std::is_same<ordinal_type,
typename std::remove_pointer<col_ind_t>::type>::value) {
141 cols = ordinal_type_array((ordinal_type*)sp_colind, this->globalNumNonZeros_);
144 cols = ordinal_type_array(
"c", this->globalNumNonZeros_);
145 for(global_size_type n = 0; n < this->globalNumNonZeros_; ++n) {
146 cols(n) =
static_cast<ordinal_type
>(sp_colind[n]);
153 row_ptr = size_type_array(this->rowptr_.getRawPtr(), this->globalNumRows_ + 1);
154 cols = ordinal_type_array(this->colind_.getRawPtr(), this->globalNumNonZeros_);
159 data_.solver.analyze(this->globalNumCols_, row_ptr, cols);
166 template <
class Matrix,
class Vector>
173 value_type_array values;
175 if(do_optimization()) {
177 typename MatrixAdapter<Matrix>::spmtx_vals_t sp_values = this->matrixA_->returnValues();
178 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
179 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null");
182 values = value_type_array(sp_values, this->globalNumNonZeros_);
187 values = value_type_array(this->nzvals_.getRawPtr(), this->globalNumNonZeros_);
190 data_.solver.factorize(values);
196 template <
class Matrix,
class Vector>
203 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
204 const size_t nrhs = X->getGlobalNumVectors();
206 const size_t val_store_size = as<size_t>(ld_rhs * nrhs);
207 Teuchos::Array<tacho_type> xValues(val_store_size);
208 Teuchos::Array<tacho_type> bValues(val_store_size);
211 #ifdef HAVE_AMESOS2_TIMERS
212 Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
213 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
216 tacho_type>::do_get(B, bValues(),
218 ROOTED, this->rowIndexBase_);
224 #ifdef HAVE_AMESOS2_TIMER
225 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
228 if (workspace_.extent(0) < this->globalNumRows_ || workspace_.extent(1) < nrhs) {
229 workspace_ = solve_array_t(
"t", this->globalNumRows_, nrhs);
232 solve_array_t x(xValues.getRawPtr(), this->globalNumRows_, nrhs);
233 solve_array_t b(bValues.getRawPtr(), this->globalNumRows_, nrhs);
235 data_.solver.solve(x, b, workspace_);
244 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
246 TEUCHOS_TEST_FOR_EXCEPTION( ierr != 0, std::runtime_error,
247 "tacho_solve has error code: " << ierr );
251 #ifdef HAVE_AMESOS2_TIMERS
252 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
258 ROOTED, this->rowIndexBase_);
265 template <
class Matrix,
class Vector>
270 return( this->matrixA_->getGlobalNumRows() == this->matrixA_->getGlobalNumCols() );
274 template <
class Matrix,
class Vector>
278 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
286 template <
class Matrix,
class Vector>
287 Teuchos::RCP<const Teuchos::ParameterList>
290 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
292 if( is_null(valid_params) ){
293 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
305 template <
class Matrix,
class Vector>
308 return (this->root_ && (this->matrixA_->getComm()->getSize() == 1));
311 template <
class Matrix,
class Vector>
315 if(current_phase == SOLVE) {
319 if(!do_optimization()) {
320 #ifdef HAVE_AMESOS2_TIMERS
321 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
326 nzvals_.resize(this->globalNumNonZeros_);
327 colind_.resize(this->globalNumNonZeros_);
328 rowptr_.resize(this->globalNumRows_ + 1);
331 size_type nnz_ret = 0;
333 #ifdef HAVE_AMESOS2_TIMERS
334 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
337 TEUCHOS_TEST_FOR_EXCEPTION( this->rowIndexBase_ != this->columnIndexBase_,
339 "Row and column maps have different indexbase ");
343 this->matrixA_.ptr(),
344 nzvals_(), colind_(),
347 this->columnIndexBase_);
355 template<
class Matrix,
class Vector>
361 #endif // AMESOS2_TACHO_DEF_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:65
Amesos2 interface to the Tacho package.
Definition: Amesos2_Tacho_decl.hpp:65
Similar to get_ccs_helper , but used to get a CRS representation of the given matrix.
Definition: Amesos2_Util.hpp:665
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Tacho.
Definition: Amesos2_Tacho_def.hpp:93
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_Tacho_def.hpp:77
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:266
Utility functions for Amesos2.
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Tacho_def.hpp:267
int numericFactorization_impl()
Tacho specific numeric factorization.
Definition: Amesos2_Tacho_def.hpp:168
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Tacho_def.hpp:86
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Tacho_def.hpp:288
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Tacho specific solve.
Definition: Amesos2_Tacho_def.hpp:198
TachoSolver(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Initialize from Teuchos::RCP.
Definition: Amesos2_Tacho_def.hpp:58
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Tacho_def.hpp:313
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition: Amesos2_Tacho_def.hpp:307
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
~TachoSolver()
Destructor.
Definition: Amesos2_Tacho_def.hpp:71