# Is the Julia linear algebra multithreaded?

**URL:** <https://discourse.julialang.org/t/is-the-julia-linear-algebra-multithreaded/8487>\
**Category:** General Usage\
**Created:** [January 20, 2018, 1:57am UTC](https://discourse.julialang.org/t/is-the-julia-linear-algebra-multithreaded/8487 "2018-01-20T01:57:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 20, 2018, 1:57am UTC](https://discourse.julialang.org/t/is-the-julia-linear-algebra-multithreaded/8487/1 "2018-01-20T01:57:19Z")

</div>

Is the Julia linear algebra multithreaded? I think I read somewhere that it isn’t, but I can’t find that text anymore. Does anyone know for sure?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [January 20, 2018, 1:59am UTC](https://discourse.julialang.org/t/is-the-julia-linear-algebra-multithreaded/8487/2 "2018-01-20T01:59:25Z")

</div>

It is multithreaded. You can use `BLAS.set_num_threads(1)` if you want single threaded.  
This also applies to many LAPACK functions.  
The default is set to the number of physical cores, not threads. Eg, eigfact would churn away at 1600% CPU on my threadripper for huge matrices.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 20, 2018, 2:02am UTC](https://discourse.julialang.org/t/is-the-julia-linear-algebra-multithreaded/8487/3 "2018-01-20T02:02:22Z")

</div>

> [@Elrod](#):
>
> BLAS.set\_num\_threads(1)

Excellent, thank you very much!

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 20, 2018, 2:48am UTC](https://discourse.julialang.org/t/is-the-julia-linear-algebra-multithreaded/8487/4 "2018-01-20T02:48:29Z")

</div>

Would you by any chance also know how `BLAS.set_num_threads` interacts with `JULIA_NUM_THREADS `? Is it independent of it, or is it only allowing the number of threads to be set up to this number?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [January 20, 2018, 2:53am UTC](https://discourse.julialang.org/t/is-the-julia-linear-algebra-multithreaded/8487/5 "2018-01-20T02:53:25Z")

</div>

They’re independent.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 20, 2018, 2:54am UTC](https://discourse.julialang.org/t/is-the-julia-linear-algebra-multithreaded/8487/6 "2018-01-20T02:54:14Z")

</div>

Splendid. Ta!

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [February 7, 2018, 2:31pm UTC](https://discourse.julialang.org/t/is-the-julia-linear-algebra-multithreaded/8487/7 "2018-02-07T14:31:05Z")

</div>

In case someone wants to see what `BLAS` number of threads is currently set to: [https://github.com/JuliaLang/julia/blob/251a501def6a52d497784ad1ca8206579d814bce/stdlib/Distributed/test/distributed\_exec.jl#L918](https://github.com/JuliaLang/julia/blob/251a501def6a52d497784ad1ca8206579d814bce/stdlib/Distributed/test/distributed_exec.jl#L918)

Note that one has to change `LinearAlgebra` to `LinAlg` for julia version \< 0.7.
