Multiplication, sum and Cholesky decomposition of sparse matrices

I’m trying to solve a system of differential equations involving variational inequalities. I’m currently using the LCP solver in LCPsolve.jl. I’ve profiled my code and found that the bottleneck is in lines 216-219 here. More specifically, the profiler highlights the multiplication and sum in:

``````H = Jk'*Jk + μ*I
``````

where `Jk` is a sparse matrix with size that varies within the `for` loop (but always smaller than 150x150) and

``````typeof(Jk) = SparseMatrixCSC{Float64, Int64}
typeof(μ) = Float64
``````

It also seems that those steps also allocate memory. The other operation highlighted by the profiler is

``````-(cholesky(H)\Jphi)
``````

where

``````typeof(H) = SparseMatrixCSC{Float64, Int64}
typeof(Jphi) = Vector{Float64}
``````

Is there a way to improve the performance and/or memory allocation of those steps? Thank you!

For such a tiny matrix, you might be better off with dense-matrix operations. Does `Jk` have an particular sparsity pattern?

1 Like

It is either a tridiagonal matrix or it looks like this:

``````⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀
⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⡇⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⣹⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢻⣦⡀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡏⠈⠻⣦⡀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡼⠁⠀⠀⠈⠻⣦`````````

This is the same as julia - Multiplication, sum and Cholesky decomposition of sparse matrices - Stack Overflow, right?

Yes it is.