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

Clean up implementation in SolverBicgstab #14257

Merged
merged 2 commits into from Sep 14, 2022

Conversation

kronbichler
Copy link
Member

This commit removes one redundant inner product from SolverBicgstab (t * t near the end of the algorithm) and otherwise restructures the code: I do not like the style of having local class variables holding pointers to the vectors (despite the work I did in #14251 where I did actually some variables to the class), because the VectorMemory class should take care of it. Furthermore, there were some scalars as class variables, which makes it much more cumbersome to read the code than if we define them at the place of use. All of these changes should also be seen against the background that the typical use case of BiCGStab is that we enter the iterate function only once; the outer iteration is, as far as I can see, only there to catch some rather artificial breakdown that is not seen on large systems. As a result, the code to hold things in the class variables seems like premature optimization to me.

I had to add some arguments to the iterate function in this process, but I think this makes the code clearer, so even that seems like a clear win.

Comment on lines -126 to +79
class SolverBicgstab : public SolverBase<VectorType>,
protected internal::SolverBicgstabData
class SolverBicgstab : public SolverBase<VectorType>
Copy link
Member Author

Choose a reason for hiding this comment

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

This is possibly an incompatible change, but since the base class was marked as internal, I don't think we need to create a way out for the user.

@kronbichler
Copy link
Member Author

If we would go into the operations on vectors, similarly to #13698, we could get out quite some additional performance, also without introspection into the preconditioner. (I will not do that here, because I have not critical use case of it for now, but I wanted to push some changes I had accumulated recently.)

@@ -408,13 +341,13 @@ SolverBicgstab<VectorType>::iterate(const MatrixType & A,

preconditioner.vmult(y, p);
A.vmult(v, y);
rhobar = rbar * v;
if (std::fabs(rhobar) < additional_data.breakdown)
const double rbar_dot_v = rbar * v;
Copy link
Member

Choose a reason for hiding this comment

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

double is fine? Shouldn't it be VectorType::value_type?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but then I think we should do it for all occurrences (omega, alpha, etc). This class won't currently work for complex numbers without proper restructuring (I am not even sure if BiCGStab does work theoretically), so I am not sure I will be able to correctly resolve the ambiguity between VectorType::value_type and the associated real_type. I will do my best.

IterationResult state(false, SolverControl::failure, 0, 0);
do
{
state = iterate(A, preconditioner);
state = iterate(A, x, b, preconditioner, state.last_step);
Copy link
Member

Choose a reason for hiding this comment

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

Personally, I would suggest to inline this function (in a follow-up PR).

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually tried to move everything into solve, but then I was discouraged by the various places where the iterate function might jump out and request a new attempt with a clean residual and no history, so I gave up. I am sure it can be further restructured, but I realized it would take more time than I wanted to spend (which is probably better spent once we do the bigger task of integrating similar tricks as in the SolverCG and need to restructure the code a bit more).

Copy link
Member

Choose a reason for hiding this comment

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

I see. Let's keep it like this for now.

@peterrum peterrum merged commit 436196a into dealii:master Sep 14, 2022
@kronbichler kronbichler deleted the cleanup_bicgstab branch August 10, 2023 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants