# From MKL back to OpenBLAS

**URL:** <https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722>\
**Category:** Performance\
**Tags:** mkl\
**Created:** [April 16, 2020, 11:49pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722 "2020-04-16T23:49:23Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![martincornejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martincornejo/32/13436_2.png) [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Post date:** [April 16, 2020, 11:49pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/1 "2020-04-16T23:49:23Z")

</div>

After [building MKL on Julia](https://github.com/JuliaComputing/MKL.jl).

```julia
julia>]add https://github.com/JuliaComputing/MKL.jl

julia>] build MKL

```

Is there a way to set OpenBLAS back?

---

<div class="post-metadata">

**Author:** ![Kruxigt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kruxigt/32/11694_2.png) [@Kruxigt](https://discourse.julialang.org/u/Kruxigt)\
**Post date:** [April 29, 2020, 12:10am UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/2 "2020-04-29T00:10:05Z")

</div>

Probably not the best way but reinstalling Julia works. At least on Mac I can just run the install and replace the current install and REPL history etc will still be left.

---

<div class="post-metadata">

**Author:** ![martincornejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martincornejo/32/13436_2.png) [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Post date:** [April 29, 2020, 10:28am UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/3 "2020-04-29T10:28:03Z")

</div>

At the end that is just what I did. I wanted to know if there was an easy and fast way to switch between both in order to perform some benchmarks.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 29, 2020, 10:30am UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/4 "2020-04-29T10:30:32Z")

</div>

This should work: [MKL.jl/install.jl at 61720ba15055424dde7dabfef8e3880eebbd4566 · JuliaLinearAlgebra/MKL.jl · GitHub](https://github.com/JuliaComputing/MKL.jl/blob/61720ba15055424dde7dabfef8e3880eebbd4566/src/install.jl#L83)

---

<div class="post-metadata">

**Author:** ![martincornejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martincornejo/32/13436_2.png) [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Post date:** [April 29, 2020, 10:53am UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/5 "2020-04-29T10:53:20Z")

</div>

It took a few minutes (to be exact since you replied) for the re-build, but I had not expected for it to be faster. Thanks, that’s exactly what I was looking for.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [November 19, 2021, 5:14pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/6 "2021-11-19T17:14:04Z")

</div>

I tried to run the install script in Julia and executed

```julia
julia> enable_openblas_startup()
[ Info: Removing code to load MKL in C:\Users\Win10\AppData\Local\Programs\Julia-1.6.3\bin\..\share\julia\base\sysimg.jl
[ Info: getting precompile script from: https://raw.githubusercontent.com/JuliaLang/julia/release-1.6/contrib/generate_precompile.jl
┌ Warning: Base.download is deprecated; use Downloads.download instead
│ caller = get_precompile_statments_file() at switchblas.jl:75
└ @ Main C:\Users\Win10\source\repos\julia\idioms\test\switchblas.jl:75
ERROR: UndefKeywordError: keyword argument sysimage_path not assigned

```

Is this borken or am I doing it wrong? Nevermind I’m doing it wrong. Used a newer, unsupported version of the package compiler, it seems.

---

<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:** [November 19, 2021, 5:23pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/7 "2021-11-19T17:23:46Z")

</div>

For Julia 1.7 you don’t have to do anything else than just **restarting** Julia. We even want to add a way to dynamically switch back to OpenBLAS (or back and forth) at some point. However, no one has implemented that yet despite the fact that it should be fairly simple. See [https://github.com/JuliaLinearAlgebra/MKL.jl/issues/90](https://github.com/JuliaLinearAlgebra/MKL.jl/issues/90)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 19, 2021, 5:24pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/8 "2021-11-19T17:24:08Z")

</div>

Just use 1.7 for MKL. It’s just not worth dealing with 1.6 when it comes to this.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [January 5, 2022, 11:58pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/9 "2022-01-05T23:58:57Z")

</div>

The following seems to work, for switching at run-time in Julia 1.7.  
No need to restart.

```julia
julia> using LinearAlgebra

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

julia> LinearAlgebra. __init__ ()

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

julia> MKL. __init__ ()
4770

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

```

Credits to @giordano (though he also warned this might not be proper way to switch).

---

<div class="post-metadata">

**Author:** ![jamblejoe](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jamblejoe](https://discourse.julialang.org/u/jamblejoe)\
**Post date:** [January 13, 2024, 3:12pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/10 "2024-01-13T15:12:56Z")

</div>

What is the “correct” way to switch back to OpenBLAS as of Julia 1.10?

---

<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 14, 2024, 12:19am UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/11 "2024-01-14T00:19:59Z")

</div>

Start a new Julia session, and don’t `using MKL` this time.

Starting in Julia 1.7, switching to MKL doesn’t require anything permanent. Just a `using MLK` (which I have in my `startup.jl`). So to not use it, don’t `using MKL`.

---

<div class="post-metadata">

**Author:** ![jamblejoe](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jamblejoe](https://discourse.julialang.org/u/jamblejoe)\
**Post date:** [January 15, 2024, 12:24pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/12 "2024-01-15T12:24:01Z")

</div>

Thanks for the quick response! Is there an intended way to switch back from MKL (by `using MKL`) to OpenBLAS _without_ restarting the Julia session?

---

<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:** [January 15, 2024, 1:04pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/13 "2024-01-15T13:04:14Z")

</div>

```julia-repl
julia> using OpenBLAS_jll, LinearAlgebra.BLAS

julia> BLAS.lbt_forward(OpenBLAS_jll.libopenblas_path; clear=true)
4860

```

---

<div class="post-metadata">

**Author:** ![jamblejoe](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jamblejoe](https://discourse.julialang.org/u/jamblejoe)\
**Post date:** [January 15, 2024, 4:56pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/14 "2024-01-15T16:56:41Z")

</div>

Perfect, thanks!

---

<div class="post-metadata">

**Author:** ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Post date:** [January 16, 2024, 7:47pm UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/15 "2024-01-16T19:47:27Z")

</div>

How do you apply the same trick for MKL?  
Since after

```julia
BLAS.lbt_forward(OpenBLAS_jll.libopenblas_path; clear=true)
using MKL;

```

Won’t have effect. Is there a way to set MKL as you did with OpenBLAS?

---

<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:** [January 17, 2024, 2:04am UTC](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/16 "2024-01-17T02:04:06Z")

</div>

It won’t have any effect because you had already loaded MKL.jl in the same session, and the ` __init__ ` function is skipped, so the solution is to look at what the init function (which is almost the entirety of the package) would do:

> <https://github.com/JuliaLinearAlgebra/MKL.jl/blob/682a3ad62b50e5183a47716738917bf7d8bc1a17/src/MKL.jl#L40-L85>

(which is pretty much what was suggested in [From MKL back to OpenBLAS - #9 by e3c6](https://discourse.julialang.org/t/from-mkl-back-to-openblas/37722/9))
