I am trying to debug an SDL application using the experimental multi-threading. It appears to conflict with a parallel for I wrote. I separated this parallel for part just to test it and benchmark separately, and I am having this problem calling the function with @btime. It specifically looks like after the first execution of the function it enters some kind of live-lock. It works OK with a single thread. Could this be a BenchmarkTools bug? Or a multi-threading bug?
using Images
using BenchmarkTools
using Base.Threads
function render_julia_set!(pixels, c::Complex{T}, maxit, cmap) where {T}
K,J = size(pixels)
rJ = T(1) / J
rK = T(1) / K
@threads for j in 1:J
for k in 1:K
z = (((k * rK - T(1/2)) + (j * rJ - T(1/2))im)*T(3))::Complex{T}
ju_itrs = julia_pix(c, z, maxit)
pixels[k, j] = cmap[ju_itrs]
end
# @show j
end
nothing
end
@inline function julia_pix(c::Complex{T}, z, maxit) where {T}
for iteration in 1:maxit-1
if real(z * z') >= T(4)
return iteration
end
z = z^2 + c
end
maxit
end
function bench(maxit)
c = (-0.75f0+0.11f0)*im
# K=16;J=9
K=1920;J=1080
pixels = zeros(UInt32, K, J)
cmap = map(colormap("Blues", maxit)) do aa
convert(ARGB32,aa).color
end
@btime render_julia_set!($pixels, $c, $maxit, $cmap)
# render_julia_set!(pixels, c, maxit, cmap)
# @time [render_julia_set!(pixels, c, maxit, cmap) for x in 1:100]
end
bench(31)