19 #ifndef AMESOS2_BASKER_DEF_HPP
20 #define AMESOS2_BASKER_DEF_HPP
22 #include <Teuchos_Tuple.hpp>
23 #include <Teuchos_ParameterList.hpp>
24 #include <Teuchos_StandardParameterEntryValidators.hpp>
32 template <
class Matrix,
class Vector>
33 Basker<Matrix,Vector>::Basker(
34 Teuchos::RCP<const Matrix> A,
35 Teuchos::RCP<Vector> X,
36 Teuchos::RCP<const Vector> B )
37 : SolverCore<Amesos2::Basker,Matrix,Vector>(A, X, B)
38 , is_contiguous_(true)
45 template <
class Matrix,
class Vector>
46 Basker<Matrix,Vector>::~Basker( )
49 template <
class Matrix,
class Vector>
52 return (this->root_ && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_);
55 template<
class Matrix,
class Vector>
61 #ifdef HAVE_AMESOS2_TIMERS
62 Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
69 template <
class Matrix,
class Vector>
78 template <
class Matrix,
class Vector>
87 #ifdef HAVE_AMESOS2_TIMERS
88 Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
91 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
92 std::cout <<
"Basker:: Before numeric factorization" << std::endl;
93 std::cout <<
"nzvals_ : " << nzvals_.toString() << std::endl;
94 std::cout <<
"rowind_ : " << rowind_.toString() << std::endl;
95 std::cout <<
"colptr_ : " << colptr_.toString() << std::endl;
98 basker_dtype * pBaskerValues = function_map::convert_scalar(host_nzvals_view_.data());
99 info = basker.factor(this->globalNumRows_, this->globalNumCols_, this->globalNumNonZeros_, host_col_ptr_view_.data(), host_rows_view_.data(), pBaskerValues);
103 this->setNnzLU( as<size_t>(basker.get_NnzLU() ) ) ;
109 Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
113 TEUCHOS_TEST_FOR_EXCEPTION( (info == -1) ,
115 "Basker: Could not alloc space for L and U");
116 TEUCHOS_TEST_FOR_EXCEPTION( (info == -2),
118 "Basker: Could not alloc needed work space");
119 TEUCHOS_TEST_FOR_EXCEPTION( (info == -3) ,
121 "Basker: Could not alloc additional memory needed for L and U");
122 TEUCHOS_TEST_FOR_EXCEPTION( (info > 0) ,
124 "Basker: Zero pivot found at: " << info );
130 template <
class Matrix,
class Vector>
140 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
141 const size_t nrhs = X->getGlobalNumVectors();
145 #ifdef HAVE_AMESOS2_TIMERS
146 Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
147 Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
150 const bool initialize_data =
true;
151 const bool do_not_initialize_data =
false;
152 if ( single_proc_optimization() && nrhs == 1 ) {
154 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
155 host_solve_array_t>::do_get(initialize_data, B, bValues_, as<size_t>(ld_rhs));
157 bDidAssignX = Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
158 host_solve_array_t>::do_get(do_not_initialize_data, X, xValues_, as<size_t>(ld_rhs));
161 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
162 host_solve_array_t>::do_get(initialize_data, B, bValues_,
164 (is_contiguous_ ==
true) ? ROOTED : CONTIGUOUS_AND_ROOTED,
165 this->rowIndexBase_);
168 bDidAssignX = Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
169 host_solve_array_t>::do_get(do_not_initialize_data, X, xValues_,
171 (is_contiguous_ ==
true) ? ROOTED : CONTIGUOUS_AND_ROOTED,
172 this->rowIndexBase_);
177 #ifdef HAVE_AMESOS2_TIMERS
178 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
181 basker_dtype * pxBaskerValues = function_map::convert_scalar(xValues_.data());
182 basker_dtype * pbBaskerValues = function_map::convert_scalar(bValues_.data());
183 ierr = basker.solveMultiple(nrhs, pbBaskerValues, pxBaskerValues);
187 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
189 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
191 "Encountered zero diag element at: " << ierr);
192 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
194 "Could not alloc needed working memory for solve" );
199 #ifdef HAVE_AMESOS2_TIMERS
200 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
203 Util::put_1d_data_helper_kokkos_view<MultiVecAdapter<Vector>,
204 host_solve_array_t>::do_put(X, xValues_,
206 (is_contiguous_ ==
true) ? ROOTED : CONTIGUOUS_AND_ROOTED);
213 template <
class Matrix,
class Vector>
218 return( this->globalNumRows_ == this->globalNumCols_ );
222 template <
class Matrix,
class Vector>
227 using Teuchos::getIntegralValue;
228 using Teuchos::ParameterEntryValidator;
230 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
232 if(parameterList->isParameter(
"IsContiguous"))
234 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
239 template <
class Matrix,
class Vector>
240 Teuchos::RCP<const Teuchos::ParameterList>
243 using Teuchos::ParameterList;
245 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
247 if( is_null(valid_params) ){
248 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
250 pl->set(
"IsContiguous",
true,
"Are GIDs contiguous");
251 pl->set(
"alnnz", 2,
"Approx number of nonzeros in L, default is 2*nnz(A)");
252 pl->set(
"aunnx", 2,
"Approx number of nonzeros in I, default is 2*nnz(U)");
259 template <
class Matrix,
class Vector>
264 if(current_phase == SOLVE)
return (
false);
266 #ifdef HAVE_AMESOS2_TIMERS
267 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
272 host_nzvals_view_ = host_value_type_array(
273 Kokkos::ViewAllocateWithoutInitializing(
"host_nzvals_view_"), this->globalNumNonZeros_);
274 host_rows_view_ = host_ordinal_type_array(
275 Kokkos::ViewAllocateWithoutInitializing(
"host_rows_view_"), this->globalNumNonZeros_);
276 host_col_ptr_view_ = host_ordinal_type_array(
277 Kokkos::ViewAllocateWithoutInitializing(
"host_col_ptr_view_"), this->globalNumRows_ + 1);
280 local_ordinal_type nnz_ret = 0;
282 #ifdef HAVE_AMESOS2_TIMERS
283 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
288 ::do_get(this->matrixA_.ptr(),
289 host_nzvals_view_, host_rows_view_, host_col_ptr_view_, nnz_ret,
290 (is_contiguous_ ==
true) ? ROOTED : CONTIGUOUS_AND_ROOTED,
292 this->rowIndexBase_);
296 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
298 "Amesos2_Basker loadA_impl: Did not get the expected number of non-zero vals");
304 template<
class Matrix,
class Vector>
310 #endif // AMESOS2_Basker_DEF_HPP
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:614
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:31
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Basker_def.hpp:261
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Basker_def.hpp:241
Amesos2 interface to the Baker package.
Definition: Amesos2_Basker_decl.hpp:39
Amesos2 Basker declarations.
bool single_proc_optimization() const
can we optimize size_type and ordinal_type for straight pass through,
Definition: Amesos2_Basker_def.hpp:51
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:42
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Basker_def.hpp:215
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Basker_def.hpp:57
int numericFactorization_impl()
Basker specific numeric factorization.
Definition: Amesos2_Basker_def.hpp:80
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:142
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:132