Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add early return to solvers that apply preconditioners before first residual check #1653

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/solver/cg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ void Cg<ValueType>::apply_dense_impl(const VectorType* dense_b,
this->get_system_matrix(),
std::shared_ptr<const LinOp>(dense_b, [](const LinOp*) {}), dense_x, r);

// If the initial guess is already a good enough solution, return
// immediately.
r->compute_conj_dot(r, rho, reduction_tmp);
bool all_stopped =
stop_criterion->update()
.num_iterations(0)
.residual(r)
.implicit_sq_residual_norm(rho)
.solution(dense_x)
.check(RelativeStoppingId, true, &stop_status, &one_changed);
this->template log<log::Logger::iteration_complete>(
this, dense_b, dense_x, 0, r, nullptr, rho, &stop_status, all_stopped);
if (all_stopped) {
return;
}

int iter = -1;
/* Memory movement summary:
* 18n * values + matrix/preconditioner storage
Expand Down
Loading