# Speeding up matrix exponential and matrix multiplication

**URL:** <https://discourse.julialang.org/t/speeding-up-matrix-exponential-and-matrix-multiplication/102272>\
**Category:** Performance\
**Tags:** question, speed-optimization, matrix\
**Created:** [July 30, 2023, 4:22pm UTC](https://discourse.julialang.org/t/speeding-up-matrix-exponential-and-matrix-multiplication/102272 "2023-07-30T16:22:00Z")\
**Posts on this page:** 1\
**Showing post:** 53

<div class="post-metadata">

**Author:** ![eveningsilverfox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eveningsilverfox/32/51932_2.png) [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Post date:** [July 31, 2023, 10:31pm UTC](https://discourse.julialang.org/t/speeding-up-matrix-exponential-and-matrix-multiplication/102272/53 "2023-07-31T22:31:38Z")

</div>

This expands on it:

> [@Regarding the multithreaded performance of OpenBLAS](https://discourse.julialang.org/t/regarding-the-multithreaded-performance-of-openblas/75450/5):
>
> 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 OpenBL…

> [@Matrix multiplication is slower when multithreading in Julia](https://discourse.julialang.org/t/matrix-multiplication-is-slower-when-multithreading-in-julia/56227/12):
>
> While this is true (at least I think so as well), I guess the interesting part is what happens for BLAS.set\_num\_threads(N) where N\>1. And based on a simple test I just ran, OpenBLAS (default) and MKL behave very differently here! Test function: function f() X = rand(1000,1000); Y = zeros(Threads.nthreads()) Threads.@threads for i in 1:Threads.nthreads() Y[i] = sum(X \* X) end return Y end MKL: # 4 Julia threads julia\> BLAS.set\_num\_threads(1) julia\> @btime f(); #…

> **[Julia Threads + BLAS Threads · ThreadPinning.jl](https://carstenbauer.github.io/ThreadPinning.jl/dev/explanations/blas/)**
>
> Documentation for ThreadPinning.jl.

---

_[View the full topic](https://discourse.julialang.org/t/speeding-up-matrix-exponential-and-matrix-multiplication/102272)._
