-
Notifications
You must be signed in to change notification settings - Fork 99
Modularize assembly internals and add SparseMatrixCSR extension #864
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
Conversation
49d273a
to
27d1980
Compare
27d1980
to
0c3efc8
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #864 +/- ##
==========================================
+ Coverage 94.03% 94.11% +0.07%
==========================================
Files 39 40 +1
Lines 6555 6643 +88
==========================================
+ Hits 6164 6252 +88
Misses 391 391 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
94ece96
to
8102774
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just took a look as I was curious, nice work on factoring out some parts - this will make it easier to extend!
@fredrikekre Do you have some time to review? |
Thanks @KnutAM for the pointer on the canonical keyword. PR should be good to go now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice to make this more flexible!
Do I understand this PR correctly that the main purpose is to introduce the necessary abstractions to allow extensions to different (CSR) matrix formats, and that the SparseMatrixCSR extension is just an example?
While testing to understand, I realized the following behavior,
julia> K = sparsecsr([2], [2], [2.])
2×2 SparseMatrixCSR{1, Float64, Int64} with 1 stored entry:
[2, 2] = 2.0
julia> K+K
2×2 Matrix{Float64}:
0.0 0.0
0.0 4.0
Which could lead to quite severe user issues if used in e.g. the transient heat tutorial here. So perhaps, instead of adding an extension that we have to maintain, could we add the implementation to the test suite instead?
And when JuliaSparse/SparseArrays.jl#546 is finalized, we could directly support most ops for abstract CSR inside Ferrite (but unless SparseMatricesCSR
adopts the interface, we probably don't want to keep supporting that)?
src/Dofs/ConstraintHandler.jl
Outdated
Compute "f -= K*inhomogeneities". | ||
By default this is a generic version via SpMSpV kernel. | ||
""" | ||
function add_inhomogeneities!(K, f::AbstractVector, inhomogeneities::AbstractVector, prescribed_dofs::AbstractVector{<:Integer}, dofmapping) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this only modifies f
.
function add_inhomogeneities!(K, f::AbstractVector, inhomogeneities::AbstractVector, prescribed_dofs::AbstractVector{<:Integer}, dofmapping) | |
function add_inhomogeneities!(f::AbstractVector, K::AbstractMatrix, inhomogeneities::AbstractVector, prescribed_dofs::AbstractVector{<:Integer}, dofmapping) |
I would prefer the interface
add_inhomogeneities!(f::AbstractVector, ch::ConstraintHandler, K::AbstractMatrix)
for extra clarity (that only f
is modified), and easier extensibility (following the change for zero_out_columns!
and zero_out_rows!
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. That makes sense from an interface point of view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, any reason not passing the constraint handler instead of inhomogeneities, prescribed_dofs, and dofmapping? (Esp. since dofmapping isn't always used).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No specific reason. The internals are not consistent here. I changed it to take the ch for now to simplify forward compatibility.
Thanks for the review Knut!
Almost. It should contain all changes to allow users to add support for any of their favorite serial matrix formats in their packages (BSR,CSR,CSC,...) and it adds helpers for CSR/CSC to do some of the stuff. The main blocker on master is right now that there is no easy way to add support for new matrix formats in the constraint handler and this PR introduces necessary hooks. I am not sure if I missed somthing more advanced than Dirichlet tho.
Can elaborate why adding an extension should make us responsible for fixing bugs in upstream packages? If I would not add the CSR stuff here then there would be again the question why the refactor which I propose is necessary in first place...
I have essentially given up on the effort of establishing an interface for different matrix types centrally right now, as it does not seem to be something people actually want, if you look at all the discussion in e.g. slack or discourse. But to answer the question: Yes, that was my initial plan, to have interfaces to different matrix formats which we can adopt. I just started adding a custom intermediate layer in Thunderbolt to circumvent the lack of a well-defined interface. |
No, I meant that it makes us responsible for maintaining the extension. And IIUC we don't actually have a use case to support Another option could be to add a how-to on how to support a new matrix format, if the interface is considered stable enough? (Or just mark as experimental/devdocs) |
Right, as with all other extensions.
IterativeSolvers.jl, Krylov.jl, KrylovKit.jl to name a few and we can implement how to cheaply convert the format to most direct solvers like Pardiso.jl , which require CSR. I also use it in Thunderbolt to wrap for my parallel CSR format and for parallel preconditioners therein.
Yes. Should I add these also to the PR?
I wanted to do this later after PRs to support the big packages are done, so we actually can figure out if it is stable enough. |
Aha, then I misunderstood the conversations here, #864 (comment), #864 (comment), #864 (comment), #864 (comment).
No, that wasn't what I meant. Related to above, I just didn't know that |
Probably to elaborate here, most of the iterative solvers packages literally just need to define matrix-vector products to be defined for the thing you shove into them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some details, but otherwise LGTM.
Co-authored-by: Knut Andreas Meyer <knutam@gmail.com>
Co-authored-by: Knut Andreas Meyer <knutam@gmail.com>
Thanks for the detailed review Knut! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some formatting (and we should run CI as it includes the formatting check) and the changelog is included in the docs.
Co-authored-by: Knut Andreas Meyer <knutam@gmail.com>
Towards #848 and #628 . This should show how we could assemble into custom sparse matrix formats.
TODO