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)
72 , is_contiguous_(true)
79 template <
class Matrix,
class Vector>
80 Basker<Matrix,Vector>::~Basker( )
83 template <
class Matrix,
class Vector>
86 return (this->root_ && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_);
89 template<
class Matrix,
class Vector>
95 #ifdef HAVE_AMESOS2_TIMERS
96 Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
103 template <
class Matrix,
class Vector>
112 template <
class Matrix,
class Vector>
121 #ifdef HAVE_AMESOS2_TIMERS
122 Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
125 #ifdef HAVE_AMESOS2_VERBOSE_DEBUG
126 std::cout <<
"Basker:: Before numeric factorization" << std::endl;
127 std::cout <<
"nzvals_ : " << nzvals_.toString() << std::endl;
128 std::cout <<
"rowind_ : " << rowind_.toString() << std::endl;
129 std::cout <<
"colptr_ : " << colptr_.toString() << std::endl;
132 basker_dtype * pBaskerValues = function_map::convert_scalar(host_nzvals_view_.data());
133 info = basker.factor(this->globalNumRows_, this->globalNumCols_, this->globalNumNonZeros_, host_col_ptr_view_.data(), host_rows_view_.data(), pBaskerValues);
137 this->setNnzLU( as<size_t>(basker.get_NnzLU() ) ) ;
143 Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
147 TEUCHOS_TEST_FOR_EXCEPTION( (info == -1) ,
149 "Basker: Could not alloc space for L and U");
150 TEUCHOS_TEST_FOR_EXCEPTION( (info == -2),
152 "Basker: Could not alloc needed work space");
153 TEUCHOS_TEST_FOR_EXCEPTION( (info == -3) ,
155 "Basker: Could not alloc additional memory needed for L and U");
156 TEUCHOS_TEST_FOR_EXCEPTION( (info > 0) ,
158 "Basker: Zero pivot found at: " << info );
164 template <
class Matrix,
class Vector>
174 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
175 const size_t nrhs = X->getGlobalNumVectors();
178 #ifdef HAVE_AMESOS2_TIMERS
179 Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
180 Teuchos::TimeMonitor redistTimer( this->timers_.vecRedistTime_ );
183 if ( single_proc_optimization() && nrhs == 1 ) {
185 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
186 host_solve_array_t>::do_get(B, bValues_, as<size_t>(ld_rhs));
188 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
189 host_solve_array_t>::do_get(X, xValues_, as<size_t>(ld_rhs));
192 if ( is_contiguous_ ==
true ) {
193 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
194 host_solve_array_t>::do_get(B, bValues_, as<size_t>(ld_rhs), ROOTED, this->rowIndexBase_);
197 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
198 host_solve_array_t>::do_get(B, bValues_, as<size_t>(ld_rhs), CONTIGUOUS_AND_ROOTED, this->rowIndexBase_);
202 if ( is_contiguous_ ==
true ) {
203 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
204 host_solve_array_t>::do_get(X, xValues_, as<size_t>(ld_rhs), ROOTED, this->rowIndexBase_);
207 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
208 host_solve_array_t>::do_get(X, xValues_, as<size_t>(ld_rhs), CONTIGUOUS_AND_ROOTED, this->rowIndexBase_);
214 #ifdef HAVE_AMESOS2_TIMERS
215 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
218 basker_dtype * pxBaskerValues = function_map::convert_scalar(xValues_.data());
219 basker_dtype * pbBaskerValues = function_map::convert_scalar(bValues_.data());
220 ierr = basker.solveMultiple(nrhs, pbBaskerValues, pxBaskerValues);
224 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
226 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
228 "Encountered zero diag element at: " << ierr);
229 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
231 "Could not alloc needed working memory for solve" );
234 #ifdef HAVE_AMESOS2_TIMERS
235 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
238 if ( is_contiguous_ ==
true ) {
239 Util::put_1d_data_helper_kokkos_view<
245 Util::put_1d_data_helper_kokkos_view<
248 CONTIGUOUS_AND_ROOTED);
256 template <
class Matrix,
class Vector>
261 return( this->globalNumRows_ == this->globalNumCols_ );
265 template <
class Matrix,
class Vector>
270 using Teuchos::getIntegralValue;
271 using Teuchos::ParameterEntryValidator;
273 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
275 if(parameterList->isParameter(
"IsContiguous"))
277 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
282 template <
class Matrix,
class Vector>
283 Teuchos::RCP<const Teuchos::ParameterList>
286 using Teuchos::ParameterList;
288 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
290 if( is_null(valid_params) ){
291 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
293 pl->set(
"IsContiguous",
true,
"Are GIDs contiguous");
294 pl->set(
"alnnz", 2,
"Approx number of nonzeros in L, default is 2*nnz(A)");
295 pl->set(
"aunnx", 2,
"Approx number of nonzeros in I, default is 2*nnz(U)");
302 template <
class Matrix,
class Vector>
307 if(current_phase == SOLVE)
return (
false);
309 #ifdef HAVE_AMESOS2_TIMERS
310 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
315 host_nzvals_view_ = host_value_type_array(
316 Kokkos::ViewAllocateWithoutInitializing(
"host_nzvals_view_"), this->globalNumNonZeros_);
317 host_rows_view_ = host_ordinal_type_array(
318 Kokkos::ViewAllocateWithoutInitializing(
"host_rows_view_"), this->globalNumNonZeros_);
319 host_col_ptr_view_ = host_ordinal_type_array(
320 Kokkos::ViewAllocateWithoutInitializing(
"host_col_ptr_view_"), this->globalNumRows_ + 1);
323 local_ordinal_type nnz_ret = 0;
325 #ifdef HAVE_AMESOS2_TIMERS
326 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
329 if ( is_contiguous_ ==
true ) {
330 Util::get_ccs_helper_kokkos_view<
332 ::do_get(this->matrixA_.ptr(), host_nzvals_view_, host_rows_view_, host_col_ptr_view_,
333 nnz_ret, ROOTED, ARBITRARY, this->rowIndexBase_);
336 Util::get_ccs_helper_kokkos_view<
338 ::do_get(this->matrixA_.ptr(), host_nzvals_view_, host_rows_view_, host_col_ptr_view_,
339 nnz_ret, CONTIGUOUS_AND_ROOTED, ARBITRARY, this->rowIndexBase_);
344 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
346 "Amesos2_Basker loadA_impl: Did not get the expected number of non-zero vals");
352 template<
class Matrix,
class Vector>
358 #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:304
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Basker_def.hpp:284
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,
Definition: Amesos2_Basker_def.hpp:85
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:258
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Basker_def.hpp:91
int numericFactorization_impl()
Basker specific numeric factorization.
Definition: Amesos2_Basker_def.hpp:114
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:166