I’m following the documentation for parallel code in Julia v1.0. The simple example in the docs for using a 1D SharedArrays and @distributed does execute correctly for me. However, if I modify the example to make the SharedArray be 2D instead of 1D, it no longer works correctly.
using SharedArrays, Distributed
a = SharedArray{Float64}(5,5)
@distributed for i = 1:5
a[i,:] = i
end
a
5×5 SharedArray{Float64,2}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
I found that explicitly doing the assignment with another inner for loop will work correctly. This is inconvenient though
a = SharedArray{Float64}(5, 5)
@distributed for i = 1:5
for j in 1:5
a[i,j] = i
end
end
a
5×5 SharedArray{Float64,2}:
1.0 1.0 1.0 1.0 1.0
2.0 2.0 2.0 2.0 2.0
3.0 3.0 3.0 3.0 3.0
4.0 4.0 4.0 4.0 4.0
5.0 5.0 5.0 5.0 5.0