Does pmap() return in order?

Let’s say I have a function f where I do something with the ith column of a matrix available to all workers (~40). I then return an array of Any and length 4:

@everywhere function f(i:Int)
    //do something with the i-th column of matrix
    ret = Array{Any}(undef, 4)
    // write results to ret[1] to ret[4]
    return ret
end

function main()
    ret = pmap(f, 1:N)
end

When I do ret = pmap(f, 1:N) where N is large (e.g. 10k), is it guaranteed that the ret will be in order, i.e. the ret[i] will be the results from the ith column?

I ran a test case where N = 200 and seems like it is. If it actually is, then I won’t need to change my implementation.

Yes, there’s almost no way to use it otherwise. (The order that’s not guaranteed is the execution order)

3 Likes