10#ifndef AMESOS2_TACHO_DEF_HPP
11#define AMESOS2_TACHO_DEF_HPP
13#include <Teuchos_Tuple.hpp>
14#include <Teuchos_ParameterList.hpp>
15#include <Teuchos_StandardParameterEntryValidators.hpp>
18#include "Amesos2_Tacho_decl.hpp"
23template <
class Matrix,
class Vector>
25 Teuchos::RCP<const Matrix> A,
26 Teuchos::RCP<Vector> X,
27 Teuchos::RCP<const Vector> B )
33 data_.dofs_per_node = 1;
34 data_.pivot_pert =
false;
35 data_.diag_shift =
false;
36 data_.verbose =
false;
37 data_.small_problem_threshold_size = 1024;
41template <
class Matrix,
class Vector>
45 data_.solver.release();
49template <
class Matrix,
class Vector>
53 std::ostringstream oss;
54 oss <<
"Tacho solver interface";
58template<
class Matrix,
class Vector>
65template <
class Matrix,
class Vector>
69#ifdef HAVE_AMESOS2_TIMERS
70 Teuchos::TimeMonitor symFactTime( this->timers_.symFactTime_ );
75 if(do_optimization()) {
76 this->matrixA_->returnRowPtr_kokkos_view(host_row_ptr_view_);
77 this->matrixA_->returnColInd_kokkos_view(host_cols_view_);
80 if (data_.diag_shift) {
81 data_.solver.shiftDiagonal();
83 data_.solver.setSolutionMethod(data_.method);
84 data_.solver.setLevelSetOptionAlgorithmVariant(data_.variant);
85 data_.solver.setSmallProblemThresholdsize(data_.small_problem_threshold_size);
86 data_.solver.setVerbose(data_.verbose);
87 data_.solver.setLevelSetOptionNumStreams(data_.streams);
92 if (data_.dofs_per_node > 1) {
93 data_.solver.analyze(this->globalNumCols_, data_.dofs_per_node, host_row_ptr_view_, host_cols_view_);
95 data_.solver.analyze(this->globalNumCols_, host_row_ptr_view_, host_cols_view_);
97 data_.solver.initialize();
103template <
class Matrix,
class Vector>
107#ifdef HAVE_AMESOS2_TIMERS
108 Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
113 if(do_optimization()) {
117 device_value_type_array device_nzvals_temp;
118 this->matrixA_->returnValues_kokkos_view(device_nzvals_temp);
119 Kokkos::deep_copy(device_nzvals_view_, device_nzvals_temp);
121 if (data_.pivot_pert) {
122 data_.solver.useDefaultPivotTolerance();
124 data_.solver.useNoPivotTolerance();
126 data_.solver.factorize(device_nzvals_view_);
131template <
class Matrix,
class Vector>
138 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
139 const size_t nrhs = X->getGlobalNumVectors();
148#ifdef HAVE_AMESOS2_TIMERS
149 Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
151 const bool initialize_data =
true;
152 const bool do_not_initialize_data =
false;
153 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
154 device_solve_array_t>::do_get(initialize_data, B, this->bValues_,
156 ROOTED, this->rowIndexBase_);
157 bDidAssignX = Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
158 device_solve_array_t>::do_get(do_not_initialize_data, X, this->xValues_,
160 ROOTED, this->rowIndexBase_);
167#ifdef HAVE_AMESOS2_TIMERS
168 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
170 if (workspace_.extent(0) < this->globalNumRows_ || workspace_.extent(1) < nrhs) {
171 workspace_ = device_solve_array_t(
172 Kokkos::ViewAllocateWithoutInitializing(
"t"), this->globalNumRows_, nrhs);
175 data_.solver.solve(xValues_, bValues_, workspace_);
184 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
186 TEUCHOS_TEST_FOR_EXCEPTION( ierr != 0, std::runtime_error,
187 "tacho_solve has error code: " << ierr );
194#ifdef HAVE_AMESOS2_TIMERS
195 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
200 Util::template put_1d_data_helper_kokkos_view<
203 ROOTED, this->rowIndexBase_);
210template <
class Matrix,
class Vector>
215 return( this->matrixA_->getGlobalNumRows() == this->matrixA_->getGlobalNumCols() );
219template <
class Matrix,
class Vector>
223 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
228 auto method_name = parameterList->get<std::string> (
"method",
"chol");
229 if (method_name ==
"ldl-nopiv")
231 else if (method_name ==
"chol")
233 else if (method_name ==
"ldl")
235 else if (method_name ==
"lu")
238 std::cout <<
"Error: not supported solution method\n";
241 data_.variant = parameterList->get<
int> (
"variant", 2);
243 data_.small_problem_threshold_size = parameterList->get<
int> (
"small problem threshold size", 1024);
245 data_.verbose = parameterList->get<
bool> (
"verbose",
false);
247 data_.streams = parameterList->get<
int> (
"num-streams", 1);
249 data_.dofs_per_node = parameterList->get<
int> (
"dofs-per-node", 1);
251 data_.pivot_pert = parameterList->get<
bool> (
"perturb-pivot",
false);
252 data_.diag_shift = parameterList->get<
bool> (
"shift-diag",
false);
259template <
class Matrix,
class Vector>
260Teuchos::RCP<const Teuchos::ParameterList>
263 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
265 if( is_null(valid_params) ){
266 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
268 pl->set(
"method",
"chol",
"Type of factorization, chol, ldl, or lu");
269 pl->set(
"variant", 2,
"Type of solver variant, 0, 1, or 2");
270 pl->set(
"small problem threshold size", 1024,
"Problem size threshold below with Tacho uses LAPACK.");
271 pl->set(
"verbose",
false,
"Verbosity");
272 pl->set(
"num-streams", 1,
"Number of GPU streams");
273 pl->set(
"dofs-per-node", 1,
"DoFs per node");
274 pl->set(
"perturb-pivot",
false,
"Perturb tiny pivots");
275 pl->set(
"shift-diag",
false,
"Shift diagonal entries");
287template <
class Matrix,
class Vector>
290 return (this->root_ && (this->matrixA_->getComm()->getSize() == 1));
293template <
class Matrix,
class Vector>
298 if(current_phase == SOLVE) {
302 if(!do_optimization()) {
303#ifdef HAVE_AMESOS2_TIMERS
304 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
315 if (device_nzvals_view_.extent(0) != this->globalNumNonZeros_)
316 Kokkos::resize(device_nzvals_view_, this->globalNumNonZeros_);
317 if (host_cols_view_.extent(0) != this->globalNumNonZeros_)
318 Kokkos::resize(host_cols_view_, this->globalNumNonZeros_);
319 if (host_row_ptr_view_.extent(0) != this->globalNumRows_ + 1)
320 Kokkos::resize(host_row_ptr_view_, this->globalNumRows_ + 1);
322 Kokkos::resize(device_nzvals_view_, 0);
323 Kokkos::resize(host_cols_view_, 0);
324 Kokkos::resize(host_row_ptr_view_, 1);
328 typename host_size_type_array::value_type nnz_ret = 0;
330 #ifdef HAVE_AMESOS2_TIMERS
331 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
334 TEUCHOS_TEST_FOR_EXCEPTION( this->rowIndexBase_ != this->columnIndexBase_,
336 "Row and column maps have different indexbase ");
339 device_value_type_array, host_ordinal_type_array, host_size_type_array>::do_get(
340 this->matrixA_.ptr(),
346 this->columnIndexBase_);
353 device_nzvals_view_ = device_value_type_array(
354 Kokkos::ViewAllocateWithoutInitializing(
"nzvals"), this->globalNumNonZeros_);
362template <
class Matrix,
class Vector>
365 const Teuchos::EVerbosityLevel verbLevel)
const
367 out <<
" Tacho current parameters:" << std::endl;
368 out <<
" > method = " << data_.method;
369 if (data_.method == 0) out <<
" (ldl-nopiv)" << std::endl;
370 if (data_.method == 1) out <<
" (chol)" << std::endl;
371 if (data_.method == 2) out <<
" (ldl)" << std::endl;
372 if (data_.method == 3) out <<
" (lu)" << std::endl;
373 out <<
" > variant = " << data_.variant << std::endl;
374 out <<
" > verbose = " << data_.verbose << std::endl;
375 out <<
" > num-streams = " << data_.streams << std::endl;
376 out <<
" > dofs-per-node = " << data_.dofs_per_node << std::endl;
377 out <<
" > perturb-pivo = " << (data_.pivot_pert ?
"YES" :
"NO") << std::endl;
378 out <<
" > shift-diag = " << (data_.diag_shift ?
"YES" :
"NO") << std::endl;
379 out <<
" > small problem threshold size = " << data_.small_problem_threshold_size << std::endl;
384template<
class Matrix,
class Vector>
@ ROOTED
Definition Amesos2_TypeDecl.hpp:93
@ ARBITRARY
Definition Amesos2_TypeDecl.hpp:109
Utility functions for Amesos2.
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers.
Definition Amesos2_SolverCore_decl.hpp:72
Amesos2 interface to the Tacho package.
Definition Amesos2_Tacho_decl.hpp:34
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition Amesos2_Tacho_def.hpp:212
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition Amesos2_Tacho_def.hpp:261
int numericFactorization_impl()
Tacho specific numeric factorization.
Definition Amesos2_Tacho_def.hpp:105
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Tacho specific solve.
Definition Amesos2_Tacho_def.hpp:133
~TachoSolver()
Destructor.
Definition Amesos2_Tacho_def.hpp:42
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition Amesos2_Tacho_def.hpp:289
TachoSolver(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Initialize from Teuchos::RCP.
Definition Amesos2_Tacho_def.hpp:24
std::string description() const override
Returns a short description of this Solver.
Definition Amesos2_Tacho_def.hpp:51
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition Amesos2_Tacho_def.hpp:295
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Tacho.
Definition Amesos2_Tacho_def.hpp:67
void describe_impl(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the status information about the current solver with some level of verbosity.
Definition Amesos2_Tacho_def.hpp:364
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition Amesos2_Tacho_def.hpp:60
EPhase
Used to indicate a phase in the direct solution.
Definition Amesos2_TypeDecl.hpp:31
A templated MultiVector class adapter for Amesos2.
Definition Amesos2_MultiVecAdapter_decl.hpp:142
Similar to get_ccs_helper , but used to get a CRS representation of the given matrix.
Definition Amesos2_Util.hpp:600