# How to use CachingPool?

**URL:** https://discourse.julialang.org/t/how-to-use-cachingpool/18498
**Category:** Julia at Scale
**Created:** [December 9, 2018, 6:29pm UTC](https://discourse.julialang.org/t/how-to-use-cachingpool/18498 "2018-12-09T18:29:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MaximilianJHuber](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maximilianjhuber/32/2579_2.png) [@MaximilianJHuber](https://discourse.julialang.org/u/MaximilianJHuber)
#### Post date: [December 9, 2018, 6:29pm UTC](https://discourse.julialang.org/t/how-to-use-cachingpool/18498/1 "2018-12-09T18:29:03Z")

</div>

Do I used the CachingPool incorrectly, or is this a bug?

On Julia 1.0.2:

```julia
using Distributed
addprocs(2)
@everywhere f_passall(a,x) = length(x) + a
its = 1:20
bigarr = ones(10^8)
pool = CachingPool(workers())
pmap(pool, x->f_passall(x,bigarr), its)

```

throws:

```julia
MethodError: no method matching iterate(::getfield(Main, Symbol("##9#10")))
Closest candidates are:
  iterate(!Matched::Core.SimpleVector) at essentials.jl:589
  iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:589
  iterate(!Matched::ExponentialBackOff) at error.jl:171
  ...
in top-level scope at base\none
in pmap at stdlib\v1.0\Distributed\src\pmap.jl:157
in #pmap#226 at stdlib\v1.0\Distributed\src\pmap.jl:157
in pmap at stdlib\v1.0\Distributed\src\pmap.jl:156
in #pmap#225 at stdlib\v1.0\Distributed\src\pmap.jl:156
in pmap at stdlib\v1.0\Distributed\src\pmap.jl:101
in #pmap#215 at stdlib\v1.0\Distributed\src\pmap.jl:126
in at base\none
in #asyncmap#667 at base\asyncmap.jl:81
in at base\none
in #async_usemap#668 at base\asyncmap.jl:103
in wrap_n_exec_twice at base\asyncmap.jl:154
in maptwice at base\asyncmap.jl:162
in map at base\abstractarray.jl:2013
in collect at base\array.jl:619
in iterate at base\generator.jl:44 
in iterate at base\iterators.jl:320 
in zip_iterate at base\iterators.jl:300

```

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [December 10, 2018, 9:27pm UTC](https://discourse.julialang.org/t/how-to-use-cachingpool/18498/2 "2018-12-10T21:27:22Z")

</div>

I think you might have the argument order wrong:

Have you tried `pmap(x->f_passall(x,bigarr), pool, its)` ?

See [Distributed Computing · The Julia Language](https://docs.julialang.org/en/v1.0/stdlib/Distributed/#Distributed.pmap)

Xref: [https://github.com/JuliaLang/julia/issues/30332](https://github.com/JuliaLang/julia/issues/30332)

---

<div class="post-metadata">

### Author: ![MaximilianJHuber](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maximilianjhuber/32/2579_2.png) [@MaximilianJHuber](https://discourse.julialang.org/u/MaximilianJHuber)
#### Post date: [December 10, 2018, 10:26pm UTC](https://discourse.julialang.org/t/how-to-use-cachingpool/18498/3 "2018-12-10T22:26:58Z")

</div>

The second argument is a WorkerPool, which [defaults](https://github.com/JuliaLang/julia/blob/d789231e9985537686052db9b2314c0d51656308/stdlib/Distributed/src/pmap.jl#L156) to the pool of idle workers.

---

<div class="post-metadata">

### Author: ![MaximilianJHuber](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maximilianjhuber/32/2579_2.png) [@MaximilianJHuber](https://discourse.julialang.org/u/MaximilianJHuber)
#### Post date: [December 10, 2018, 10:56pm UTC](https://discourse.julialang.org/t/how-to-use-cachingpool/18498/4 "2018-12-10T22:56:05Z")

</div>

You are right, the `CachingPool` is a [subtype](https://github.com/JuliaLang/julia/blob/c2b61df607f24c0c58076c70dfb4f4a08f0f5a73/stdlib/Distributed/src/workerpool.jl#L273) of an `AbstractWorkerPool`! Thank you!

It might be used incorrectly (compared to Julia 1.0.2) [here](https://discourse.julialang.org/t/pmap-slow-compared-to-map/14691), [here](https://discourse.julialang.org/t/pmap-performance-regression-pmap-x-f-x-y-x-creates-copies-of-y/14221/9), [here](https://discourse.julialang.org/t/everywhere-and-pmap-inside-of-a-function/5405/6), and [here](https://discourse.julialang.org/t/how-should-i-implement-parallel-maximum-likelihood/10113).

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [December 10, 2018, 11:55pm UTC](https://discourse.julialang.org/t/how-to-use-cachingpool/18498/5 "2018-12-10T23:55:19Z")

</div>

> [@MaximilianJHuber](#):
>
> It might be used incorrectly (compared to Julia 1.0.2) [here](https://discourse.julialang.org/t/pmap-slow-compared-to-map/14691), [here](https://discourse.julialang.org/t/pmap-performance-regression-pmap-x-f-x-y-x-creates-copies-of-y/14221/9), [here](https://discourse.julialang.org/t/everywhere-and-pmap-inside-of-a-function/5405/6), and [here](https://discourse.julialang.org/t/how-should-i-implement-parallel-maximum-likelihood/10113).

`pmap` arguments were re-ordered to allow do-block syntax ( [reorder pmap arguments to allow do-block syntax by mweastwood · Pull Request #26783 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/26783) ).

Using v0.7 gives you deprecation message:

```julia
Julia-0.7.0> pmap(pool, x->f_passall(x,bigarr), its)
┌ Warning: `pmap(p::AbstractWorkerPool, f, c; kwargs...)` is deprecated, use `pmap(f, p, c; kwargs...)` instead.
│ caller = top-level scope at none:0
└ @ Core none:0

```
