# Pmap extremely slow when function returns large object

**URL:** https://discourse.julialang.org/t/pmap-extremely-slow-when-function-returns-large-object/74937
**Category:** Performance
**Tags:** question, performance, parallel
**Created:** [January 20, 2022, 1:12pm UTC](https://discourse.julialang.org/t/pmap-extremely-slow-when-function-returns-large-object/74937 "2022-01-20T13:12:41Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [January 20, 2022, 2:12pm UTC](https://discourse.julialang.org/t/pmap-extremely-slow-when-function-returns-large-object/74937/4 "2022-01-20T14:12:16Z")

</div>

Here is the best I see with large tuples

```julia
using BenchmarkTools
using Distributed
using SharedArrays

addprocs(length(Sys.cpu_info())÷2-1)

@everywhere using Random
@everywhere N = 100
@everywhere function foo(i)
	Random.seed!(i)
	NTuple{N*N,Float64}(rand(N,N))
end

n = 10

@btime (array = pmap(1:n) do i
    foo(i)
end)
println()

```

yielding

```julia
  12.775 ms (200650 allocations: 8.42 MiB)

```

and that is not including considerable compilation time as you already noted. Regarding this see for example [Correct way to dereference large memory? - #4 by jakobnissen](https://discourse.julialang.org/t/correct-way-to-dereference-large-memory/47395/4)

---

_[View the full topic](https://discourse.julialang.org/t/pmap-extremely-slow-when-function-returns-large-object/74937)._
