# Pmap and multi-threaded BLAS

**URL:** <https://discourse.julialang.org/t/pmap-and-multi-threaded-blas/31617>\
**Category:** Performance\
**Tags:** blas, parallel\
**Created:** [November 28, 2019, 11:09am UTC](https://discourse.julialang.org/t/pmap-and-multi-threaded-blas/31617 "2019-11-28T11:09:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahthomas](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@ahthomas](https://discourse.julialang.org/u/ahthomas)\
**Post date:** [November 28, 2019, 11:09am UTC](https://discourse.julialang.org/t/pmap-and-multi-threaded-blas/31617/1 "2019-11-28T11:09:30Z")

</div>

When I run a call to one of the low level `LinearAlgebra.BLAS` functions inside a function executed on a worker process launched via `pmap` it appears that `BLAS` does not use multiple threads. Here is a simple example:

```julia
using Distributed

@everywhere using LinearAlgebra
@everywhere function test(K)
    M = rand(K, K);
    out = BLAS.gemm('T', 'N', M, M);
    println("Done!")
end

pmap(test, [4096, 4096, 4096]);

```

Running with a single `julia` process (e.g. just using `julia` on the command line) and examining `top` shows that Julia is using about `750%` CPU which is what I would expect given that BLAS defaults to 8 threads. However, running with `julia -p 3` shows that each of the three Julia worker processes never get above `100%` CPU use. Is this expected behavior? If so are there steps I can take to allow each of the worker processes to use a multi-threaded BLAS? I’m using a machine with dozens of cores so I don’t expect contention among the processes. I’m a Julia newbie so apologies if there’s a simple explanation for this.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [November 28, 2019, 7:43pm UTC](https://discourse.julialang.org/t/pmap-and-multi-threaded-blas/31617/2 "2019-11-28T19:43:01Z")

</div>

Rather than starting with `julia -p 3`, start with one process and invoke `addprocs(3, enable_threaded_blas=true)`.

---

<div class="post-metadata">

**Author:** ![ahthomas](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@ahthomas](https://discourse.julialang.org/u/ahthomas)\
**Post date:** [November 29, 2019, 9:29am UTC](https://discourse.julialang.org/t/pmap-and-multi-threaded-blas/31617/3 "2019-11-29T09:29:10Z")

</div>

Thanks - works perfectly!
