ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
parallel_linear_solver.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_SOLVERS_VIENNACL_PARALLEL_LINEAR_SOLVER_HPP
2#define VIENNASHE_SOLVERS_VIENNACL_PARALLEL_LINEAR_SOLVER_HPP
3
4/* ============================================================================
5 Copyright (c) 2011-2022, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8
9 -----------------
10 ViennaSHE - The Vienna Spherical Harmonics Expansion Boltzmann Solver
11 -----------------
12
13 http://viennashe.sourceforge.net/
14
15 License: MIT (X11), see file LICENSE in the base directory
16=============================================================================== */
17
18
19// viennashe
20#include "viennashe/forwards.h"
25
26#include "viennashe/log/log.hpp"
29
30// viennacl
31#include "viennacl/linalg/bicgstab.hpp"
32#include "viennacl/linalg/ilu.hpp"
33#include "viennacl/io/matrix_market.hpp"
34
39namespace viennashe
40{
41 namespace solvers
42 {
43
50 template <typename CompressedMatrixType,
51 typename VectorType>
52 VectorType solve(CompressedMatrixType const & system_matrix,
53 VectorType const & rhs,
56 )
57 {
58 typedef typename VectorType::value_type NumericT;
59
60 //
61 // Step 1: Convert data to ViennaCL types:
62 //
63
64 viennacl::compressed_matrix<NumericT> A(system_matrix.size1(), system_matrix.size2());
65 viennacl::vector<NumericT> b(system_matrix.size1());
66
67 viennacl::fast_copy(&(rhs[0]), &(rhs[0]) + rhs.size(), b.begin());
68 detail::copy(system_matrix, A);
69
70 //
71 // parallel block-preconditioner
72 //
73
74 log::info<log_linear_solver>() << "* solve(): Computing block preconditioner (multi-threaded)... " << std::endl;
75 //viennacl::linalg::ilut_tag precond_tag(config.ilut_entries(),
76 // config.ilut_drop_tolerance());
77 viennacl::linalg::ilu0_tag precond_tag;
78
79 typedef typename viennacl::linalg::block_ilu_precond<viennacl::compressed_matrix<NumericT>,
80 viennacl::linalg::ilu0_tag>::index_vector_type IndexVectorType;
81
82 IndexVectorType block_indices(config.block_preconditioner_boundaries());
83
84 // make sure that there are block boundaries available:
85 if (block_indices.size() == 0)
86 {
87 block_indices.resize(1);
88 block_indices[0].first = 0;
89 block_indices[0].second = A.size1();
90 }
91
92 viennacl::linalg::block_ilu_precond<viennacl::compressed_matrix<NumericT>,
93 viennacl::linalg::ilu0_tag> block_preconditioner(A, precond_tag, 1);//block_indices);
94 //log::debug<log_linear_solver>() << "Time: " << timer.get() << std::endl;
95
96 //
97 // Solve system:
98 //
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());
101
102 viennacl::vector<NumericT> vcl_result = viennacl::linalg::solve(A,
103 b,
104 solver_tag,
105 block_preconditioner);
106
107 //log::debug<log_linear_solver>() << "Time: " << timer.get() << std::endl;
108 //log::debug<log_linear_solver>() << "Number of iterations (block ILUT): " << solver_tag.iters() << std::endl;
109
110 //
111 // Step 3: Convert data back:
112 //
113 VectorType result(vcl_result.size());
114 viennacl::fast_copy(vcl_result.begin(), vcl_result.end(), &(result[0]));
115
117
118 //
119 // As a check, compute residual:
120 //
121 log::info<log_linear_solver>() << "* solve(): residual: "
123 << " after " << solver_tag.iters() << " iterations." << std::endl;
124 //log::debug<log_linear_solver>() << "SHE result (compressed): " << compressed_result << std::endl;
125
126 return result;
127 }
128
129 } // solvers
130
131} // viennashe
132
133
134#endif
135
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.
Definition: config.hpp:124
A configuration class holding options for use within the different linear solvers.
Definition: config.hpp:57
Internal tag used for the specification of a CPU-based multi-threaded linear solver.
Definition: forwards.h:209
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)
Definition: linalg_util.hpp:37
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).
Definition: checks.hpp:111
The main ViennaSHE namespace. All functionality resides inside this namespace.
Definition: accessors.hpp:40
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.