You may simply be delaying the computation long enough for the workers to 
finish their task.

--Tim

On Thursday, May 21, 2015 12:56:41 PM rk wrote:
> Hi
> 
> I'm trying to understand the behavior of the following code that uses a
> SharedArray and a parallel for loop
> 
> a = SharedArray(Float64,10,10)
> @parallel for i = 1:10
>   for j = 1:10
>     a[i,j] = i + j
>   end
> end
> sum(a)
> 
> 
> As may be expected, the above code does not correctly compute sum(a) while
> attaching an @sync before the @parallel does. However, if I the run the
> following code,
> 
> a = SharedArray(Float64,10,10)
> @parallel for i = 1:10
>   for j = 1:10
>     a[i,j] = i + j
>   end
> end
> a.*1
> sum(a)
> 
> I do get the correct value for sum(a). I'm trying to understand the reason
> for this. Maybe I'm misunderstanding something quite basic about the usage
> of SharedArrays and the parallel for loop.
> 
> Thank you very much for your help

Reply via email to