My configuration is
julia> Threads.nthreads()
4
julia> Threads.nthreads(:default)
4
I have a function
function parallel_CG!(B, θ, β, μ, ν)
for ite = ...
...
for ba = ...
sub_j_vec = ...
println("before entering @threads, sub_j_vec = $sub_j_vec")
Threads.@threads for i = eachindex(sub_j_vec)
j = sub_j_vec[i]
# @info "inside @threads" i j
println("inside @threads, i = $i, j = $j")
end
error("No.1 can you see this error??")
end
end
end
when I call it, I get the expected result as follows
julia> parallel_CG!(B, θ, β, μ, ν)
before entering @threads, sub_j_vec = [1, 4, 2, 3]
inside @threads, i = 1, j = 1
inside @threads, i = 3, j = 2
inside @threads, i = 2, j = 4
inside @threads, i = 4, j = 3
ERROR: No.1 can you see this error??
However, if I delete the #
symbol in the definition of the function, and re-run the function, I get this corrupted result
julia> parallel_CG!(B, θ, β, μ, ν)
before entering @threads, sub_j_vec = [1, 4, 2, 3]
┌ Info: inside @threads
│ i = 1
└ j = 2
┌ Info: inside @threads
│ i = 4
└ j = 2
┌ Info: inside @threads
│ i = 2
└ j = 4
inside @threads, i = 1, j = 4
inside @threads, i = 4, j = 4
inside @threads, i = 2, j = 4
┌ Info: inside @threads
│ i = 3
└ j = 4
inside @threads, i = 3, j = 4
ERROR: No.1 can you see this error??
My question is—why?