# Regarding the multithreaded performance of OpenBLAS

**URL:** https://discourse.julialang.org/t/regarding-the-multithreaded-performance-of-openblas/75450
**Category:** Performance
**Tags:** blas, multithreading
**Created:** [January 30, 2022, 4:48am UTC](https://discourse.julialang.org/t/regarding-the-multithreaded-performance-of-openblas/75450 "2022-01-30T04:48:52Z")
**Posts on this page:** 1
**Showing post:** 5

<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: [January 30, 2022, 8:29am UTC](https://discourse.julialang.org/t/regarding-the-multithreaded-performance-of-openblas/75450/5 "2022-01-30T08:29:06Z")

</div>

> [@ash](#):
>
> What is the meaning of the special case `OPEN_BLAS_NUM_THREADS=1` ? What exactly is going on here and why do we need this when running multithreaded code? Does this mean if multithreading doesn’t benefit my code that much, I should “de-multithread” so I can run OpenBLAS with 16 threads and run the rest of the code with 1 thread? I’m confused

This has already been mentioned by me and @jpsamaroo in the [other discourse thread](https://discourse.julialang.org/t/matrix-multiplication-is-slower-when-multithreading-in-julia/56227/) you linked. Basically `OPENBLAS_NUM_THREADS=1` (you have a typo there) is special because it makes OpenBLAS computations run on the respective calling (Julia) thread. for `OPENBLAS_NUM_THREADS>1` the behavior changes qualitatively in the sense that OpenBLAS will create an own pool of OpenBLAS threads which it will use to run BLAS computation triggered by any of the Julia threads (there is only a single pool of OpenBLAS threads, irrespective of how many Julia threads you have). Hence, assuming `Threads.nthreads() == 16`, setting `OPENBLAS_NUM_THREADS=1` will, effectively, make all your BLAS computations run on all of the Julia threads (16) whereas setting `OPENBLAS_NUM_THREADS=2` will make all your BLAS computations run on only 2 separate OpenBLAS threads. That’s why you see such horrible performance for your 16/8 case for example.

As for your other question, in general, multithreading your computation with Julia threads (if possible) and using `OPENBLAS_NUM_THREADS=1` should be better than using only a single Julia thread and `OPENBLAS_NUM_THREADS=16`. The main point is that you can parallelize your specific application much more effectively than OpenBLAS, which can only parallelize the BLAS parts. However, as with every “rule of thumb”, there are exceptions and it can depend on the computation at hand. (BTW, in your case, the rule of thumb seems to hold: compare 16/1 (538) to 1/16 (900).)

---

_[View the full topic](https://discourse.julialang.org/t/regarding-the-multithreaded-performance-of-openblas/75450)._
