Skip to content

Restoring get_num_threads function of BLAS #21105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Restoring get_num_threads function of BLAS #21105

wants to merge 2 commits into from

Conversation

usefulhyun
Copy link
Contributor

BLAS.get_num_threads function have been deleted by this commit 1da2c9b.

But, I can not find why, I think, I and other people also need this function by #15008.
And It already implemented by @tkelman before.

@tkelman tkelman added the needs tests Unit tests are required for this change label Mar 20, 2017
@martinholters
Copy link
Member

Note this:

julia/test/distributed_exec.jl

Lines 1172 to 1191 in e05a921

const get_num_threads = function() # anonymous so it will be serialized when called
blas = BLAS.vendor()
# Wrap in a try to catch unsupported blas versions
try
if blas == :openblas
return ccall((:openblas_get_num_threads, Base.libblas_name), Cint, ())
elseif blas == :openblas64
return ccall((:openblas_get_num_threads64_, Base.libblas_name), Cint, ())
elseif blas == :mkl
return ccall((:MKL_Get_Max_Num_Threads, Base.libblas_name), Cint, ())
end
# OSX BLAS looks at an environment variable
if is_apple()
return ENV["VECLIB_MAXIMUM_THREADS"]
end
end
return nothing
end

Wrapping in a try to catch unsupported blas versions
@tkelman
Copy link
Contributor

tkelman commented Mar 20, 2017

IIRC the issue with this in openblas is that it returns the build time hard coded max number of threads, which is much less useful or expected than the run time dynamic number of threads setting.

@usefulhyun
Copy link
Contributor Author

@tkelman , because in some case it returns the hard coded max number of threads, it have been deleted, is this right? Can I know anther option to replace this function?

@tkelman
Copy link
Contributor

tkelman commented Mar 20, 2017

It would probably be more useful to look at the same environment variables that blas implentations do

@usefulhyun usefulhyun closed this Mar 21, 2017
@antoine-levitt
Copy link
Contributor

@tkelman IIRC the issue with this in openblas is that it returns the build time hard coded max number of threads, which is much less useful or expected than the run time dynamic number of threads setting.

Has this not been fixed by OpenMathLib/OpenBLAS#762? At least here (0.6 and 0.7, linux openblas) it seems to work as expected. This PR should be re-opened as it seems like a useful functionality to have (if only for symmetry wrt set_num_threads)

@Jutho
Copy link
Contributor

Jutho commented Jun 3, 2020

I am also in favour of reopening this. I think the MKL call needs to be
mkl_get_max_threads instead of MKL_Get_Max_Num_Threads.

One important use case I see, as multithreading in Julia is now more easy to use with @spawn, is that a package developer writes some code that implements an algorithm that uses multithreading at a higher level, and want to use single threaded matrix multiplication in the specific block of code ran on the different threads. So (s)he could do BLAS.set_num_threads(1) before the block of his own multithreaded code starts, but to restore BLAS.set_num_threads(originalvalue), (s)he needs to be able to find out what the originalvalue of number of BLAS threads is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests Unit tests are required for this change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants