Skip to content

Commit 001f3dc

Browse files
committed
Add test for default number of BLAS threads
1 parent 2e5e0ac commit 001f3dc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/threads.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,22 @@ end
366366
@test jl_setaffinity(0, mask, cpumasksize) == 0
367367
end
368368
end
369+
370+
# Make sure default number of BLAS threads respects CPU affinity: issue #55572
371+
@testset "LinearAlgebra number of default threads" begin
372+
if AFFINITY_SUPPORTED
373+
allowed_cpus = findall(uv_thread_getaffinity())
374+
cmd = addenv(`$(Base.julia_cmd()) --startup-file=no -E 'using LinearAlgebra; BLAS.get_num_threads()'`,
375+
# Remove all variables which could affect the default number of threads
376+
"OPENBLAS_NUM_THREADS"=>nothing,
377+
"GOTO_NUM_THREADS"=>nothing,
378+
"OMP_NUM_THREADS"=>nothing)
379+
function test_num_threads(n)
380+
expected_num_threads = @static Sys.isapple() && Base.BinaryPlatforms.arch(Base.BinaryPlatforms.HostPlatform()) == "aarch64" ? string(max(1, n)) : string(max(1, n ÷ 2))
381+
@test readchomp(setcpuaffinity(cmd, allowed_cpus[1:n])) == "1"
382+
end
383+
for n in 1:length(allowed_cpus)
384+
test_num_threads(n)
385+
end
386+
end
387+
end

0 commit comments

Comments
 (0)