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