41template <base::concepts::sparse_matrix Matrix>
42class parallel_symmetric_successive_over_relaxation;
47 "num_collect::linear::parallel_symmetric_successive_over_relaxation");
56template <base::concepts::sparse_matrix Matrix>
71template <base::concepts::sparse_matrix Matrix>
74 parallel_symmetric_successive_over_relaxation<Matrix>>,
76 static_assert(Matrix::IsRowMajor == 1,
"Row major matrix is required.");
78 "Complex matrices are not supported.");
115 "All diagonal elements of the coefficient matrix must not be "
118 (
coeff.nonZeros() / omp_get_max_threads() > 1000);
129 template <base::concepts::dense_vector_of<scalar_type> Right,
130 base::concepts::dense_vector_of<scalar_type> Solution>
132 const auto& coeff_ref =
coeff();
135 "Coefficient matrix must be a square matrix.");
137 "Right-hand-side vector must have the number of elements same as "
138 "the size of the coefficient matrix.");
140 "Solution vector must have the number of elements same as the size "
141 "of the coefficient matrix.");
144 const scalar_type right_norm = right.squaredNorm();
155 "parallel_symmetric_successive_over_relaxation.");
198 "Relaxation coefficient must be in the range (0, 2).");
227 template <base::concepts::dense_vector_of<scalar_type> Right,
228 base::concepts::dense_vector_of<scalar_type> Solution>
230 Solution& solution)
const {
238 const index_type num_threads = omp_get_num_threads();
239 const index_type thread_id = omp_get_thread_num();
241 (size + num_threads - 1) / num_threads;
242 const index_type my_start_row = thread_id * rows_per_thread;
244 std::min(my_start_row + rows_per_thread, size);
248 "my rows: {} - {} (whole rows: {})", my_start_row,
255 for (
index_type i = my_start_row; i < my_last_row; ++i) {
257 i, my_start_row, prev_sol_coeff);
263 for (
index_type i = my_last_row - 1; i >= my_start_row; --i) {
265 coeff_ref, right, solution, i, my_last_row, prev_sol_coeff);
282 template <base::concepts::dense_vector_of<scalar_type> Right,
283 base::concepts::dense_vector_of<scalar_type> Solution>
285 Solution& solution)
const {
294 coeff_ref, right, solution, i, 0, prev_sol_coeff);
300 coeff_ref, right, solution, i, size, prev_sol_coeff);
317 template <base::concepts::dense_vector_of<scalar_type> Right,
318 base::concepts::dense_vector_of<scalar_type> Solution>
323 for (
typename matrix_type::InnerIterator iter(coeff_ref, i); iter;
325 if (start_row <= iter.index() && iter.index() < i) {
328 }
else if (iter.index() != i) {
329 numerator -= iter.value() * solution(iter.index());
335 prev_sol_coeff * solution(i);
336 return row_residual * row_residual;
351 template <base::concepts::dense_vector_of<scalar_type> Right,
352 base::concepts::dense_vector_of<scalar_type> Solution>
357 for (
typename matrix_type::InnerIterator iter(coeff_ref, i); iter;
359 if (i < iter.index() && iter.index() < end_row) {
360 numerator -= iter.value() * solution(iter.index());
361 }
else if (iter.index() != i) {
Class of exception on failure in algorithm.
Base class of iterative solvers.
StorageIndex storage_index_type
auto coeff() const noexcept -> const matrix_type &
auto tolerance() const noexcept -> real_scalar_type
RealScalar real_scalar_type
auto compute(const matrix_type &coeff) -> parallel_symmetric_successive_over_relaxation< Matrix > &
auto max_iterations() const noexcept -> index_type
Class to solve linear equations using symmetric successive over-relaxation using threads golub2013.
auto iterations() const noexcept -> index_type
Get the number of iterations.
void solve_vector_in_place(const Right &right, Solution &solution) const
Iterate repeatedly until stop criterion is satisfied for a vector.
vector_type intermidiate_solution_
Intermidiate solution vector.
auto relaxation_coeff(const scalar_type &val) -> parallel_symmetric_successive_over_relaxation &
Set the relaxation coefficient.
void iterate_no_parallel(const matrix_type &coeff_ref, const Right &right, Solution &solution) const
Iterate once in single thread.
parallel_symmetric_successive_over_relaxation()
Constructor.
auto run_parallel(bool val) -> parallel_symmetric_successive_over_relaxation &
Set whether to run in parallel.
scalar_type residual_
Last residual.
scalar_type relaxation_coeff_
Relaxation coefficient.
Eigen::VectorX< scalar_type > vector_type
Type of vectors.
scalar_type residual_rate_
Rate of last residual.
bool run_parallel_
Whether to run in parallel.
auto process_row_forward(const matrix_type &coeff_ref, const Right &right, Solution &solution, index_type i, index_type start_row, const scalar_type &prev_sol_coeff) const -> scalar_type
Process a row in the forward update.
vector_type diag_
Diagonal coefficients.
index_type iterations_
Number of iterations.
vector_type inv_diag_
Inverse of diagonal coefficients.
void iterate_parallel(const matrix_type &coeff_ref, const Right &right, Solution &solution) const
Iterate once in parallel.
void process_row_backward(const matrix_type &coeff_ref, const Right &right, Solution &solution, index_type i, index_type end_row, const scalar_type &prev_sol_coeff) const
Process a row in the backward update.
auto residual_rate() const noexcept -> scalar_type
Get the rate of the last residual.
void compute(const matrix_type &coeff)
Prepare to solve.
Class of tags of logs without memory management.
Class to incorporate logging in algorithms.
logging_mixin(log_tag_view tag)
Constructor.
auto logger() const noexcept -> const num_collect::logging::logger &
Access to the logger.
Definition of dense_vector_of concept.
Definition of exceptions.
Definition of index_type type.
Definition of iterative_solver_base class.
Definition of log_tag_view class.
Definition of macros for logging.
#define NUM_COLLECT_LOG_TRACE(LOGGER,...)
Write a trace log.
#define NUM_COLLECT_LOG_AND_THROW(EXCEPTION_TYPE,...)
Write an error log and throw an exception for an error.
Definition of logging_mixin class.
std::ptrdiff_t index_type
Type of indices in this library.
Namespace of solvers of linear equations.
constexpr auto parallel_symmetric_successive_over_relaxation_tag
Log tag of parallel_symmetric_successive_over_relaxation.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of real_scalar concept.
Definition of sparse_matrix concept.
Matrix matrix_type
Type of the matrix.
Traits of iterative solvers.