1 #ifndef VIENNACL_LINALG_DETAIL_ILUT_HPP_
2 #define VIENNACL_LINALG_DETAIL_ILUT_HPP_
55 double drop_tolerance = 1e-4,
56 bool with_level_scheduling =
false)
57 : entries_per_row_(entries_per_row),
58 drop_tolerance_(drop_tolerance),
59 use_level_scheduling_(with_level_scheduling) {}
64 drop_tolerance_ = tol;
80 unsigned int entries_per_row_;
81 double drop_tolerance_;
82 bool use_level_scheduling_;
87 template<
typename NumericT,
typename SizeT,
typename SparseVectorT>
96 NumericT
const * elements = viennacl::linalg::host_based::detail::extract_raw_pointer<NumericT>(A.
handle());
97 unsigned int const * row_buffer = viennacl::linalg::host_based::detail::extract_raw_pointer<unsigned int>(A.
handle1());
98 unsigned int const * col_buffer = viennacl::linalg::host_based::detail::extract_raw_pointer<unsigned int>(A.
handle2());
100 SizeT row_i_begin =
static_cast<SizeT
>(row_buffer[
row]);
101 SizeT row_i_end =
static_cast<SizeT
>(row_buffer[row+1]);
102 NumericT row_norm = 0;
103 for (SizeT buf_index_i = row_i_begin; buf_index_i < row_i_end; ++buf_index_i)
105 NumericT entry = elements[buf_index_i];
106 w[col_buffer[buf_index_i]] = entry;
107 row_norm += entry * entry;
109 return std::sqrt(row_norm);
113 template<
typename NumericT,
typename SizeT,
typename SparseVectorT>
114 NumericT
setup_w(std::vector< std::map<SizeT, NumericT> >
const & A,
118 NumericT row_norm = 0;
120 for (
typename std::map<SizeT, NumericT>::const_iterator iter_w = w.begin(); iter_w != w.end(); ++iter_w)
121 row_norm += iter_w->second * iter_w->second;
123 return std::sqrt(row_norm);
135 template<
typename SparseMatrixTypeT,
typename NumericT,
typename SizeT>
137 std::vector< std::map<SizeT, NumericT> > & output,
140 typedef std::map<SizeT, NumericT> SparseVector;
141 typedef typename SparseVector::iterator SparseVectorIterator;
142 typedef typename std::map<SizeT, NumericT>::const_iterator OutputRowConstIterator;
143 typedef std::multimap<NumericT, std::pair<SizeT, NumericT> > TemporarySortMap;
148 TemporarySortMap temp_map;
156 NumericT row_norm =
setup_w(A, i, w);
160 for (SparseVectorIterator w_k = w.begin(); w_k != w.end(); ++w_k)
162 SizeT k = w_k->first;
167 NumericT a_kk = output[k][k];
168 if (a_kk <= 0 && a_kk >= 0)
170 std::cerr <<
"ViennaCL: FATAL ERROR in ILUT(): Diagonal entry is zero in row " << k
171 <<
" while processing line " << i <<
"!" << std::endl;
172 throw "ILUT zero diagonal!";
175 NumericT w_k_entry = w_k->second / a_kk;
176 w_k->second = w_k_entry;
179 if ( std::fabs(w_k_entry) > tau_i)
182 for (OutputRowConstIterator u_k = output[k].begin(); u_k != output[k].end(); ++u_k)
185 w[u_k->first] -= w_k_entry * u_k->second;
196 for (SparseVectorIterator w_k = w.begin(); w_k != w.end(); ++w_k)
198 SizeT k = w_k->first;
199 NumericT w_k_entry = w_k->second;
201 NumericT abs_w_k = std::fabs(w_k_entry);
202 if ( (abs_w_k > tau_i) || (k == i) )
206 throw "Triangular factor in ILUT singular!";
208 temp_map.insert(std::make_pair(abs_w_k, std::make_pair(k, w_k_entry)));
215 for (
typename TemporarySortMap::reverse_iterator iter = temp_map.rbegin(); iter != temp_map.rend(); ++iter)
217 std::map<SizeT, NumericT> & row_i = output[i];
218 SizeT j = (iter->second).first;
219 NumericT w_j_entry = (iter->second).second;
225 row_i[j] = w_j_entry;
231 row_i[j] = w_j_entry;
237 row_i[j] = w_j_entry;
251 template<
typename MatrixT>
254 typedef typename MatrixT::value_type NumericType;
265 template<
typename VectorT>
269 unsigned int const * row_buffer = viennacl::linalg::host_based::detail::extract_raw_pointer<unsigned int>(LU_.
handle1());
270 unsigned int const * col_buffer = viennacl::linalg::host_based::detail::extract_raw_pointer<unsigned int>(LU_.
handle2());
271 NumericType
const * elements = viennacl::linalg::host_based::detail::extract_raw_pointer<NumericType>(LU_.
handle());
273 viennacl::linalg::host_based::detail::csr_inplace_solve<NumericType>(row_buffer, col_buffer, elements, vec, LU_.
size2(),
unit_lower_tag());
274 viennacl::linalg::host_based::detail::csr_inplace_solve<NumericType>(row_buffer, col_buffer, elements, vec, LU_.
size2(),
upper_tag());
278 void init(MatrixT
const & mat)
286 std::vector< std::map<unsigned int, NumericType> > LU_temp(mat.size1());
294 ilut_tag
const & tag_;
303 template<
typename NumericT,
unsigned int AlignmentV>
327 multifrontal_L_row_index_arrays_,
328 multifrontal_L_row_buffers_,
329 multifrontal_L_col_buffers_,
330 multifrontal_L_element_buffers_,
331 multifrontal_L_row_elimination_num_list_);
336 multifrontal_U_row_index_arrays_,
337 multifrontal_U_row_buffers_,
338 multifrontal_U_col_buffers_,
339 multifrontal_U_element_buffers_,
340 multifrontal_U_row_elimination_num_list_);
360 void init(MatrixType
const & mat)
365 std::vector< std::map<unsigned int, NumericT> > LU_temp(mat.size1());
391 multifrontal_U_diagonal_.resize(LU_.
size1(),
false);
395 multifrontal_U_diagonal_,
396 multifrontal_L_row_index_arrays_,
397 multifrontal_L_row_buffers_,
398 multifrontal_L_col_buffers_,
399 multifrontal_L_element_buffers_,
400 multifrontal_L_row_elimination_num_list_);
404 multifrontal_U_diagonal_,
405 multifrontal_U_row_index_arrays_,
406 multifrontal_U_row_buffers_,
407 multifrontal_U_col_buffers_,
408 multifrontal_U_element_buffers_,
409 multifrontal_U_row_elimination_num_list_);
417 for (
typename std::list< viennacl::backend::mem_handle >::iterator it = multifrontal_L_row_index_arrays_.begin();
418 it != multifrontal_L_row_index_arrays_.end();
422 for (
typename std::list< viennacl::backend::mem_handle >::iterator it = multifrontal_L_row_buffers_.begin();
423 it != multifrontal_L_row_buffers_.end();
427 for (
typename std::list< viennacl::backend::mem_handle >::iterator it = multifrontal_L_col_buffers_.begin();
428 it != multifrontal_L_col_buffers_.end();
432 for (
typename std::list< viennacl::backend::mem_handle >::iterator it = multifrontal_L_element_buffers_.begin();
433 it != multifrontal_L_element_buffers_.end();
442 for (
typename std::list< viennacl::backend::mem_handle >::iterator it = multifrontal_U_row_index_arrays_.begin();
443 it != multifrontal_U_row_index_arrays_.end();
447 for (
typename std::list< viennacl::backend::mem_handle >::iterator it = multifrontal_U_row_buffers_.begin();
448 it != multifrontal_U_row_buffers_.end();
452 for (
typename std::list< viennacl::backend::mem_handle >::iterator it = multifrontal_U_col_buffers_.begin();
453 it != multifrontal_U_col_buffers_.end();
457 for (
typename std::list< viennacl::backend::mem_handle >::iterator it = multifrontal_U_element_buffers_.begin();
458 it != multifrontal_U_element_buffers_.end();
465 ilut_tag
const & tag_;
468 std::list<viennacl::backend::mem_handle> multifrontal_L_row_index_arrays_;
469 std::list<viennacl::backend::mem_handle> multifrontal_L_row_buffers_;
470 std::list<viennacl::backend::mem_handle> multifrontal_L_col_buffers_;
471 std::list<viennacl::backend::mem_handle> multifrontal_L_element_buffers_;
472 std::list<vcl_size_t > multifrontal_L_row_elimination_num_list_;
475 std::list<viennacl::backend::mem_handle> multifrontal_U_row_index_arrays_;
476 std::list<viennacl::backend::mem_handle> multifrontal_U_row_buffers_;
477 std::list<viennacl::backend::mem_handle> multifrontal_U_col_buffers_;
478 std::list<viennacl::backend::mem_handle> multifrontal_U_element_buffers_;
479 std::list<vcl_size_t > multifrontal_U_row_elimination_num_list_;
const vcl_size_t & size2() const
Returns the number of columns.
viennacl::vector_expression< const vector_base< T >, const vector_base< T >, op_element_binary< op_div > > element_div(vector_base< T > const &v1, vector_base< T > const &v2)
void inplace_solve(const matrix_base< NumericT > &A, matrix_base< NumericT > &B, SolverTagT)
Direct inplace solver for triangular systems with multiple right hand sides, i.e. A \ B (MATLAB notat...
ilut_precond(MatrixT const &mat, ilut_tag const &tag)
NumericT setup_w(viennacl::compressed_matrix< NumericT > const &A, SizeT row, SparseVectorT &w)
Dispatcher overload for extracting the row of nonzeros of a compressed matrix.
const vcl_size_t & size1() const
Returns the number of rows.
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
void set_entries_per_row(unsigned int e)
void precondition(viennacl::compressed_matrix< NumericT > &A, ilu0_tag const &)
Implementation of a ILU-preconditioner with static pattern. Optimized version for CSR matrices...
This file provides the forward declarations for the main types used within ViennaCL.
bool use_level_scheduling() const
void level_scheduling_setup_U(viennacl::compressed_matrix< NumericT, AlignmentV > const &LU, viennacl::vector< NumericT > const &diagonal_LU, std::list< viennacl::backend::mem_handle > &row_index_arrays, std::list< viennacl::backend::mem_handle > &row_buffers, std::list< viennacl::backend::mem_handle > &col_buffers, std::list< viennacl::backend::mem_handle > &element_buffers, std::list< vcl_size_t > &row_elimination_num_list)
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
void level_scheduling_substitute(viennacl::vector< NumericT > &vec, std::list< viennacl::backend::mem_handle > const &row_index_arrays, std::list< viennacl::backend::mem_handle > const &row_buffers, std::list< viennacl::backend::mem_handle > const &col_buffers, std::list< viennacl::backend::mem_handle > const &element_buffers, std::list< vcl_size_t > const &row_elimination_num_list)
const handle_type & handle() const
Returns the OpenCL handle to the matrix entry array.
const handle_type & handle1() const
Returns the OpenCL handle to the row index array.
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
void apply(VectorT &vec) const
A tag class representing an upper triangular matrix.
A tag for incomplete LU factorization with threshold (ILUT)
Implementation of the compressed_matrix class.
ilut_precond(MatrixType const &mat, ilut_tag const &tag)
unsigned int get_entries_per_row() const
const handle_type & handle2() const
Returns the OpenCL handle to the column index array.
ILUT preconditioner class, can be supplied to solve()-routines.
Common routines for single-threaded or OpenMP-enabled execution on CPU.
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
viennacl::memory_types memory_type() const
void apply(viennacl::vector< NumericT > &vec) const
void set_drop_tolerance(double tol)
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
void use_level_scheduling(bool b)
A tag class representing a lower triangular matrix with unit diagonal.
void row_info(compressed_matrix< NumericT, AlignmentV > const &mat, vector_base< NumericT > &vec, viennacl::linalg::detail::row_info_types info_selector)
void level_scheduling_setup_L(viennacl::compressed_matrix< NumericT, AlignmentV > const &LU, viennacl::vector< NumericT > const &diagonal_LU, std::list< viennacl::backend::mem_handle > &row_index_arrays, std::list< viennacl::backend::mem_handle > &row_buffers, std::list< viennacl::backend::mem_handle > &col_buffers, std::list< viennacl::backend::mem_handle > &element_buffers, std::list< vcl_size_t > &row_elimination_num_list)
Common routines used within ILU-type preconditioners.
const handle_type & handle() const
Returns the memory handle.
ilut_tag(unsigned int entries_per_row=20, double drop_tolerance=1e-4, bool with_level_scheduling=false)
The constructor.
memory_types get_active_handle_id() const
Returns an ID for the currently active memory buffer. Other memory buffers might contain old or no da...
double get_drop_tolerance() const
void switch_memory_context(T &obj, viennacl::context new_ctx)
Generic convenience routine for migrating data of an object to a new memory domain.