Hello! I found myself using a lot of let
statements before multi-threaded for-loops with the Threads.@threads
command in my code. I wanted to know if these were still useful in the present version of julia now. Does anyone know the status of this declaration?
For an example:
function withlet(g::Int64)
b = 1.4
A = Array{Float64,1}(undef,g)
let A = A, b = b, g = g
Threads.@threads for i = 1:g
A[i] = b
end
end
end
function nolet(g::Int64)
b = 1.4
A = Array{Float64,1}(undef,g)
# let A = A, b = b, g = g
Threads.@threads for i = 1:length(A)
A[i] = b
end
# end
end
The reason I ask is because there doesn’t seem to be a different in this simple example:
julia> using BenchmarkTools
julia> @btime withlet(5000_000)
2.954 ms (23 allocations: 38.15 MiB)
julia> @btime nolet(5000_000)
3.043 ms (23 allocations: 38.15 MiB)
I seem to remember that using the let
statement can reduce the allocations in a given function, but I can’t find the post where I saw that (circa v1.2). Is there any use to using the let
statements?