On Wednesday, 17 June 2015 10:28:37 UTC+2, Nils Gudat wrote:
>
> I haven't used @everywhere in combination with begin..end blocks, I 
> usually pair @sync with @parallel - see an example here 
> <https://github.com/nilshg/LearningModels/blob/master/NHL/NHL_6_Bellman.jl>, 
> where I've parallelized the entire nested loop ranging from lines 25 to 47. 
>


Aha! Thanks. Copying your example I was able to produce this:

    N = 5
    tmp = SharedArray(Int, (N))
    
    for i = 1:N
        # Compute tmp in parallel #
        @sync @parallel for j = (i + 1):N
            tmp[j] = i * j
        end
        
        # Consume tmp in serial #
        for j = (i + 1):N
            println(tmp[j])
        end
    end


This seems to work correctly and gives the same answer as the serial code. 
Can you help me understand how it works? What does "@sync @parallel" do? I 
feel like I half-understand it, but the concept is not clear in my head.

Thanks.

Daniel.

Reply via email to