Skip to content

Commit

Permalink
additional variable ignore_residual_check
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Mar 23, 2023
1 parent 603e8bb commit 81fab18
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions core/solver/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ void Ir<ValueType>::apply_dense_impl(const VectorType* dense_b,
if (stop_criterion->update()
.num_iterations(iter)
.solution(dense_x)
// we have the residual check later
.ignore_residual_check(true)
.check(relative_stopping_id, false, &stop_status,
&one_changed)) {
break;
Expand Down
13 changes: 6 additions & 7 deletions core/stop/residual_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,17 @@ bool ResidualNormBase<ValueType>::check_impl(
const NormVector* dense_tau;
if (updater.residual_norm_ != nullptr) {
dense_tau = as<NormVector>(updater.residual_norm_);
} else if (updater.ignore_residual_check_) {
// If solver already provide the residual norm, we will still store it.
// Otherwise, we skip the residual check.
return false;
} else if (updater.residual_ != nullptr) {
norm_dispatch<ValueType>(
[&](auto dense_r) { dense_r->compute_norm2(u_dense_tau_); },
updater.residual_);
dense_tau = u_dense_tau_.get();
} else if (set_finalized && updater.solution_ != nullptr &&
system_matrix_ != nullptr && b_ != nullptr) {
// Only compute the residual from solution in the finalized step
} else if (updater.solution_ != nullptr && system_matrix_ != nullptr &&
b_ != nullptr) {
auto exec = this->get_executor();
norm_dispatch<ValueType>(
[&](auto dense_b, auto dense_x) {
Expand All @@ -210,10 +213,6 @@ bool ResidualNormBase<ValueType>::check_impl(
},
b_.get(), updater.solution_);
dense_tau = u_dense_tau_.get();
} else if (!set_finalized) {
// If it is not the finalized step and does not contain residual, we
// skip the residual norm check
return false;
} else {
GKO_NOT_SUPPORTED(nullptr);
}
Expand Down
5 changes: 4 additions & 1 deletion include/ginkgo/core/stop/criterion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class Criterion : public EnableAbstractPolymorphicObject<Criterion> {
* Criterion's check function. The pattern used is a Builder, except Updater
* builds a function's arguments before calling the function itself, and
* does not build an object. This allows calling a Criterion's check in the
* form of: stop_criterion->update() .num_iterations(num_iterations)
* form of: stop_criterion->update()
* .num_iterations(num_iterations)
* .ignore_residual_check(ignore_residual_check)
* .residual_norm(residual_norm)
* .implicit_sq_residual_norm(implicit_sq_residual_norm)
* .residual(residual)
Expand Down Expand Up @@ -123,6 +125,7 @@ class Criterion : public EnableAbstractPolymorphicObject<Criterion> {
mutable _type* _name##_ {}

GKO_UPDATER_REGISTER_PARAMETER(size_type, num_iterations);
GKO_UPDATER_REGISTER_PARAMETER(bool, ignore_residual_check);
GKO_UPDATER_REGISTER_PTR_PARAMETER(const LinOp, residual);
GKO_UPDATER_REGISTER_PTR_PARAMETER(const LinOp, residual_norm);
GKO_UPDATER_REGISTER_PTR_PARAMETER(const LinOp,
Expand Down

0 comments on commit 81fab18

Please sign in to comment.