Skip to content

Commit

Permalink
Call uv_thread_getaffinity only if AFFINITY_SUPPORTED
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored Mar 20, 2022
1 parent c430269 commit 3b666df
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,21 @@ function get_nthreads(options = ``; cpus = nothing)
end

@testset "nthreads determined based on CPU affinity" begin
allowed_cpus = findall(uv_thread_getaffinity())
if AFFINITY_SUPPORTED && length(allowed_cpus) 2
@test get_nthreads() 2
@test get_nthreads(cpus = allowed_cpus[1:1]) == 1
@test get_nthreads(cpus = allowed_cpus[2:2]) == 1
@test get_nthreads(cpus = allowed_cpus[1:2]) == 2
@test get_nthreads(`-t1`, cpus = allowed_cpus[1:1]) == 1
@test get_nthreads(`-t1`, cpus = allowed_cpus[2:2]) == 1
@test get_nthreads(`-t1`, cpus = allowed_cpus[1:2]) == 1
if AFFINITY_SUPPORTED
allowed_cpus = findall(uv_thread_getaffinity())
if length(allowed_cpus) 2
@test get_nthreads() 2
@test get_nthreads(cpus = allowed_cpus[1:1]) == 1
@test get_nthreads(cpus = allowed_cpus[2:2]) == 1
@test get_nthreads(cpus = allowed_cpus[1:2]) == 2
@test get_nthreads(`-t1`, cpus = allowed_cpus[1:1]) == 1
@test get_nthreads(`-t1`, cpus = allowed_cpus[2:2]) == 1
@test get_nthreads(`-t1`, cpus = allowed_cpus[1:2]) == 1

if length(allowed_cpus) 3
@test get_nthreads(cpus = allowed_cpus[1:2:3]) == 2
@test get_nthreads(cpus = allowed_cpus[2:3]) == 2
end
if length(allowed_cpus) 3
@test get_nthreads(cpus = allowed_cpus[1:2:3]) == 2
@test get_nthreads(cpus = allowed_cpus[2:3]) == 2
end
end
end

Expand Down

0 comments on commit 3b666df

Please sign in to comment.