# Using MKL in 1.7

**URL:** <https://discourse.julialang.org/t/using-mkl-in-1-7/72398>\
**Category:** Performance\
**Tags:** package\
**Created:** [December 1, 2021, 7:00pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398 "2021-12-01T19:00:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [December 1, 2021, 7:00pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/1 "2021-12-01T19:00:08Z")

</div>

My understanding is that all you need to do is type

```julia
using MKL

```

in the REPL and BLAS trampoline will take care of the rest. When I do that I see no difference in performance.

What should I be doing? I’m on an Intel Mac and MKL.jl installed with no complaints.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [December 1, 2021, 7:02pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/2 "2021-12-01T19:02:00Z")

</div>

What platform are you using?

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [December 1, 2021, 7:02pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/3 "2021-12-01T19:02:17Z")

</div>

Intel Mac

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [December 1, 2021, 7:04pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/4 "2021-12-01T19:04:41Z")

</div>

What does `LinearAlgebra.BLAS.get_config()` say for you after you load `MKL`?

```julia
julia> using LinearAlgebra.BLAS

julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
└ [ILP64] libopenblas64_.so

julia> using MKL

julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
└ [ILP64] libmkl_rt.so

```

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [December 1, 2021, 7:07pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/5 "2021-12-01T19:07:25Z")

</div>

Looks like it’s doing the right thing. Seems like I need more compelling benchmarks.

Thanks,

```julia
julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
└ [ILP64] libopenblas64_.0.3.13.dylib

julia> using MKL

julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
└ [ILP64] libmkl_rt.1.dylib

```

---

<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:** [December 1, 2021, 7:37pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/6 "2021-12-01T19:37:44Z")

</div>

FWIW, on my Macbook Pro (Intel):

```julia
julia> using BenchmarkTools

julia> using LinearAlgebra

julia> BLAS.set_num_threads(1)

julia> A = rand(1000,1000); B = rand(1000,1000);

julia> @btime $A * $B;
  53.150 ms (2 allocations: 7.63 MiB)

julia> @btime inv($A);
  79.604 ms (5 allocations: 8.13 MiB)

julia> using MKL

julia> BLAS.set_num_threads(1)

julia> @btime $A * $B;
  51.048 ms (2 allocations: 7.63 MiB)

julia> @btime inv($A);
  62.249 ms (5 allocations: 9.35 MiB)

```

(UPDATED because I didn’t set the number of threads to one for MKL.)

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [December 1, 2021, 7:46pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/7 "2021-12-01T19:46:49Z")

</div>

Interesting. Your matrix-matrix product timings are like what I got with a different example. I did not try inv and am somewhat surprised at what you found. MKL may not be as amazing as I expected.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [December 1, 2021, 7:52pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/8 "2021-12-01T19:52:47Z")

</div>

You’re setting num threads to 1 with OpenBLAS but not MKL?

```julia
julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
└ [ILP64] libopenblas64_.so

julia> BLAS.set_num_threads(1)

julia> A = rand(1000,1000); B = rand(1000,1000);

julia> @btime $A * $B;
  45.090 ms (2 allocations: 7.63 MiB)

julia> using MKL

julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
└ [ILP64] libmkl_rt.so

julia> @btime $A * $B;
  14.268 ms (2 allocations: 7.63 MiB)

julia> BLAS.set_num_threads(1)

julia> @btime $A * $B;
  45.732 ms (2 allocations: 7.63 MiB)

```

---

<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:** [December 1, 2021, 7:55pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/9 "2021-12-01T19:55:37Z")

</div>

Indeed, my bad. Correct it above.

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [December 8, 2021, 6:33pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/10 "2021-12-08T18:33:23Z")

</div>

Is there any way I can use the output of BLAS.get\_config() within a program to see if I’m using MKL or not?

---

<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:** [December 8, 2021, 6:37pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/11 "2021-12-08T18:37:38Z")

</div>

Something along the lines of `any(contains("mkl"), getfield.(BLAS.get_config().loaded_libs, :libname))` should do the job.

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [December 8, 2021, 6:44pm UTC](https://discourse.julialang.org/t/using-mkl-in-1-7/72398/12 "2021-12-08T18:44:29Z")

</div>

That did it. Thanks.
