Just put @sync in front of @parallel. The workers are not yet done with their 
tasks before you run your test.

Please capture these hints by making pull requests to improve the parallel 
documentation---you'll save future users the confusion you're suffering 
(sorry), and other developers the time in answering. 
https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#improving-documentation

--Tim

On Tuesday, July 21, 2015 03:58:19 PM Richard Dennis wrote:
> Running 0.4.0-dev+5933.  I expected the print outs from this code to be the
> same and to equal zero.  What am I doing wrong?  Thanks in advance.
> 
> addprocs(4);
> 
> @everywhere function test(state)
>   return state.^2.0
> end
> 
> const n = 10000;
> const m = 10000;
> states = randn(n);
> store = zeros(n,m);
> for i = 1:n j = 1:m
>   state = states[i]
>   store[i,j] = i-j+test(state)
> end
> 
> stored = SharedArray(typeof(1.0),n,m);
> @parallel for i = 1:n j = 1:m
>   state = states[i]
>   stored[i,j] = i-j+test(state)
> end
> 
> println(maximum(store-stored))
> println(maximum(store-stored))
> 
> rmprocs(2:5);

Reply via email to