# How do I use multithreaded BLAS in each MPI process

**URL:** https://discourse.julialang.org/t/how-do-i-use-multithreaded-blas-in-each-mpi-process/40587
**Category:** Julia at Scale
**Tags:** question
**Created:** [June 1, 2020, 10:38pm UTC](https://discourse.julialang.org/t/how-do-i-use-multithreaded-blas-in-each-mpi-process/40587 "2020-06-01T22:38:25Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![shipengcheng1230](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shipengcheng1230/32/4089_2.png) [@shipengcheng1230](https://discourse.julialang.org/u/shipengcheng1230)
#### Post date: [June 1, 2020, 10:38pm UTC](https://discourse.julialang.org/t/how-do-i-use-multithreaded-blas-in-each-mpi-process/40587/1 "2020-06-01T22:38:25Z")

</div>

I would like to launch one MPI process on each node and perform multithreaded BLAS, the same as tested [here](https://scicomp.stackexchange.com/questions/7766/performance-optimization-or-tuning-possible-for-scalapack-gemm), and discussed at [combining-distributed-computing-multithreading](https://discourse.julialang.org/t/combining-distributed-computing-multithreading/24320).

Specifically, I am trying to use [Elemental.jl](https://github.com/JuliaParallel/Elemental.jl):

```julia
using MPI, MPIClusterManagers, Distributed
using BenchmarkTools

np = 20
man = MPIManager(np = np)
addprocs(man)
println("Added procs $(procs())")

@everywhere using LinearAlgebra, Elemental, MPI

@mpi_do man begin
    A = Elemental.DistMatrix{Float64}
    B = Elemental.uniform(A, 50000, 50000)
    C = Elemental.uniform(A, 50000)
    D = Elemental.uniform(A, 50000)
end

@btime @mpi_do man begin
    mul!(D, B, C, 1.0, 0.0)
end

```

However, the example above is the worst kind of usage for launching as many MPI processes as the number of CPUs, which has way too much communication overhead.

I noticed that there is an option `enable_threaded_blas` in [addprocs](https://docs.julialang.org/en/v1/stdlib/Distributed/#Distributed.addprocs). However, I still don’t have any clue about how to glue them together. How may I achieve this, given the example code above, or use another library if possible in Julia’s ecosystem?

Thanks for your time and help!
