# Pmap results in Array of type Any

**URL:** <https://discourse.julialang.org/t/pmap-results-in-array-of-type-any/53307>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 13, 2021, 10:00pm UTC](https://discourse.julialang.org/t/pmap-results-in-array-of-type-any/53307 "2021-01-13T22:00:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![threadedblue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/threadedblue/32/19247_2.png) [@threadedblue](https://discourse.julialang.org/u/threadedblue)\
**Post date:** [January 13, 2021, 10:00pm UTC](https://discourse.julialang.org/t/pmap-results-in-array-of-type-any/53307/1 "2021-01-13T22:00:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [January 13, 2021, 10:14pm UTC](https://discourse.julialang.org/t/pmap-results-in-array-of-type-any/53307/2 "2021-01-13T22:14:57Z")

</div>

Please provide an MWE (minimum working example).  
See also: [PSA Make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![threadedblue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/threadedblue/32/19247_2.png) [@threadedblue](https://discourse.julialang.org/u/threadedblue)\
**Post date:** [January 14, 2021, 1:28pm UTC](https://discourse.julialang.org/t/pmap-results-in-array-of-type-any/53307/3 "2021-01-14T13:28:40Z")

</div>

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.

```julia
#!/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:

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

```

---

<div class="post-metadata">

**Author:** ![threadedblue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/threadedblue/32/19247_2.png) [@threadedblue](https://discourse.julialang.org/u/threadedblue)\
**Post date:** [January 14, 2021, 2:26pm UTC](https://discourse.julialang.org/t/pmap-results-in-array-of-type-any/53307/4 "2021-01-14T14:26:14Z")

</div>

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:

```julia
#!/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))

```

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [January 14, 2021, 2:26pm UTC](https://discourse.julialang.org/t/pmap-results-in-array-of-type-any/53307/5 "2021-01-14T14:26:44Z")

</div>

```julia
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"

```

---

<div class="post-metadata">

**Author:** ![threadedblue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/threadedblue/32/19247_2.png) [@threadedblue](https://discourse.julialang.org/u/threadedblue)\
**Post date:** [January 14, 2021, 2:29pm UTC](https://discourse.julialang.org/t/pmap-results-in-array-of-type-any/53307/6 "2021-01-14T14:29:40Z")

</div>

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

Thanks, I had no idea.

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [January 14, 2021, 2:33pm UTC](https://discourse.julialang.org/t/pmap-results-in-array-of-type-any/53307/7 "2021-01-14T14:33:00Z")

</div>

```julia
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. 🙂

Also if I then apply it to an empty vector:

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

```
