JuliaLang / JuliaLang/LinearAlgebra.jl
BLAS threads should default to physical not logical core count?
- Dominant language
- Julia
- Stars
- 77
- Forks
- 65
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 10
Description
On an i7-8550u, OpenBLAS is defaulting to 8 threads. I was comparing to RecursiveFactorizations.jl, and saw the performance is like:
```julia
using BenchmarkTools
import LinearAlgebra, RecursiveFactorization
ccall((:openblas_get_num_threads64_, Base.libblas_name), Cint, ())
LinearAlgebra.BLAS.set_num_threads(4)
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 0.5
luflop(m, n) = n^3÷3 - n÷3 + m*n^2
luflop(n) = luflop(n, n)
bas_mflops = Float64[]
rec_mflops = Float64[]
ns = 50:50:800
for n in ns
A = rand(n, n)
bt = @belapsed LinearAlgebra.lu!($(copy(A)))
rt = @belapsed RecursiveFactorization.lu!($(copy(A)))
push!(bas_mflops, luflop(n)/bt/1e9)
push!(rec_mflops, luflop(n)/rt/1e9)
end
using Plots
plt = plot(ns, bas_mflops, legend=:bottomright, lab="OpenBLAS", title="LU Factorization Benchmark", marker=:auto)
plot!(plt, ns, rec_mflops, lab="RecursiveFactorization", marker=:auto)
xaxis!(plt, "size (N x N)")
yaxis!(plt, "GFLOPS")
```
1 thread

4 threads

8 threads

Conclusion: the default that Julia chooses, 8 threads, is the worst, with 1 thread doing better. But using the number of physical cores, 4, is best.
So there were a lot of issues on Discourse and Slack #gripes where essentially "setting BLAS threads to 1 is better than the default!", but it looks like it's because the default should be the number of physical and not logical threads. I am actually very surprised it's not set that way, and so I was wondering why, and also where this default is set (I couldn't find it).
Contributor guide
No contributing guide indexed for this repository
Research direction
No file or entry point is named; start by tracing where LinearAlgebra selects the OpenBLAS thread default. Reproduce the supplied BenchmarkTools LU comparison at 1, 4, and 8 threads, then determine whether physical-core selection should become the default and how the behavior should be validated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100