Strange behavior parallel for


#1

I’m having a strange behavior when using @parallel for inside other for.

 c = collect(0:0.1:0.2)
 λ = [0.0 0.0]
 for λ[1] in c
   @parallel for λ[2] in c
     println("λ $(λ)")
   end
 end

Running this code with one thread prints this strange result:

λ [0.2 0.0]
λ [0.2 0.1]
λ [0.2 0.2]
λ [0.2 0.0]
λ [0.2 0.1]
λ [0.2 0.2]

But running the same code with two threads(julia -p 2) I get the correct behavior:

From worker 3:  λ [0.0 0.2]
From worker 2:  λ [0.0 0.0]
From worker 2:  λ [0.0 0.1]
From worker 2:  λ [0.1 0.0]
From worker 3:  λ [0.1 0.2]
From worker 3:  λ [0.2 0.2]
From worker 2:  λ [0.1 0.1]
From worker 2:  λ [0.2 0.0]
From worker 2:  λ [0.2 0.1]

I’m not sure if this is an issue.


#2

Mutation of normal array won’t be visible on a different worker.