# Pmap usage

**URL:** <https://discourse.julialang.org/t/pmap-usage/51718>\
**Category:** Performance\
**Tags:** question, parallel\
**Created:** [December 12, 2020, 1:31pm UTC](https://discourse.julialang.org/t/pmap-usage/51718 "2020-12-12T13:31:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmurga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmurga/32/15944_2.png) [@jmurga](https://discourse.julialang.org/u/jmurga)\
**Post date:** [December 12, 2020, 1:31pm UTC](https://discourse.julialang.org/t/pmap-usage/51718/1 "2020-12-12T13:31:55Z")

</div>

Hi everyone,

I am trying to execute a custom function in my own server using `pmap` function. The server accounts for two physical cpus and a 24 threads.  
The problem is at the second execution of the functions, the number of procs selected using `Distributed.addprocs()` are not working at 100%, while at the first execution all threads are running at 100%.

This is my current function:  
`tmp = Distributed.pmap(bgsIter,nParam,afac,bfac,alTot,alLow,ndivergence,nSfs,nDac);`  
where `bgsIter` execute internally another functions. One execution of `bgsIter` takes about 0.4ms. Am I using pmap correctly or should I move to other `Distributed` function?

As I far understand from the documentation `pmap` is designed for these cases: _Julia’s [`pmap`](https://docs.julialang.org/en/v1/stdlib/Distributed/#Distributed.pmap) is designed for the case where each function call does a large amount of work. In contrast, `@distributed for` can handle situations where each iteration is tiny, perhaps merely summing two numbers._

I am really a beginner with parallel programming so any advice will be great!

Thanks in advance, Jesús.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [December 13, 2020, 7:43am UTC](https://discourse.julialang.org/t/pmap-usage/51718/2 "2020-12-13T07:43:26Z")

</div>

Maybe you’re better off using threads, as you are on a single machine (and the 0.4ms seems a rather short execution time to use pmap). You could try [https://github.com/tkf/ThreadsX.jl](https://github.com/tkf/ThreadsX.jl) and the `map` function there.

However, to get more help you really need to provide an executable, minimal example. Otherwise it’s tricky to help you more.
