1#ifndef VIENNASHE_SOLVERS_VIENNACL_PARALLEL_LINEAR_SOLVER_HPP
2#define VIENNASHE_SOLVERS_VIENNACL_PARALLEL_LINEAR_SOLVER_HPP
31#include "viennacl/linalg/bicgstab.hpp"
32#include "viennacl/linalg/ilu.hpp"
33#include "viennacl/io/matrix_market.hpp"
50 template <
typename CompressedMatrixType,
52 VectorType
solve(CompressedMatrixType
const & system_matrix,
53 VectorType
const & rhs,
58 typedef typename VectorType::value_type NumericT;
64 viennacl::compressed_matrix<NumericT> A(system_matrix.size1(), system_matrix.size2());
65 viennacl::vector<NumericT> b(system_matrix.size1());
67 viennacl::fast_copy(&(rhs[0]), &(rhs[0]) + rhs.size(), b.begin());
74 log::info<log_linear_solver>() <<
"* solve(): Computing block preconditioner (multi-threaded)... " << std::endl;
77 viennacl::linalg::ilu0_tag precond_tag;
79 typedef typename viennacl::linalg::block_ilu_precond<viennacl::compressed_matrix<NumericT>,
80 viennacl::linalg::ilu0_tag>::index_vector_type IndexVectorType;
82 IndexVectorType block_indices(
config.block_preconditioner_boundaries());
85 if (block_indices.size() == 0)
87 block_indices.resize(1);
88 block_indices[0].first = 0;
89 block_indices[0].second = A.size1();
92 viennacl::linalg::block_ilu_precond<viennacl::compressed_matrix<NumericT>,
93 viennacl::linalg::ilu0_tag> block_preconditioner(A, precond_tag, 1);
99 log::info<log_linear_solver>() <<
"* solve(): Solving system (multi-threaded)... " << std::endl;
100 viennacl::linalg::bicgstab_tag solver_tag(
config.tolerance(),
config.max_iters());
105 block_preconditioner);
113 VectorType result(vcl_result.size());
114 viennacl::fast_copy(vcl_result.begin(), vcl_result.end(), &(result[0]));
121 log::info<log_linear_solver>() <<
"* solve(): residual: "
123 <<
" after " << solver_tag.iters() <<
" iterations." << std::endl;
Defines a set of checker functors for micro-tests within ViennaSHE.
The main SHE configuration class. To be adjusted by the user for his/her needs.
A configuration class holding options for use within the different linear solvers.
Internal tag used for the specification of a CPU-based multi-threaded linear solver.
Contains forward declarations and definition of small classes that must be defined at an early stage.
Implementation of various utilities related to linear algebra.
A logging facility providing fine-grained control over logging in ViennaSHE.
VectorType::value_type norm_2(VectorType const &v)
VectorType prod(sparse_matrix< NumericT > const &system_matrix, VectorType const &x)
Computes A * x for a sparse A and a vector x.
void copy(MatrixT const &assembled_matrix, viennacl::compressed_matrix< NumericT > &vcl_matrix)
std::vector< double > solve(viennashe::math::sparse_matrix< double > &A, std::vector< double > const &b, linear_solver_config const &config)
Public interface for solving a system of linear equations represented using a sparse matrix.
VectorType solve(CompressedMatrixType const &system_matrix, VectorType const &rhs, viennashe::solvers::linear_solver_config const &config, viennashe::solvers::parallel_linear_solver_tag)
Solves the provided system using an iterative solver with a block preconditioner on CPU.
void check_vector_for_valid_entries(VectorType const &vec, std::string message="Location not specified")
Checks a vector for valid entries (i.e. no NaN).
The main ViennaSHE namespace. All functionality resides inside this namespace.
Provides bindings to a serial ILUT-based solver shipped with ViennaCL.
The SHE configuration class is defined here.
Defines all the log keys used within the viennashe::solvers namespace.