Plotting slow

We are currently working on a simulation and the bottleneck is plotting.
We are plotting a grid of dimension 1000 x 2000 and saving it.

  
T_c_hm = heatmap(x, y, transpose(T_c_renh), size = (1000, 400), clim=(0, 0.3))
savefig("run/T_c_$it_text.png")
T_s_hm = heatmap(x, y, transpose(T_s_renh), size = (1000, 400), clim=(0, 1.0))
savefig("run/T_s_$it_text.png")
u_hm = heatmap(x, y, transpose(v_renh), size = (1000, 400), clim=(0,0.3))
savefig("run/u_$it_text.png")

We tried using gr() with no avail.

Maybe try Makie.jl?

https://docs.makie.org/stable/reference/plots/heatmap/index.html

1 Like

What would you expect?

using GR
@time heatmap(randn(1000,2000))
  0.197676 seconds (8.00 M allocations: 160.242 MiB, 24.41% gc time)

Do you have a complete MWE?

Its a bit frustrating when you have an 80 Terraflop GPU that does all the computation in 20 ms and then taking 200 ms per plot, so I guess we are going to implement it our own. Is there a fast png library that wont bottleneck again?

Perhaps you could save this as an image rather than trying to plot it as a heatmap?

If you’re interested in GPU plotting, I would at least consider if GLMakie meets your needs.

using GLMakie
julia> @time let
       f = Figure(size=(2000,1000))
       ax = Axis(f[1, 1])
       
       centers_x = 1:5
       centers_y = 6:10
       data = reshape(rand(25), 5, 5)
       
       heatmap!(ax, centers_x, centers_y, data)
       save("/tmp/my.png", f)
       end
  0.025841 seconds (96.64 k allocations: 8.738 MiB)
6 Likes

Very nice, thanks a lot. The solution we had at the end was using ParralelStencil

@parallel_indices (i, j) function heatmap_para!(image, array, min_val, max_val, table)
    x = (array[i, j] - min_val) / (max_val - min_val)

    for k in 1:3
        col = 0.0
 
        for l in 1:6
            col *= x
            col += table[k, 7-l]
        end

        image[j, i, k] = clamp(col, 0, 1)
    end

    return nothing
end