Skip to content

Conversation

yhmtsai
Copy link
Member

@yhmtsai yhmtsai commented Jul 21, 2025

In most of our solver, we need to calculate the actual residual norm by b - Ax when required because these solvers only have the implicit residual norm, which is updated from the previous iteration such that it might not be correct enough for residual norm like CG.

This PR avoids reallocation the internal rhs in each iteration.
Note. we still have the allocation when generating the criterion, but it also requires storing the criterion in the solver and it is more critical when we setup some residual-norm aware smoother not the usual setup.

@yhmtsai yhmtsai requested a review from a team July 21, 2025 13:51
@yhmtsai yhmtsai self-assigned this Jul 21, 2025
@yhmtsai yhmtsai added the 1:ST:ready-for-review This PR is ready for review label Jul 21, 2025
@ginkgo-bot ginkgo-bot added reg:testing This is related to testing. mod:core This is related to the core module. mod:reference This is related to the reference module. type:stopping-criteria This is related to the stopping criteria labels Jul 21, 2025
Comment on lines +190 to +191
using dense_b_type = std::remove_cv_t<
std::remove_reference_t<decltype(*dense_b)>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the same as

Suggested change
using dense_b_type = std::remove_cv_t<
std::remove_reference_t<decltype(*dense_b)>>;
using dense_b_type = std::decay_t<decltype(*dense_b)>>;

initial_res.get());
auto abs_criterion = this->abs_factory_->generate(system_mtx, rhs, nullptr,
initial_res.get());
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either these blocks need a SCOPED_TRACE or the above is extracted into a new test fixture and the blocks are fully separated.

Copy link
Member

@upsj upsj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aim looks good, but I would like to aim towards reducing mutable usage in our classes. That would also make thread-safety #996 easier. If we can collect the thread-unsafe parts of Ginkgo in a small number of places, like the dense caches and workspaces, then we only need to make sure those work safely across multiple threads, and the rest follows automatically. Without mutable, we can also rely on const-ness implying thread-safety.

Comment on lines 88 to +90
mutable gko::array<char> reduction_tmp_;
// temporary rhs for residual computation
mutable std::shared_ptr<LinOp> rhs_{};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid adding more mutable functionality, and instead either find a way to include the stopping criteria in the workspace setup, or hide it behind an opaque pointer, so at least there is no mutability in the public interface. We could do this by adding a workspace parameter to the check function and having the old version create a temporary workspace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1:ST:ready-for-review This PR is ready for review mod:core This is related to the core module. mod:reference This is related to the reference module. reg:testing This is related to testing. type:stopping-criteria This is related to the stopping criteria
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants