Skip to content

Commit

Permalink
Add test for default number of BLAS threads
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Aug 23, 2024
1 parent 2e5e0ac commit 854362f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,19 @@ end
@test jl_setaffinity(0, mask, cpumasksize) == 0
end
end

# Make sure default number of BLAS threads respects CPU affinity: issue #55572
@testset "LinearAlgebra number of default threads" begin
if AFFINITY_SUPPORTED
allowed_cpus = findall(uv_thread_getaffinity())
cmd = addenv(`$(Base.julia_cmd()) --startup-file=no -E 'using LinearAlgebra; BLAS.get_num_threads()'`,
# Remove all variables which could affect the default number of threads
"OPENBLAS_NUM_THREADS"=>nothing,
"GOTO_NUM_THREADS"=>nothing,
"OMP_NUM_THREADS"=>nothing)
for n in 1:length(allowed_cpus)
expected_num_threads = @static Sys.isapple() && Base.BinaryPlatforms.arch(Base.BinaryPlatforms.HostPlatform()) == "aarch64" ? string(max(1, n)) : string(max(1, n ÷ 2))
@test readchomp(setcpuaffinity(cmd, allowed_cpus[1:n])) == expected_num_threads
end
end
end

0 comments on commit 854362f

Please sign in to comment.