Hello,

I have been looking at the documentation for parallel programming, with 
special interest in SharedArrays. But no matter how hard I try, I cannot 
get a clear picture of what @sync and @async do. I think they are not 
really explained anywhere. Maybe they are explained somewhere and I just 
haven't found it. To make my question concrete, here is the implementation 
of pmap:

function pmap(f, lst)
    np = nprocs()  # determine the number of processes available
    n = length(lst)
    results = cell(n)
    i = 1
    # function to produce the next work item from the queue.
    # in this case it's just an index.
    nextidx() = (idx=i; i+=1; idx)
    @sync begin
        for p=1:np
            if p != myid() || np == 1
                @async begin
                    while true
                        idx = nextidx()
                        if idx > n
                            break
                        end
                        results[idx] = remotecall_fetch(p, f, lst[idx])
                    end
                end
            end
        end
    end
    resultsend




Can someone help me understand how this function works? In particular, what 
do @sync and @async do?

Thanks for the help.

Cheers,
Daniel

Reply via email to