Correct way to set MKL threads at runtime

What is the correct way to set MKL threads at runtime? Documentation seems to be misleading, it says to use BLAS.set_num_threads(1) to be single threaded, but it does not work. The only way I have found to actually make it work is calling julia with MKL_NUM_THREADS=1, is there no way to set it at runtime then?

small code used to run
using MKL
using LinearAlgebra
BLAS.set_num_threads(1)
A = rand(5000, 5000)

A .+= A'

eigen(A)

BLAS.set_num_threads(1) works for me.

I thought this worked, but you’re right. As explained in the github issue you’ve also commented on, Setting MKL thread number · Issue #174 · JuliaLinearAlgebra/MKL.jl · GitHub, when using MKL, BLAS.set_num_threads(n) only affects the number of threads used for BLAS functions like A * B, not LAPACK functions like eigen. I don’t think this is the intended semantics, so hopefully someone will follow up on the github issue.

2 Likes

I have re-reported the issue on libblastrampoline make MKL thread setter/getter work for both BLAS and LAPACK · Issue #151 · JuliaLinearAlgebra/libblastrampoline · GitHub since this is where the link to the setter is being performed.

2 Likes

As of now, it just seems like it is not possible since it is not implemented by MKL itself Solved: How to set number of LAPACK threads during runtime? - Intel Community

2 Likes