20 #ifndef AMESOS2_SHYLUBASKER_DEF_HPP
21 #define AMESOS2_SHYLUBASKER_DEF_HPP
23 #include <Teuchos_Tuple.hpp>
24 #include <Teuchos_ParameterList.hpp>
25 #include <Teuchos_StandardParameterEntryValidators.hpp>
33 template <
class Matrix,
class Vector>
34 ShyLUBasker<Matrix,Vector>::ShyLUBasker(
35 Teuchos::RCP<const Matrix> A,
36 Teuchos::RCP<Vector> X,
37 Teuchos::RCP<const Vector> B )
38 : SolverCore<Amesos2::ShyLUBasker,Matrix,Vector>(A, X, B)
39 , is_contiguous_(true)
46 #if defined(HAVE_AMESOS2_KOKKOS) && defined(KOKKOS_ENABLE_OPENMP)
51 typedef Kokkos::OpenMP Exe_Space;
53 ShyLUbasker = new ::BaskerNS::BaskerTrilinosInterface<local_ordinal_type, shylubasker_dtype, Exe_Space>();
54 ShyLUbasker->Options.no_pivot = BASKER_FALSE;
55 ShyLUbasker->Options.static_delayed_pivot = 0;
56 ShyLUbasker->Options.symmetric = BASKER_FALSE;
57 ShyLUbasker->Options.realloc = BASKER_TRUE;
58 ShyLUbasker->Options.verbose = BASKER_FALSE;
59 ShyLUbasker->Options.prune = BASKER_TRUE;
60 ShyLUbasker->Options.btf_matching = 2;
61 ShyLUbasker->Options.blk_matching = 1;
62 ShyLUbasker->Options.matrix_scaling = 0;
63 ShyLUbasker->Options.min_block_size = 0;
64 ShyLUbasker->Options.amd_dom = BASKER_TRUE;
65 ShyLUbasker->Options.use_metis = BASKER_TRUE;
66 ShyLUbasker->Options.use_nodeNDP = BASKER_TRUE;
67 ShyLUbasker->Options.run_nd_on_leaves = BASKER_TRUE;
68 ShyLUbasker->Options.run_amd_on_leaves = BASKER_FALSE;
69 ShyLUbasker->Options.transpose = BASKER_FALSE;
70 ShyLUbasker->Options.replace_tiny_pivot = BASKER_FALSE;
71 ShyLUbasker->Options.verbose_matrix_out = BASKER_FALSE;
73 ShyLUbasker->Options.user_fill = (double)BASKER_FILL_USER;
74 ShyLUbasker->Options.use_sequential_diag_facto = BASKER_FALSE;
75 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
76 num_threads = Kokkos::OpenMP::max_hardware_threads();
78 num_threads = Kokkos::OpenMP::impl_max_hardware_threads();
82 TEUCHOS_TEST_FOR_EXCEPTION(1 != 0,
84 "Amesos2_ShyLUBasker Exception: Do not have supported Kokkos node type (OpenMP) enabled for ShyLUBasker");
89 template <
class Matrix,
class Vector>
90 ShyLUBasker<Matrix,Vector>::~ShyLUBasker( )
93 #if defined(HAVE_AMESOS2_KOKKOS) && defined(KOKKOS_ENABLE_OPENMP)
94 ShyLUbasker->Finalize();
99 template <
class Matrix,
class Vector>
102 return (this->root_ && (this->matrixA_->getComm()->getSize() == 1) && is_contiguous_);
105 template<
class Matrix,
class Vector>
111 #ifdef HAVE_AMESOS2_TIMERS
112 Teuchos::TimeMonitor preOrderTimer(this->timers_.preOrderTime_);
119 template <
class Matrix,
class Vector>
127 ShyLUbasker->SetThreads(num_threads);
135 if ( single_proc_optimization() ) {
137 host_ordinal_type_array sp_rowptr;
138 host_ordinal_type_array sp_colind;
140 this->matrixA_->returnRowPtr_kokkos_view(sp_rowptr);
141 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr.data() ==
nullptr,
142 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
143 this->matrixA_->returnColInd_kokkos_view(sp_colind);
144 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind.data() ==
nullptr,
145 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
147 host_value_type_array hsp_values;
148 this->matrixA_->returnValues_kokkos_view(hsp_values);
149 shylubasker_dtype * sp_values = function_map::convert_scalar(hsp_values.data());
151 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
152 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
155 info = ShyLUbasker->Symbolic(this->globalNumRows_,
156 this->globalNumCols_,
157 this->globalNumNonZeros_,
163 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
164 std::runtime_error,
"Error in ShyLUBasker Symbolic");
169 shylubasker_dtype * sp_values = function_map::convert_scalar(nzvals_view_.data());
170 info = ShyLUbasker->Symbolic(this->globalNumRows_,
171 this->globalNumCols_,
172 this->globalNumNonZeros_,
177 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
178 std::runtime_error,
"Error in ShyLUBasker Symbolic");
184 Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
189 template <
class Matrix,
class Vector>
198 #ifdef HAVE_AMESOS2_TIMERS
199 Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
208 if ( single_proc_optimization() ) {
210 host_ordinal_type_array sp_rowptr;
211 host_ordinal_type_array sp_colind;
212 this->matrixA_->returnRowPtr_kokkos_view(sp_rowptr);
213 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr.data() ==
nullptr,
214 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
215 this->matrixA_->returnColInd_kokkos_view(sp_colind);
216 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind.data() ==
nullptr,
217 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
219 host_value_type_array hsp_values;
220 this->matrixA_->returnValues_kokkos_view(hsp_values);
221 shylubasker_dtype * sp_values = function_map::convert_scalar(hsp_values.data());
224 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
225 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
228 info = ShyLUbasker->Factor( this->globalNumRows_,
229 this->globalNumCols_,
230 this->globalNumNonZeros_,
235 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
236 std::runtime_error,
"Error ShyLUBasker Factor");
241 shylubasker_dtype * sp_values = function_map::convert_scalar(nzvals_view_.data());
242 info = ShyLUbasker->Factor(this->globalNumRows_,
243 this->globalNumCols_,
244 this->globalNumNonZeros_,
249 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
250 std::runtime_error,
"Error ShyLUBasker Factor");
255 local_ordinal_type blnnz = local_ordinal_type(0);
256 local_ordinal_type bunnz = local_ordinal_type(0);
257 ShyLUbasker->GetLnnz(blnnz);
258 ShyLUbasker->GetUnnz(bunnz);
262 this->setNnzLU( as<size_t>( blnnz + bunnz ) );
268 Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
272 TEUCHOS_TEST_FOR_EXCEPTION(info == -1,
274 "ShyLUBasker: Could not alloc space for L and U");
275 TEUCHOS_TEST_FOR_EXCEPTION(info == -2,
277 "ShyLUBasker: Could not alloc needed work space");
278 TEUCHOS_TEST_FOR_EXCEPTION(info == -3,
280 "ShyLUBasker: Could not alloc additional memory needed for L and U");
281 TEUCHOS_TEST_FOR_EXCEPTION(info > 0,
283 "ShyLUBasker: Zero pivot found at: " << info );
289 template <
class Matrix,
class Vector>
295 #ifdef HAVE_AMESOS2_TIMERS
296 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
303 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
304 const size_t nrhs = X->getGlobalNumVectors();
306 const bool ShyluBaskerTransposeRequest = this->control_.useTranspose_;
307 const bool initialize_data =
true;
308 const bool do_not_initialize_data =
false;
310 if ( single_proc_optimization() && nrhs == 1 ) {
313 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
314 host_solve_array_t>::do_get(initialize_data, B, bValues_, as<size_t>(ld_rhs));
316 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
317 host_solve_array_t>::do_get(do_not_initialize_data, X, xValues_, as<size_t>(ld_rhs));
322 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
323 host_solve_array_t>::do_get(initialize_data, B, bValues_,
325 (is_contiguous_ ==
true) ? ROOTED : CONTIGUOUS_AND_ROOTED,
326 this->rowIndexBase_);
329 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
330 host_solve_array_t>::do_get(do_not_initialize_data, X, xValues_,
332 (is_contiguous_ ==
true) ? ROOTED : CONTIGUOUS_AND_ROOTED,
333 this->rowIndexBase_);
337 shylubasker_dtype * pxValues = function_map::convert_scalar(xValues_.data());
338 shylubasker_dtype * pbValues = function_map::convert_scalar(bValues_.data());
339 if (!ShyluBaskerTransposeRequest)
340 ierr = ShyLUbasker->Solve(nrhs, pbValues, pxValues);
342 ierr = ShyLUbasker->Solve(nrhs, pbValues, pxValues,
true);
346 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
348 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
350 "Encountered zero diag element at: " << ierr);
351 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
353 "Could not alloc needed working memory for solve" );
355 Util::put_1d_data_helper_kokkos_view<
358 (is_contiguous_ ==
true) ? ROOTED : CONTIGUOUS_AND_ROOTED);
364 template <
class Matrix,
class Vector>
369 return( this->globalNumRows_ == this->globalNumCols_ );
373 template <
class Matrix,
class Vector>
378 using Teuchos::getIntegralValue;
379 using Teuchos::ParameterEntryValidator;
381 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
383 if(parameterList->isParameter(
"IsContiguous"))
385 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
388 if(parameterList->isParameter(
"num_threads"))
390 num_threads = parameterList->get<
int>(
"num_threads");
392 if(parameterList->isParameter(
"pivot"))
394 ShyLUbasker->Options.no_pivot = (!parameterList->get<
bool>(
"pivot"));
396 if(parameterList->isParameter(
"delayed pivot"))
398 ShyLUbasker->Options.static_delayed_pivot = (parameterList->get<
int>(
"delayed pivot"));
400 if(parameterList->isParameter(
"pivot_tol"))
402 ShyLUbasker->Options.pivot_tol = parameterList->get<
double>(
"pivot_tol");
404 if(parameterList->isParameter(
"symmetric"))
406 ShyLUbasker->Options.symmetric = parameterList->get<
bool>(
"symmetric");
408 if(parameterList->isParameter(
"realloc"))
410 ShyLUbasker->Options.realloc = parameterList->get<
bool>(
"realloc");
412 if(parameterList->isParameter(
"verbose"))
414 ShyLUbasker->Options.verbose = parameterList->get<
bool>(
"verbose");
416 if(parameterList->isParameter(
"verbose_matrix"))
418 ShyLUbasker->Options.verbose_matrix_out = parameterList->get<
bool>(
"verbose_matrix");
420 if(parameterList->isParameter(
"btf"))
422 ShyLUbasker->Options.btf = parameterList->get<
bool>(
"btf");
424 if(parameterList->isParameter(
"use_metis"))
426 ShyLUbasker->Options.use_metis = parameterList->get<
bool>(
"use_metis");
428 if(parameterList->isParameter(
"use_nodeNDP"))
430 ShyLUbasker->Options.use_nodeNDP = parameterList->get<
bool>(
"use_nodeNDP");
432 if(parameterList->isParameter(
"run_nd_on_leaves"))
434 ShyLUbasker->Options.run_nd_on_leaves = parameterList->get<
bool>(
"run_nd_on_leaves");
436 if(parameterList->isParameter(
"run_amd_on_leaves"))
438 ShyLUbasker->Options.run_amd_on_leaves = parameterList->get<
bool>(
"run_amd_on_leaves");
440 if(parameterList->isParameter(
"amd_on_blocks"))
442 ShyLUbasker->Options.amd_dom = parameterList->get<
bool>(
"amd_on_blocks");
444 if(parameterList->isParameter(
"transpose"))
447 const auto transpose = parameterList->get<
bool>(
"transpose");
449 this->control_.useTranspose_ =
true;
451 if(parameterList->isParameter(
"use_sequential_diag_facto"))
453 ShyLUbasker->Options.use_sequential_diag_facto = parameterList->get<
bool>(
"use_sequential_diag_facto");
455 if(parameterList->isParameter(
"user_fill"))
457 ShyLUbasker->Options.user_fill = parameterList->get<
double>(
"user_fill");
459 if(parameterList->isParameter(
"prune"))
461 ShyLUbasker->Options.prune = parameterList->get<
bool>(
"prune");
463 if(parameterList->isParameter(
"replace_tiny_pivot"))
465 ShyLUbasker->Options.replace_tiny_pivot = parameterList->get<
bool>(
"replace_tiny_pivot");
467 if(parameterList->isParameter(
"btf_matching"))
469 ShyLUbasker->Options.btf_matching = parameterList->get<
int>(
"btf_matching");
470 if (ShyLUbasker->Options.btf_matching == 1 || ShyLUbasker->Options.btf_matching == 2) {
471 ShyLUbasker->Options.matching =
true;
473 ShyLUbasker->Options.matching =
false;
476 if(parameterList->isParameter(
"blk_matching"))
478 ShyLUbasker->Options.blk_matching = parameterList->get<
int>(
"blk_matching");
480 if(parameterList->isParameter(
"matrix_scaling"))
482 ShyLUbasker->Options.matrix_scaling = parameterList->get<
int>(
"matrix_scaling");
484 if(parameterList->isParameter(
"min_block_size"))
486 ShyLUbasker->Options.min_block_size = parameterList->get<
int>(
"min_block_size");
490 template <
class Matrix,
class Vector>
491 Teuchos::RCP<const Teuchos::ParameterList>
494 using Teuchos::ParameterList;
496 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
498 if( is_null(valid_params) )
500 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
501 pl->set(
"IsContiguous",
true,
502 "Are GIDs contiguous");
503 pl->set(
"num_threads", 1,
504 "Number of threads");
505 pl->set(
"pivot",
false,
507 pl->set(
"delayed pivot", 0,
508 "Apply static delayed pivot on a big block");
509 pl->set(
"pivot_tol", .0001,
510 "Tolerance before pivot, currently not used");
511 pl->set(
"symmetric",
false,
512 "Should Symbolic assume symmetric nonzero pattern");
513 pl->set(
"realloc" ,
false,
514 "Should realloc space if not enough");
515 pl->set(
"verbose",
false,
516 "Information about factoring");
517 pl->set(
"verbose_matrix",
false,
518 "Give Permuted Matrices");
521 pl->set(
"prune",
false,
522 "Use prune on BTF blocks (Not Supported)");
523 pl->set(
"btf_matching", 2,
524 "Matching option for BTF: 0 = none, 1 = Basker, 2 = Trilinos (default), (3 = MC64 if enabled)");
525 pl->set(
"blk_matching", 1,
526 "Matching optioon for block: 0 = none, 1 or anything else = Basker (default), (2 = MC64 if enabled)");
527 pl->set(
"matrix_scaling", 0,
528 "Use matrix scaling to biig A BTF block: 0 = no-scaling, 1 = symmetric diagonal scaling, 2 = row-max, and then col-max scaling");
529 pl->set(
"min_block_size", 0,
530 "Size of the minimum diagonal blocks");
531 pl->set(
"replace_tiny_pivot",
false,
532 "Replace tiny pivots during the numerical factorization");
533 pl->set(
"use_metis",
true,
535 pl->set(
"use_nodeNDP",
true,
536 "Use nodeND to compute ND partition");
537 pl->set(
"run_nd_on_leaves",
false,
538 "Run ND on the final leaf-nodes for ND factorization");
539 pl->set(
"run_amd_on_leaves",
false,
540 "Run AMD on the final leaf-nodes for ND factorization");
541 pl->set(
"amd_on_blocks",
true,
542 "Run AMD on each diagonal blocks");
543 pl->set(
"transpose",
false,
544 "Solve the transpose A");
545 pl->set(
"use_sequential_diag_facto",
false,
546 "Use sequential algorithm to factor each diagonal block");
547 pl->set(
"user_fill", (
double)BASKER_FILL_USER,
548 "User-provided padding for the fill ratio");
555 template <
class Matrix,
class Vector>
560 if(current_phase == SOLVE)
return (
false);
562 #ifdef HAVE_AMESOS2_TIMERS
563 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
568 if ( single_proc_optimization() ) {
577 Kokkos::resize(nzvals_view_, this->globalNumNonZeros_);
578 Kokkos::resize(rowind_view_, this->globalNumNonZeros_);
579 Kokkos::resize(colptr_view_, this->globalNumCols_ + 1);
582 local_ordinal_type nnz_ret = 0;
584 #ifdef HAVE_AMESOS2_TIMERS
585 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
590 ::do_get(this->matrixA_.ptr(), nzvals_view_, rowind_view_, colptr_view_, nnz_ret,
591 (is_contiguous_ ==
true) ? ROOTED : CONTIGUOUS_AND_ROOTED,
593 this->rowIndexBase_);
597 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->globalNumNonZeros_),
599 "Amesos2_ShyLUBasker loadA_impl: Did not get the expected number of non-zero vals");
607 template<
class Matrix,
class Vector>
613 #endif // AMESOS2_SHYLUBASKER_DEF_HPP
A generic helper class for getting a CCS representation of a Matrix.
Definition: Amesos2_Util.hpp:614
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
ShyLUBasker specific solve.
Definition: Amesos2_ShyLUBasker_def.hpp:291
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:31
Amesos2 interface to the Baker package.
Definition: Amesos2_ShyLUBasker_decl.hpp:42
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_ShyLUBasker_def.hpp:492
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_ShyLUBasker_def.hpp:107
void transpose(ArrayView< Scalar > vals, ArrayView< GlobalOrdinal > indices, ArrayView< GlobalSizeT > ptr, ArrayView< Scalar > trans_vals, ArrayView< GlobalOrdinal > trans_indices, ArrayView< GlobalSizeT > trans_ptr)
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_ShyLUBasker_def.hpp:366
Amesos2 ShyLUBasker declarations.
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_ShyLUBasker_def.hpp:557
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:42
int numericFactorization_impl()
ShyLUBasker specific numeric factorization.
Definition: Amesos2_ShyLUBasker_def.hpp:191
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:142
bool single_proc_optimization() const
can we optimize size_type and ordinal_type for straight pass through, also check that is_contiguous_ ...
Definition: Amesos2_ShyLUBasker_def.hpp:101