Scope of variables inside threaded for loops?

Viewed 69

In the following example

shared_arr = zeros(4000)
Threads.@threads for thread = 1:4
    tmp_arr = rand(1000)
    for i = 1:1000
        shared_arr[(thread - 1)*1000+i] = tmp_arr[i]
    end
end

I believe shared_arr is shared among all threads. Is tmp_arr allocated 4 times so that each thread has it's own tmp_arr?

1 Answers
Related