-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
Description
The default functions being passed into the sparse matrix constructors from IJV vectors, for example:
sparse(I,J,V::AbstractVector,m,n) = sparse(I, J, V, Int(m), Int(n), +)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:
julia> @time sparse_inline(dof_rows, dof_cols, k_values, fp.n_eqs, fp.n_eqs)
elapsed time: 0.096662539 seconds (61 MB allocated, 3.20% gc time in 2 pauses with 0 full sweep)
80400x80400 sparse matrix with 1119192 Float64 entries:
.
.
julia> @time Base.sparse(dof_rows, dof_cols, k_values, fp.n_eqs, fp.n_eqs)
elapsed time: 0.393187843 seconds (257 MB allocated, 27.98% gc time in 11 pauses with 1 full sweep)
80400x80400 sparse matrix with 1119192 Float64 entries:
.
.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.