JuMP is slow in generating block PSD constraints

Could an expert help me speed up the following code? In particular,

  • Have I used the performance tips (Performance tips · JuMP) correctly? That is only generate expressions inside macro.

  • Does it help to use sparse matrix?

  • Does multithreading the for loop with Threads.@threads help?

Note that computeMatrix is not a bottleneck in my case, however the bottleneck could be with the fact that length(x) is large.

Edit: I did a better benchmark this time and the slowdown is mainly due to computeMatrix as caused by having large length(x) so it seems this is not a JuMP problem.

for blk in blocks
        if size(blk, 1) > 1
            println("adding PSD constraint for block of size $(size(blk))")
            @constraint(m, sum(x[i] .* computeMatrix(i, blk) for i in 1:length(x)) in PSDCone())
        else
            println("adding inequality constraint")
            @constraint(m, sum(x[i] .* computeMatrix(i, blk) for i in 1:length(x)) .>= 0)
        end
    end

Please provide a reproducible example

1 Like

Nevermind, I got it to work faster by improving the bottleneck in computeMatrix. Multithreading does not seem to help much with the speedup.

2 Likes