Skip to content

Commit

Permalink
fix the additional residual computation when passing residual criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Mar 22, 2023
1 parent f428910 commit 81c2633
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/solver/gmres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void Gmres<ValueType>::apply_dense_impl(const VectorType* dense_b,
.residual(residual)
.residual_norm(residual_norm)
.solution(dense_x)
.check(RelativeStoppingId, false, &stop_status, &one_changed)) {
.check(RelativeStoppingId, true, &stop_status, &one_changed)) {
break;
}

Expand Down
9 changes: 7 additions & 2 deletions core/stop/residual_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ bool ResidualNormBase<ValueType>::check_impl(
[&](auto dense_r) { dense_r->compute_norm2(u_dense_tau_); },
updater.residual_);
dense_tau = u_dense_tau_.get();
} else if (updater.solution_ != nullptr && system_matrix_ != nullptr &&
b_ != nullptr) {
} else if (set_finalized && updater.solution_ != nullptr &&
system_matrix_ != nullptr && b_ != nullptr) {
// Only compute the residual from solution in the finalized step
auto exec = this->get_executor();
norm_dispatch<ValueType>(
[&](auto dense_b, auto dense_x) {
Expand All @@ -209,6 +210,10 @@ 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

0 comments on commit 81c2633

Please sign in to comment.