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_.team_on_user_stream =
false;
38 data_.small_problem_threshold_size = 1024;
42template <
class Matrix,
class Vector>
46 data_.solver.release();
50template <
class Matrix,
class Vector>
54 std::ostringstream oss;
55 oss <<
"Tacho solver interface";
59template<
class Matrix,
class Vector>
66template <
class Matrix,
class Vector>
70#ifdef HAVE_AMESOS2_TIMERS
71 Teuchos::TimeMonitor symFactTime( this->timers_.symFactTime_ );
76 if(do_optimization()) {
77 this->matrixA_->returnRowPtr_kokkos_view(host_row_ptr_view_);
78 this->matrixA_->returnColInd_kokkos_view(host_cols_view_);
81 data_.solver.setSolutionMethod(data_.method);
82 data_.solver.setLevelSetOptionAlgorithmVariant(data_.variant);
83 data_.solver.setSmallProblemThresholdsize(data_.small_problem_threshold_size);
84 data_.solver.setVerbose(data_.verbose);
85 data_.solver.setLevelSetOptionNumStreams(data_.streams, data_.team_on_user_stream);
90 if (data_.dofs_per_node > 1) {
91 data_.solver.analyze(this->globalNumCols_, data_.dofs_per_node, host_row_ptr_view_, host_cols_view_);
93 data_.solver.analyze(this->globalNumCols_, host_row_ptr_view_, host_cols_view_);
95 data_.solver.initialize();
101template <
class Matrix,
class Vector>
105#ifdef HAVE_AMESOS2_TIMERS
106 Teuchos::TimeMonitor numFactTimer(this->timers_.numFactTime_);
111 if(do_optimization()) {
115 device_value_type_array device_nzvals_temp;
116 this->matrixA_->returnValues_kokkos_view(device_nzvals_temp);
117 Kokkos::deep_copy(device_nzvals_view_, device_nzvals_temp);
119 if (data_.diag_shift) {
120 data_.solver.shiftDiagonal();
122 if (data_.pivot_pert) {
123 data_.solver.useDefaultPivotTolerance();
125 data_.solver.useNoPivotTolerance();
127 data_.solver.factorize(device_nzvals_view_);
132template <
class Matrix,
class Vector>
139 const global_size_type ld_rhs = this->root_ ? X->getGlobalLength() : 0;
140 const size_t nrhs = X->getGlobalNumVectors();
149#ifdef HAVE_AMESOS2_TIMERS
150 Teuchos::TimeMonitor mvConvTimer(this->timers_.vecConvTime_);
152 const bool initialize_data =
true;
153 const bool do_not_initialize_data =
false;
154 Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
155 device_solve_array_t>::do_get(initialize_data, B, this->bValues_,
157 ROOTED, this->rowIndexBase_);
158 bDidAssignX = Util::get_1d_copy_helper_kokkos_view<MultiVecAdapter<Vector>,
159 device_solve_array_t>::do_get(do_not_initialize_data, X, this->xValues_,
161 ROOTED, this->rowIndexBase_);
168#ifdef HAVE_AMESOS2_TIMERS
169 Teuchos::TimeMonitor solveTimer(this->timers_.solveTime_);
171 if (workspace_.extent(0) < this->globalNumRows_ || workspace_.extent(1) < nrhs) {
172 workspace_ = device_solve_array_t(
173 Kokkos::ViewAllocateWithoutInitializing(
"t"), this->globalNumRows_, nrhs);
176 data_.solver.solve(xValues_, bValues_, workspace_);
185 Teuchos::broadcast(*(this->getComm()), 0, &ierr);
187 TEUCHOS_TEST_FOR_EXCEPTION( ierr != 0, std::runtime_error,
188 "tacho_solve has error code: " << ierr );
195#ifdef HAVE_AMESOS2_TIMERS
196 Teuchos::TimeMonitor redistTimer(this->timers_.vecRedistTime_);
201 Util::template put_1d_data_helper_kokkos_view<
204 ROOTED, this->rowIndexBase_);
211template <
class Matrix,
class Vector>
216 return( this->matrixA_->getGlobalNumRows() == this->matrixA_->getGlobalNumCols() );
220template <
class Matrix,
class Vector>
224 RCP<const Teuchos::ParameterList> valid_params = getValidParameters_impl();
229 auto method_name = parameterList->get<std::string> (
"method",
"chol");
230 if (method_name ==
"ldl-nopiv")
232 else if (method_name ==
"chol")
234 else if (method_name ==
"ldl")
236 else if (method_name ==
"lu")
239 std::cout <<
"Error: not supported solution method\n";
242 data_.variant = parameterList->get<
int> (
"variant", 2);
244 data_.small_problem_threshold_size = parameterList->get<
int> (
"small problem threshold size", 1024);
246 data_.verbose = parameterList->get<
bool> (
"verbose",
false);
248 data_.streams = parameterList->get<
int> (
"num-streams", 1);
250 data_.team_on_user_stream = parameterList->get<
bool> (
"team-on-user-stream",
false);
252 data_.dofs_per_node = parameterList->get<
int> (
"dofs-per-node", 1);
254 data_.pivot_pert = parameterList->get<
bool> (
"perturb-pivot",
false);
255 data_.diag_shift = parameterList->get<
bool> (
"shift-diag",
false);
262template <
class Matrix,
class Vector>
263Teuchos::RCP<const Teuchos::ParameterList>
266 static Teuchos::RCP<const Teuchos::ParameterList> valid_params;
268 if( is_null(valid_params) ){
269 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
271 pl->set(
"method",
"chol",
"Type of factorization, chol, ldl, or lu");
272 pl->set(
"variant", 2,
"Type of solver variant, 0, 1, or 2");
273 pl->set(
"small problem threshold size", 1024,
"Problem size threshold below with Tacho uses LAPACK.");
274 pl->set(
"verbose",
false,
"Verbosity");
275 pl->set(
"num-streams", 1,
"Number of GPU streams");
276 pl->set(
"dofs-per-node", 1,
"DoFs per node");
277 pl->set(
"perturb-pivot",
false,
"Perturb tiny pivots");
278 pl->set(
"shift-diag",
false,
"Shift diagonal entries");
279 pl->set(
"team-on-user-stream",
false,
"Use user stream-0 for team/batched kernels");
291template <
class Matrix,
class Vector>
294 return (this->root_ && (this->matrixA_->getComm()->getSize() == 1));
297template <
class Matrix,
class Vector>
302 if(current_phase == SOLVE) {
306 if(!do_optimization()) {
307#ifdef HAVE_AMESOS2_TIMERS
308 Teuchos::TimeMonitor convTimer(this->timers_.mtxConvTime_);
319 if (device_nzvals_view_.extent(0) != this->globalNumNonZeros_)
320 Kokkos::resize(device_nzvals_view_, this->globalNumNonZeros_);
321 if (host_cols_view_.extent(0) != this->globalNumNonZeros_)
322 Kokkos::resize(host_cols_view_, this->globalNumNonZeros_);
323 if (host_row_ptr_view_.extent(0) != this->globalNumRows_ + 1)
324 Kokkos::resize(host_row_ptr_view_, this->globalNumRows_ + 1);
326 Kokkos::resize(device_nzvals_view_, 0);
327 Kokkos::resize(host_cols_view_, 0);
328 Kokkos::resize(host_row_ptr_view_, 1);
332 typename host_size_type_array::value_type nnz_ret = 0;
334 #ifdef HAVE_AMESOS2_TIMERS
335 Teuchos::TimeMonitor mtxRedistTimer( this->timers_.mtxRedistTime_ );
338 TEUCHOS_TEST_FOR_EXCEPTION( this->rowIndexBase_ != this->columnIndexBase_,
340 "Row and column maps have different indexbase ");
343 device_value_type_array, host_ordinal_type_array, host_size_type_array>::do_get(
344 this->matrixA_.ptr(),
350 this->columnIndexBase_);
357 device_nzvals_view_ = device_value_type_array(
358 Kokkos::ViewAllocateWithoutInitializing(
"nzvals"), this->globalNumNonZeros_);
366template <
class Matrix,
class Vector>
369 const Teuchos::EVerbosityLevel verbLevel)
const
371 out <<
" Tacho current parameters:" << std::endl;
372 out <<
" > method = " << data_.method;
373 if (data_.method == 0) out <<
" (ldl-nopiv)" << std::endl;
374 if (data_.method == 1) out <<
" (chol)" << std::endl;
375 if (data_.method == 2) out <<
" (ldl)" << std::endl;
376 if (data_.method == 3) out <<
" (lu)" << std::endl;
377 out <<
" > variant = " << data_.variant << std::endl;
378 out <<
" > verbose = " << data_.verbose << std::endl;
379 out <<
" > num-streams = " << data_.streams << std::endl;
380 out <<
" > dofs-per-node = " << data_.dofs_per_node << std::endl;
381 out <<
" > perturb-pivo = " << (data_.pivot_pert ?
"YES" :
"NO") << std::endl;
382 out <<
" > shift-diag = " << (data_.diag_shift ?
"YES" :
"NO") << std::endl;
383 out <<
" > team-on-user-stream = " << (data_.team_on_user_stream ?
"YES" :
"NO") << std::endl;
384 out <<
" > small problem threshold size = " << data_.small_problem_threshold_size << std::endl;
389template<
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:213
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition Amesos2_Tacho_def.hpp:264
int numericFactorization_impl()
Tacho specific numeric factorization.
Definition Amesos2_Tacho_def.hpp:103
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:134
~TachoSolver()
Destructor.
Definition Amesos2_Tacho_def.hpp:43
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition Amesos2_Tacho_def.hpp:293
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:52
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition Amesos2_Tacho_def.hpp:299
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Tacho.
Definition Amesos2_Tacho_def.hpp:68
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:368
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition Amesos2_Tacho_def.hpp:61
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