Skip to content

Commit 34ed890

Browse files
committed
Add test for default number of BLAS threads
1 parent b03e17a commit 34ed890

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/threads.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,19 @@ end
359359
@test jl_setaffinity(0, mask, cpumasksize) == 0
360360
end
361361
end
362+
363+
# Make sure default number of BLAS threads respects CPU affinity: issue #55572.
364+
# Note: we're doing this only on Linux.
365+
@testset "LinearAlgebra number of default threads" begin
366+
if AFFINITY_SUPPORTED
367+
allowed_cpus = findall(uv_thread_getaffinity())
368+
cmd = addenv(`$(Base.julia_cmd()) --startup-file=no -E 'using LinearAlgebra; BLAS.get_num_threads()'`,
369+
# Remove all variables which could affect the default number of threads
370+
"OPENBLAS_NUM_THREADS"=>nothing,
371+
"GOTO_NUM_THREADS"=>nothing,
372+
"OMP_NUM_THREADS"=>nothing)
373+
for n in 1:min(length(allowed_cpus), 8) # Cap to 8 to avoid too many tests on large systems
374+
@test readchomp(setcpuaffinity(cmd, allowed_cpus[1:n])) == string(max(1, n ÷ 2))
375+
end
376+
end
377+
end

0 commit comments

Comments
 (0)