# MKL threading bug?

**URL:** https://discourse.julialang.org/t/mkl-threading-bug/62342
**Category:** General Usage
**Created:** [June 3, 2021, 4:10pm UTC](https://discourse.julialang.org/t/mkl-threading-bug/62342 "2021-06-03T16:10:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![juthohaegeman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juthohaegeman/32/8620_2.png) [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)
#### Post date: [June 3, 2021, 4:10pm UTC](https://discourse.julialang.org/t/mkl-threading-bug/62342/1 "2021-06-03T16:10:03Z")

</div>

Before posting this as a github issue, I wanted to confirm that this is not some problem with my computer.

The following happens for me, but only on mac (macOs Mojave 10.14.6, MacBook Pro (15-inch, 2016), 2,9 GHz Intel Core i7) with julia 1.6.1, only with MKL (installed using MKL.jl v0.4.1) and with the default setting of multithreaded MKL (i.e. it disappears with `LinearAlgebra.BLAS.set_num_threads(1)`).

Consider the following code

```julia

using LinearAlgebra
using Random
Random.seed!(111134)

B = randn(Float64, (144, 144))
eigvals(B)

D = 4
T = Float64

Q = randn(T, (D,D))
x = one(Q)
y = similar(x)

Threads.@threads for k = 0:0
	mul!(y, Q', x)
end

```

The result in `y` is correctly computed. However, now running

```julia
eigvals(B)

```

again, this call either hangs or produces completely inconsistent and incorrect results. Removing the `@threads` call surrounding `mul!`, this problem disappears.

Is there anyone that can reproduce this on a similar configuration (definitely no linux, no OpenBLAS, these all work fine)

Is there some known conflict between Julia threading (note that `Threads.nthreads() == 1`, so it should be off) and MKL threading on Mac?

---

<div class="post-metadata">

### Author: ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)
#### Post date: [June 3, 2021, 7:36pm UTC](https://discourse.julialang.org/t/mkl-threading-bug/62342/2 "2021-06-03T19:36:50Z")

</div>

Funny, I can replicate in a recent julia 1.7 nightly + MKL, but _not_ on julia 1.6.1. Both under macOS 11.4

I think you should open an issue.

---

<div class="post-metadata">

### Author: ![juthohaegeman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juthohaegeman/32/8620_2.png) [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)
#### Post date: [June 3, 2021, 7:50pm UTC](https://discourse.julialang.org/t/mkl-threading-bug/62342/3 "2021-06-03T19:50:26Z")

</div>

Thanks. Are you sure MKL was installed on 1.6.1. MKL.jl 0.4.0 pretended to install, but did not actually do anything on Julia 1.6.1 (as you could check with `BLAS.vendor()`). This was only fixed with MKL.jl 0.4.1 yesterday.

---

<div class="post-metadata">

### Author: ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)
#### Post date: [June 3, 2021, 9:15pm UTC](https://discourse.julialang.org/t/mkl-threading-bug/62342/4 "2021-06-03T21:15:16Z")

</div>

Oh, you’re completely right! Rebuilding latest MKL master in julia 1.6.1 also makes your example hang for me

---

<div class="post-metadata">

### Author: ![juthohaegeman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juthohaegeman/32/8620_2.png) [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)
#### Post date: [June 3, 2021, 9:21pm UTC](https://discourse.julialang.org/t/mkl-threading-bug/62342/5 "2021-06-03T21:21:56Z")

</div>

Thanks for confirming; I’ve opened an issue.

In case you want to follow along:  
[https://github.com/JuliaLang/julia/issues/41077](https://github.com/JuliaLang/julia/issues/41077)
