Julia Language pmap


Example

pmap takes a function (that you specify) and applies it to all of the elements in an array. This work is divided up amongst the available workers. pmap then returns places the results from that function into another array.

addprocs(3)
sqrts = pmap(sqrt, 1:10)

if you function takes multiple arguments, you can supply multiple vectors to pmap

dots = pmap(dot, 1:10, 11:20)

As with @parallel, however, if the function given to pmap is not in base Julia (i.e. it is user-defined or defined in a package) then you must make sure that function is available to all workers first:

@everywhere begin
    function rand_det(n)
        det(rand(n,n))
    end
end

determinants = pmap(rand_det, 1:10)

See also this SO Q&A.