Skip to content

Commit

Permalink
remove restriction on number of threads
Browse files Browse the repository at this point in the history
Closes #36469
  • Loading branch information
vtjnash committed Jul 23, 2020
1 parent 34b2ae5 commit 149af56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
5 changes: 1 addition & 4 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,16 +406,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
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

0 comments on commit 149af56

Please sign in to comment.