Skip to content

Commit

Permalink
remove restriction on number of threads running (#36778)
Browse files Browse the repository at this point in the history
Closes #36469
  • Loading branch information
vtjnash committed Aug 24, 2020
1 parent 7695e37 commit 5ef6d0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,13 @@ void jl_init_threading(void)
#endif

// how many threads available, usable
int max_threads = jl_cpu_threads();
jl_n_threads = JULIA_NUM_THREADS;
if (jl_options.nthreads < 0) // --threads=auto
jl_n_threads = max_threads;
jl_n_threads = jl_cpu_threads();
else if (jl_options.nthreads > 0) // --threads=N
jl_n_threads = jl_options.nthreads;
else if ((cp = getenv(NUM_THREADS_NAME)))
jl_n_threads = (uint64_t)strtol(cp, NULL, 10);
if (jl_n_threads > max_threads)
jl_n_threads = max_threads;
if (jl_n_threads <= 0)
jl_n_threads = 1;
#ifndef __clang_analyzer__
Expand Down Expand Up @@ -451,6 +448,10 @@ void jl_start_threads(void)
// according to a 'compact' policy
// non-exclusive: no affinity settings; let the kernel move threads about
if (exclusive) {
if (jl_n_threads > jl_cpu_threads()) {
jl_n_threads = 1;
jl_error("Too many threads running for " MACHINE_EXCLUSIVE_NAME " option.");
}
memset(mask, 0, cpumasksize);
mask[0] = 1;
uvtid = (uv_thread_t)uv_thread_self();
Expand Down
26 changes: 14 additions & 12 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,29 +190,31 @@ let exename = `$(Base.julia_cmd()) --startup-file=no`

# -t, --threads
code = "print(Threads.nthreads())"
cpu_threads = ccall(:jl_cpu_threads, Int32, ())
@test string(cpu_threads) ==
cpu_threads = string(ccall(:jl_cpu_threads, Int32, ()))
@test cpu_threads ==
read(`$exename --threads auto -e $code`, String) ==
read(`$exename --threads=auto -e $code`, String) ==
read(`$exename -tauto -e $code`, String) ==
read(`$exename -t auto -e $code`, String) ==
read(`$exename -t $(cpu_threads+1) -e $code`, String)
if cpu_threads > 1
for nt in (nothing, "1"); withenv("JULIA_NUM_THREADS"=>nt) do
@test read(`$exename --threads 2 -e $code`, String) ==
read(`$exename --threads=2 -e $code`, String) ==
read(`$exename -t2 -e $code`, String) ==
read(`$exename -t auto -e $code`, String)
for nt in (nothing, "1")
withenv("JULIA_NUM_THREADS" => nt) do
@test read(`$exename --threads=2 -e $code`, String) ==
read(`$exename -t 2 -e $code`, String) == "2"
end end
end
end
cpu_threads *= "0"
@test read(`$exename -t $cpu_threads -e $code`, String) == cpu_threads
withenv("JULIA_NUM_THREADS" => cpu_threads) do
@test read(`$exename -e $code`, String) == cpu_threads
end
@test !success(`$exename -t 0`)
@test !success(`$exename -t -1`)

# Combining --threads and --procs: --threads does propagate
if cpu_threads > 1; withenv("JULIA_NUM_THREADS"=>nothing) do
withenv("JULIA_NUM_THREADS" => nothing) do
code = "print(sum(remotecall_fetch(Threads.nthreads, x) for x in procs()))"
@test read(`$exename -p2 -t2 -e $code`, String) == "6"
end end
end

# --procs
@test readchomp(`$exename -q -p 2 -e "println(nworkers())"`) == "2"
Expand Down

2 comments on commit 5ef6d0f

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something went wrong when running your job:

NanosoldierError: failed to run benchmarks against primary commit: failed process: Process(`make -j3 USECCACHE=1 USE_BINARYBUILDER_LLVM=0`, ProcessExited(2)) [2]

Logs and partial data can be found here
cc @ararslan

Please sign in to comment.