-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Non inlining of function arguments causing slow creation of sparse matrices from IJV format #10694
Comments
Yes, the default should probably be special-cased. My sense is that wanting a function other than |
I can't answer how common it is to use other functions than |
Maybe just replace |
Or make |
Matlab only implements |
|
I often use other combine functions when using sparse matrices as graph data structures and doing graph algorithms. Often, just overwriting rather than combining is useful to have. Matlab created |
I think sparse accumarray exists now. |
Perhaps it was not there 5 years back (or maybe it was), when I used matlab a lot. We've come a long way. :-) |
@KristofferC Can you try and see how the latest master performs now? I merged @mauro3 's PR. |
BTW, I didn't mean to close this issue. @KristofferC Is your code that generates the I, J, and V self-contained? It would be great if you can share it in that case. It would make a nice perf test. |
It is not self contained but it shouldnt be too hard to generate a small benchmark that has the same characteristics as te one I get in my FE code. I am currently in a place where I am unable to get the latest master but on Monday I should be able to test the functor commit and write the benchmark. |
I feel like we've piled a lot of requests on @KristofferC...you're going to have a busy Monday at this rate! |
This is an example which shows the difference between the current functor method and the previous that only used function argument: function IJV_bench(sparsity::FloatingPoint, n::Int, accums::Int)
nzs_1 = repmat(rand(1:n, Int(sparsity * n^2)), accums)
nzs_2 = repmat(rand(1:n, Int(sparsity * n^2)), accums)
vals = rand(Float64, length(nzs_1))
@time Base.sparse(nzs_1, nzs_2, vals, n, n, +)
@time Base.sparse(nzs_1, nzs_2, vals, n, n)
return
end
sparsity = 0.0001
n = 10^5
accums = 20
IJV_bench(sparsity, n, accums)
I put |
Here the result of the benchmark:
and with
both a bit more than 4x faster. |
Is there anything more to do here? Else, maybe close it. |
The default functions being passed into the sparse matrix constructors from IJV vectors, for example:
are not inlined, which means that significant time is spent to do type inference when the combine function is called many times.
In my code, for a medium sized FEM problem, the difference between inlining the plus or not is about 4x:
Since plus is the most common, maybe a special version should be made for that.
I realize that inlining of function arguments is coming so then this will be fixed by itself, however, if this it far away, then it might be worth looking at this.
The text was updated successfully, but these errors were encountered: