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>
33template <
class Matrix,
class Vector>
34ShyLUBasker<Matrix,Vector>::ShyLUBasker(
35 Teuchos::RCP<const Matrix> A,
36 Teuchos::RCP<Vector> X,
37 Teuchos::RCP<const Vector> B )
39 , is_contiguous_(true)
47#if defined(HAVE_AMESOS2_KOKKOS) && defined(KOKKOS_ENABLE_OPENMP)
52 ShyLUbasker = new ::BaskerNS::BaskerTrilinosInterface<local_ordinal_type, shylubasker_dtype, Exe_Space>();
53 ShyLUbasker->Options.no_pivot = BASKER_FALSE;
54 ShyLUbasker->Options.static_delayed_pivot = 0;
55 ShyLUbasker->Options.symmetric = BASKER_FALSE;
56 ShyLUbasker->Options.realloc = BASKER_TRUE;
57 ShyLUbasker->Options.verbose = BASKER_FALSE;
58 ShyLUbasker->Options.prune = BASKER_TRUE;
59 ShyLUbasker->Options.btf_matching = 2;
60 ShyLUbasker->Options.blk_matching = 1;
61 ShyLUbasker->Options.matrix_scaling = 0;
62 ShyLUbasker->Options.min_block_size = 0;
63 ShyLUbasker->Options.amd_dom = BASKER_TRUE;
64 ShyLUbasker->Options.use_metis = BASKER_TRUE;
65 ShyLUbasker->Options.use_nodeNDP = BASKER_TRUE;
66 ShyLUbasker->Options.run_nd_on_leaves = BASKER_TRUE;
67 ShyLUbasker->Options.run_amd_on_leaves = BASKER_FALSE;
68 ShyLUbasker->Options.transpose = BASKER_FALSE;
69 ShyLUbasker->Options.replace_tiny_pivot = BASKER_FALSE;
70 ShyLUbasker->Options.verbose_matrix_out = BASKER_FALSE;
72 ShyLUbasker->Options.user_fill = (double)BASKER_FILL_USER;
73 ShyLUbasker->Options.use_sequential_diag_facto = BASKER_FALSE;
74#ifdef KOKKOS_ENABLE_DEPRECATED_CODE
75 num_threads = Kokkos::OpenMP::max_hardware_threads();
77 num_threads = Kokkos::OpenMP::impl_max_hardware_threads();
81 TEUCHOS_TEST_FOR_EXCEPTION(1 != 0,
83 "Amesos2_ShyLUBasker Exception: Do not have supported Kokkos node type (OpenMP) enabled for ShyLUBasker");
88template <
class Matrix,
class Vector>
89ShyLUBasker<Matrix,Vector>::~ShyLUBasker( )
92#if defined(HAVE_AMESOS2_KOKKOS) && defined(KOKKOS_ENABLE_OPENMP)
93 ShyLUbasker->Finalize();
98template <
class Matrix,
class Vector>
101 return (this->
root_ && (this->
matrixA_->getComm()->getSize() == 1) && is_contiguous_);
104template<
class Matrix,
class Vector>
110#ifdef HAVE_AMESOS2_TIMERS
111 Teuchos::TimeMonitor preOrderTimer(this->
timers_.preOrderTime_);
118template <
class Matrix,
class Vector>
120ShyLUBasker<Matrix,Vector>::symbolicFactorization_impl()
126 ShyLUbasker->SetThreads(num_threads);
134 if ( single_proc_optimization() ) {
136 host_ordinal_type_array sp_rowptr;
137 host_ordinal_type_array sp_colind;
139 this->matrixA_->returnRowPtr_kokkos_view(sp_rowptr);
140 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr.data() ==
nullptr,
141 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
142 this->matrixA_->returnColInd_kokkos_view(sp_colind);
143 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind.data() ==
nullptr,
144 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
146 host_value_type_array hsp_values;
147 this->matrixA_->returnValues_kokkos_view(hsp_values);
148 shylubasker_dtype * sp_values = function_map::convert_scalar(hsp_values.data());
150 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
151 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
154 info = ShyLUbasker->Symbolic(this->globalNumRows_,
155 this->globalNumCols_,
156 this->globalNumNonZeros_,
162 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
163 std::runtime_error,
"Error in ShyLUBasker Symbolic");
168 shylubasker_dtype * sp_values = function_map::convert_scalar(nzvals_view_.data());
169 info = ShyLUbasker->Symbolic(this->globalNumRows_,
170 this->globalNumCols_,
171 this->globalNumNonZeros_,
176 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
177 std::runtime_error,
"Error in ShyLUBasker Symbolic");
183 Teuchos::broadcast(*(this->matrixA_->getComm()), 0, &info);
188template <
class Matrix,
class Vector>
197#ifdef HAVE_AMESOS2_TIMERS
198 Teuchos::TimeMonitor numFactTimer(this->
timers_.numFactTime_);
208 host_ordinal_type_array sp_rowptr;
209 host_ordinal_type_array sp_colind;
210 this->
matrixA_->returnRowPtr_kokkos_view(sp_rowptr);
211 TEUCHOS_TEST_FOR_EXCEPTION(sp_rowptr.data() ==
nullptr,
212 std::runtime_error,
"Amesos2 Runtime Error: sp_rowptr returned null ");
213 this->
matrixA_->returnColInd_kokkos_view(sp_colind);
214 TEUCHOS_TEST_FOR_EXCEPTION(sp_colind.data() ==
nullptr,
215 std::runtime_error,
"Amesos2 Runtime Error: sp_colind returned null ");
217 host_value_type_array hsp_values;
218 this->
matrixA_->returnValues_kokkos_view(hsp_values);
219 shylubasker_dtype * sp_values = function_map::convert_scalar(hsp_values.data());
222 TEUCHOS_TEST_FOR_EXCEPTION(sp_values ==
nullptr,
223 std::runtime_error,
"Amesos2 Runtime Error: sp_values returned null ");
233 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
234 std::runtime_error,
"Error ShyLUBasker Factor");
239 shylubasker_dtype * sp_values = function_map::convert_scalar(
nzvals_view_.data());
247 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
248 std::runtime_error,
"Error ShyLUBasker Factor");
253 local_ordinal_type blnnz = local_ordinal_type(0);
254 local_ordinal_type bunnz = local_ordinal_type(0);
255 ShyLUbasker->GetLnnz(blnnz);
256 ShyLUbasker->GetUnnz(bunnz);
260 this->
setNnzLU( as<size_t>( blnnz + bunnz ) );
266 Teuchos::broadcast(*(this->
matrixA_->getComm()), 0, &info);
270 TEUCHOS_TEST_FOR_EXCEPTION(info == -1,
272 "ShyLUBasker: Could not alloc space for L and U");
273 TEUCHOS_TEST_FOR_EXCEPTION(info == -2,
275 "ShyLUBasker: Could not alloc needed work space");
276 TEUCHOS_TEST_FOR_EXCEPTION(info == -3,
278 "ShyLUBasker: Could not alloc additional memory needed for L and U");
279 TEUCHOS_TEST_FOR_EXCEPTION(info > 0,
281 "ShyLUBasker: Zero pivot found at: " << info );
287template <
class Matrix,
class Vector>
297 const global_size_type ld_rhs = this->
root_ ? X->getGlobalLength() : 0;
298 const size_t nrhs = X->getGlobalNumVectors();
300 const bool ShyluBaskerTransposeRequest = this->
control_.useTranspose_;
301 const bool initialize_data =
true;
302 const bool do_not_initialize_data =
false;
303 bool use_gather = use_gather_;
304 use_gather = (use_gather && this->
matrixA_->getComm()->getSize() > 1);
305 use_gather = (use_gather && (std::is_same<scalar_type, float>::value || std::is_same<scalar_type, double>::value));
307#ifdef HAVE_AMESOS2_TIMERS
308 Teuchos::TimeMonitor mvConvTimer(this->
timers_.vecConvTime_);
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 int rval = B->gather(
bValues_, this->perm_g2l, this->recvCountRows, this->recvDisplRows,
325 X->gather(
xValues_, this->perm_g2l, this->recvCountRows, this->recvDisplRows,
332 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
333 host_solve_array_t>::do_get(initialize_data, B,
bValues_,
339 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
340 host_solve_array_t>::do_get(do_not_initialize_data, X,
xValues_,
349#ifdef HAVE_AMESOS2_TIMERS
350 Teuchos::TimeMonitor solveTimer(this->
timers_.solveTime_);
353 shylubasker_dtype * pxValues = function_map::convert_scalar(
xValues_.data());
354 shylubasker_dtype * pbValues = function_map::convert_scalar(
bValues_.data());
355 if (!ShyluBaskerTransposeRequest)
356 ierr = ShyLUbasker->Solve(nrhs, pbValues, pxValues);
358 ierr = ShyLUbasker->Solve(nrhs, pbValues, pxValues,
true);
361 Teuchos::broadcast(*(this->
getComm()), 0, &ierr);
363 TEUCHOS_TEST_FOR_EXCEPTION( ierr > 0,
365 "Encountered zero diag element at: " << ierr);
366 TEUCHOS_TEST_FOR_EXCEPTION( ierr == -1,
368 "Could not alloc needed working memory for solve" );
370#ifdef HAVE_AMESOS2_TIMERS
371 Teuchos::TimeMonitor redistTimer(this->
timers_.vecRedistTime_);
374 int rval = X->scatter(
xValues_, this->perm_g2l, this->recvCountRows, this->recvDisplRows,
376 if (rval != 0) use_gather =
false;
379 Util::put_1d_data_helper_kokkos_view<
389template <
class Matrix,
class Vector>
398template <
class Matrix,
class Vector>
400ShyLUBasker<Matrix,Vector>::setParameters_impl(
const Teuchos::RCP<Teuchos::ParameterList> & parameterList )
403 using Teuchos::getIntegralValue;
404 using Teuchos::ParameterEntryValidator;
406 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
408 if(parameterList->isParameter(
"IsContiguous"))
410 is_contiguous_ = parameterList->get<
bool>(
"IsContiguous");
413 if(parameterList->isParameter(
"UseCustomGather"))
415 use_gather_ = parameterList->get<
bool>(
"UseCustomGather");
418 if(parameterList->isParameter(
"num_threads"))
420 num_threads = parameterList->get<
int>(
"num_threads");
422 if(parameterList->isParameter(
"pivot"))
424 ShyLUbasker->Options.no_pivot = (!parameterList->get<
bool>(
"pivot"));
426 if(parameterList->isParameter(
"delayed pivot"))
428 ShyLUbasker->Options.static_delayed_pivot = (parameterList->get<
int>(
"delayed pivot"));
430 if(parameterList->isParameter(
"pivot_tol"))
432 ShyLUbasker->Options.pivot_tol = parameterList->get<
double>(
"pivot_tol");
434 if(parameterList->isParameter(
"symmetric"))
436 ShyLUbasker->Options.symmetric = parameterList->get<
bool>(
"symmetric");
438 if(parameterList->isParameter(
"realloc"))
440 ShyLUbasker->Options.realloc = parameterList->get<
bool>(
"realloc");
442 if(parameterList->isParameter(
"verbose"))
444 ShyLUbasker->Options.verbose = parameterList->get<
bool>(
"verbose");
446 if(parameterList->isParameter(
"verbose_matrix"))
448 ShyLUbasker->Options.verbose_matrix_out = parameterList->get<
bool>(
"verbose_matrix");
450 if(parameterList->isParameter(
"btf"))
452 ShyLUbasker->Options.btf = parameterList->get<
bool>(
"btf");
454 if(parameterList->isParameter(
"use_metis"))
456 ShyLUbasker->Options.use_metis = parameterList->get<
bool>(
"use_metis");
458 if(parameterList->isParameter(
"use_nodeNDP"))
460 ShyLUbasker->Options.use_nodeNDP = parameterList->get<
bool>(
"use_nodeNDP");
462 if(parameterList->isParameter(
"run_nd_on_leaves"))
464 ShyLUbasker->Options.run_nd_on_leaves = parameterList->get<
bool>(
"run_nd_on_leaves");
466 if(parameterList->isParameter(
"run_amd_on_leaves"))
468 ShyLUbasker->Options.run_amd_on_leaves = parameterList->get<
bool>(
"run_amd_on_leaves");
470 if(parameterList->isParameter(
"amd_on_blocks"))
472 ShyLUbasker->Options.amd_dom = parameterList->get<
bool>(
"amd_on_blocks");
474 if(parameterList->isParameter(
"transpose"))
477 const auto transpose = parameterList->get<
bool>(
"transpose");
478 if (transpose ==
true)
479 this->control_.useTranspose_ =
true;
481 if(parameterList->isParameter(
"use_sequential_diag_facto"))
483 ShyLUbasker->Options.use_sequential_diag_facto = parameterList->get<
bool>(
"use_sequential_diag_facto");
485 if(parameterList->isParameter(
"user_fill"))
487 ShyLUbasker->Options.user_fill = parameterList->get<
double>(
"user_fill");
489 if(parameterList->isParameter(
"prune"))
491 ShyLUbasker->Options.prune = parameterList->get<
bool>(
"prune");
493 if(parameterList->isParameter(
"replace_tiny_pivot"))
495 ShyLUbasker->Options.replace_tiny_pivot = parameterList->get<
bool>(
"replace_tiny_pivot");
497 if(parameterList->isParameter(
"btf_matching"))
499 ShyLUbasker->Options.btf_matching = parameterList->get<
int>(
"btf_matching");
500 if (ShyLUbasker->Options.btf_matching == 1 || ShyLUbasker->Options.btf_matching == 2) {
501 ShyLUbasker->Options.matching =
true;
503 ShyLUbasker->Options.matching =
false;
506 if(parameterList->isParameter(
"blk_matching"))
508 ShyLUbasker->Options.blk_matching = parameterList->get<
int>(
"blk_matching");
510 if(parameterList->isParameter(
"matrix_scaling"))
512 ShyLUbasker->Options.matrix_scaling = parameterList->get<
int>(
"matrix_scaling");
514 if(parameterList->isParameter(
"min_block_size"))
516 ShyLUbasker->Options.min_block_size = parameterList->get<
int>(
"min_block_size");
520template <
class Matrix,
class Vector>
521Teuchos::RCP<const Teuchos::ParameterList>
524 using Teuchos::ParameterList;
526 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
528 if( is_null(valid_params) )
530 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
531 pl->set(
"IsContiguous",
true,
532 "Are GIDs contiguous");
533 pl->set(
"UseCustomGather",
true,
534 "Use Matrix-gather routine");
535 pl->set(
"num_threads", 1,
536 "Number of threads");
537 pl->set(
"pivot",
false,
539 pl->set(
"delayed pivot", 0,
540 "Apply static delayed pivot on a big block");
541 pl->set(
"pivot_tol", .0001,
542 "Tolerance before pivot, currently not used");
543 pl->set(
"symmetric",
false,
544 "Should Symbolic assume symmetric nonzero pattern");
545 pl->set(
"realloc" ,
false,
546 "Should realloc space if not enough");
547 pl->set(
"verbose",
false,
548 "Information about factoring");
549 pl->set(
"verbose_matrix",
false,
550 "Give Permuted Matrices");
553 pl->set(
"prune",
false,
554 "Use prune on BTF blocks (Not Supported)");
555 pl->set(
"btf_matching", 2,
556 "Matching option for BTF: 0 = none, 1 = Basker, 2 = Trilinos (default), (3 = MC64 if enabled)");
557 pl->set(
"blk_matching", 1,
558 "Matching optioon for block: 0 = none, 1 or anything else = Basker (default), (2 = MC64 if enabled)");
559 pl->set(
"matrix_scaling", 0,
560 "Use matrix scaling to biig A BTF block: 0 = no-scaling, 1 = symmetric diagonal scaling, 2 = row-max, and then col-max scaling");
561 pl->set(
"min_block_size", 0,
562 "Size of the minimum diagonal blocks");
563 pl->set(
"replace_tiny_pivot",
false,
564 "Replace tiny pivots during the numerical factorization");
565 pl->set(
"use_metis",
true,
567 pl->set(
"use_nodeNDP",
true,
568 "Use nodeND to compute ND partition");
569 pl->set(
"run_nd_on_leaves",
false,
570 "Run ND on the final leaf-nodes for ND factorization");
571 pl->set(
"run_amd_on_leaves",
false,
572 "Run AMD on the final leaf-nodes for ND factorization");
573 pl->set(
"amd_on_blocks",
true,
574 "Run AMD on each diagonal blocks");
575 pl->set(
"transpose",
false,
576 "Solve the transpose A");
577 pl->set(
"use_sequential_diag_facto",
false,
578 "Use sequential algorithm to factor each diagonal block");
579 pl->set(
"user_fill", (
double)BASKER_FILL_USER,
580 "User-provided padding for the fill ratio");
587template <
class Matrix,
class Vector>
592 if(current_phase == SOLVE || current_phase == PREORDERING )
return(
false );
594 #ifdef HAVE_AMESOS2_TIMERS
595 Teuchos::TimeMonitor convTimer(this->
timers_.mtxConvTime_);
608 if( this->
root_ && current_phase == SYMBFACT )
615 local_ordinal_type nnz_ret = -1;
616 bool use_gather = use_gather_;
617 use_gather = (use_gather && this->
matrixA_->getComm()->getSize() > 1);
618 use_gather = (use_gather && (std::is_same<scalar_type, float>::value || std::is_same<scalar_type, double>::value));
620 #ifdef HAVE_AMESOS2_TIMERS
621 Teuchos::TimeMonitor mtxRedistTimer( this->
timers_.mtxRedistTime_ );
624 bool column_major =
true;
625 if (!is_contiguous_) {
626 auto contig_mat = this->
matrixA_->reindex(this->contig_rowmap_, this->contig_colmap_, current_phase);
628 this->transpose_map, this->nzvals_t, column_major, current_phase);
631 this->transpose_map, this->nzvals_t, column_major, current_phase);
635 if (nnz_ret < 0) use_gather =
false;
643 this->rowIndexBase_);
648 if (use_gather || this->
root_) {
649 TEUCHOS_TEST_FOR_EXCEPTION( nnz_ret != as<local_ordinal_type>(this->
globalNumNonZeros_),
651 "Amesos2_ShyLUBasker loadA_impl: Did not get the expected number of non-zero vals("
659template<
class Matrix,
class Vector>
Amesos2 ShyLUBasker declarations.
@ ROOTED
Definition Amesos2_TypeDecl.hpp:93
@ CONTIGUOUS_AND_ROOTED
Definition Amesos2_TypeDecl.hpp:94
@ ARBITRARY
Definition Amesos2_TypeDecl.hpp:109
A Matrix adapter interface for Amesos2.
Definition Amesos2_MatrixAdapter_decl.hpp:42
Amesos2 interface to the Baker package.
Definition Amesos2_ShyLUBasker_decl.hpp:43
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition Amesos2_ShyLUBasker_def.hpp:589
host_ordinal_type_array colptr_view_
Stores the row indices of the nonzero entries.
Definition Amesos2_ShyLUBasker_decl.hpp:169
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:289
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition Amesos2_ShyLUBasker_def.hpp:522
int numericFactorization_impl()
ShyLUBasker specific numeric factorization.
Definition Amesos2_ShyLUBasker_def.hpp:190
host_value_type_array nzvals_view_
Stores the values of the nonzero entries for Umfpack.
Definition Amesos2_ShyLUBasker_decl.hpp:165
static const char * name
Name of this solver interface.
Definition Amesos2_ShyLUBasker_decl.hpp:50
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition Amesos2_ShyLUBasker_def.hpp:106
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:100
host_solve_array_t xValues_
Persisting 1D store for X.
Definition Amesos2_ShyLUBasker_decl.hpp:179
host_ordinal_type_array rowind_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition Amesos2_ShyLUBasker_decl.hpp:167
host_solve_array_t bValues_
Persisting 1D store for B.
Definition Amesos2_ShyLUBasker_decl.hpp:183
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition Amesos2_ShyLUBasker_def.hpp:391
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers.
Definition Amesos2_SolverCore_decl.hpp:72
Teuchos::RCP< const MatrixAdapter< Matrix > > matrixA_
Definition Amesos2_SolverCore_decl.hpp:421
bool root_
Definition Amesos2_SolverCore_decl.hpp:472
void setNnzLU(size_t nnz)
Definition Amesos2_SolverCore_decl.hpp:418
global_size_type rowIndexBase_
Definition Amesos2_SolverCore_decl.hpp:451
global_size_type globalNumCols_
Definition Amesos2_SolverCore_decl.hpp:445
Timers timers_
Definition Amesos2_SolverCore_decl.hpp:463
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
Definition Amesos2_SolverCore_decl.hpp:329
global_size_type globalNumNonZeros_
Definition Amesos2_SolverCore_decl.hpp:448
global_size_type globalNumRows_
Definition Amesos2_SolverCore_decl.hpp:442
Control control_
Definition Amesos2_SolverCore_decl.hpp:460
EPhase
Used to indicate a phase in the direct solution.
Definition Amesos2_TypeDecl.hpp:31
void transpose(ArrayView< Scalar > vals, ArrayView< GlobalOrdinal > indices, ArrayView< GlobalSizeT > ptr, ArrayView< Scalar > trans_vals, ArrayView< GlobalOrdinal > trans_indices, ArrayView< GlobalSizeT > trans_ptr)
A templated MultiVector class adapter for Amesos2.
Definition Amesos2_MultiVecAdapter_decl.hpp:142
A generic helper class for getting a CCS representation of a Matrix.
Definition Amesos2_Util.hpp:615