Pmap results in Array of type Any

All,

New to Julia Distribution and I have a question about pmap usage particularly as to it’s return value.

I have two functions I am calling with pmap. One is written to return a simple string value, the otherreturns a struct. Both appear to be working but both are returning “Any”.

Is this right?

Please provide an MWE (minimum working example).
See also: PSA Make it easier to help you

1 Like

The following is from the script I am running from my OSX laptop. My worker is Ubuntu 18.04. I’ll show the string return for now. Likely, the struct problem is similar.

#!/usr/bin/env julia
using Distributed
workers = ["haz@uno"]
@everywhere module Encounters
    function createT()
        return "Tccd"
    end
end
T = pmap(Encounters.createT, [])
println(typeof(T))

I run it:

$> ./r.jl
Array{Any,1}

Apologies, in my zeal to post the above, I missed the call to addprocs in my sloppy cut and paste. See the new improved below:

#!/usr/bin/env julia
using Distributed
workers = ["haz@uno"]
addprocs(workers; tunnel=true, exename=`julia`,  dir="/home/haz", sshflags=`-p 2222`)`
@everywhere module Encounters
    function createT()
        return "Tccd"
    end 
end
T = pmap(Encounters.createT, [])
println(typeof(T))
julia> using Distributed

julia> addprocs(2);

julia> @everywhere module Encounters
           function createT(x)    # here you need a parameter
               return "Tccd"
           end
       end

julia> @everywhere using .Encounters

julia> T = pmap(Encounters.createT, [1,2,3])
3-element Array{String,1}:
 "Tccd"
 "Tccd"
 "Tccd"

So that’s it, the function called by pmap must have a parameter? I’ll take silence as a yes. :slightly_smiling_face:

Thanks, I had no idea.

help?> pmap
search: pmap promote_shape proportionmap typemax corspearman PermutedDimsArray

  pmap(f, [::AbstractWorkerPool], c...; distributed=true, batch_size=1, on_error=nothing, retry_delays=[], retry_check=nothing) -> collection

  Transform collection c by applying f to each element using available workers
  and tasks.

you cannot apply f to each element if it is parameterless. :slightly_smiling_face:

Also if I then apply it to an empty vector:

julia> T = pmap(Encounters.createT, [])
Any[]