Skip to content

Commit

Permalink
sed -i -e 's/\bnthreadpool\b/threadpoolsize/g' `git grep -l '\bnthrea…
Browse files Browse the repository at this point in the history
…dpool\b' `
  • Loading branch information
vtjnash committed Jul 26, 2022
1 parent 5fb309b commit 7e4006c
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,6 @@ const var"@_noinline_meta" = var"@noinline"

@deprecate splat(x) Splat(x) false

@eval Threads const nthreads = nthreadpool
@eval Threads const nthreads = threadpoolsize

# END 1.9 deprecations
2 changes: 1 addition & 1 deletion base/pcre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function get_local_match_context()
try
ctxs = THREAD_MATCH_CONTEXTS
if length(ctxs) < tid
global THREAD_MATCH_CONTEXTS = ctxs = copyto!(fill(C_NULL, _mth()), ctxs)
global THREAD_MATCH_CONTEXTS = ctxs = copyto!(fill(C_NULL, length(ctxs) + _mth()), ctxs)
end
finally
unlock(l)
Expand Down
2 changes: 1 addition & 1 deletion base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ end

function enq_work(t::Task)
(t._state === task_state_runnable && t.queue === nothing) || error("schedule: Task not runnable")
if t.sticky || Threads.nthreadpool() == 1
if t.sticky || Threads.threadpoolsize() == 1
tid = Threads.threadid(t)
if tid == 0
# Issue #41324
Expand Down
16 changes: 8 additions & 8 deletions base/threadingconstructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ Returns the number of threadpools currently configured.
nthreadpools() = Int(unsafe_load(cglobal(:jl_n_threadpools, Cint)))

"""
Threads.nthreadpool()
Threads.threadpoolsize()
Get the number of threads available to the Julia default worker thread-pool.
See also: `BLAS.get_num_threads` and `BLAS.set_num_threads` in the
[`LinearAlgebra`](@ref man-linalg) standard library, and `nprocs()` in the
[`Distributed`](@ref man-distributed) standard library.
"""
nthreadpool() = Threads._nthreads_in_pool(Int8(0))
#nthreadpool() = max(Int(JLOptions().nthreads), 1)
threadpoolsize() = Threads._nthreads_in_pool(Int8(0))
#threadpoolsize() = max(Int(JLOptions().nthreads), 1)

function threading_run(fun, static)
ccall(:jl_enter_threaded_region, Cvoid, ())
n = nthreadpool()
n = threadpoolsize()
tasks = Vector{Task}(undef, n)
for i = 1:n
t = Task(() -> fun(i)) # pass in tid
Expand Down Expand Up @@ -104,7 +104,7 @@ function _threadsfor(iter, lbody, schedule)
tid = 1
len, rem = lenr, 0
else
len, rem = divrem(lenr, nthreadpool())
len, rem = divrem(lenr, threadpoolsize())
end
# not enough iterations for all the threads?
if len == 0
Expand Down Expand Up @@ -196,7 +196,7 @@ assumption may be removed in the future.
This scheduling option is merely a hint to the underlying execution mechanism. However, a
few properties can be expected. The number of `Task`s used by `:dynamic` scheduler is
bounded by a small constant multiple of the number of available worker threads
([`Threads.nthreadpool()`](@ref)). Each task processes contiguous regions of the
([`Threads.threadpoolsize()`](@ref)). Each task processes contiguous regions of the
iteration space. Thus, `@threads :dynamic for x in xs; f(x); end` is typically more
efficient than `@sync for x in xs; @spawn f(x); end` if `length(xs)` is significantly
larger than the number of the worker threads and the run-time of `f(x)` is relatively
Expand Down Expand Up @@ -233,15 +233,15 @@ julia> function busywait(seconds)
julia> @time begin
Threads.@spawn busywait(5)
Threads.@threads :static for i in 1:Threads.nthreadpool()
Threads.@threads :static for i in 1:Threads.threadpoolsize()
busywait(1)
end
end
6.003001 seconds (16.33 k allocations: 899.255 KiB, 0.25% compilation time)
julia> @time begin
Threads.@spawn busywait(5)
Threads.@threads :dynamic for i in 1:Threads.nthreadpool()
Threads.@threads :dynamic for i in 1:Threads.threadpoolsize()
busywait(1)
end
end
Expand Down
4 changes: 2 additions & 2 deletions base/threads_overloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Threads.foreach(f, channel::Channel;
schedule::Threads.AbstractSchedule=Threads.FairSchedule(),
ntasks=Base.nthreadpool())
ntasks=Base.threadpoolsize())
Similar to `foreach(f, channel)`, but iteration over `channel` and calls to
`f` are split across `ntasks` tasks spawned by `Threads.@spawn`. This function
Expand Down Expand Up @@ -40,7 +40,7 @@ collect(d) = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256
"""
function Threads.foreach(f, channel::Channel;
schedule::Threads.AbstractSchedule=Threads.FairSchedule(),
ntasks=Threads.nthreadpool())
ntasks=Threads.threadpoolsize())
apply = _apply_for_schedule(schedule)
stop = Threads.Atomic{Bool}(false)
@sync for _ in 1:ntasks
Expand Down
2 changes: 1 addition & 1 deletion doc/src/base/multi-threading.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Base.Threads.threadid
Base.Threads.maxthreadid
Base.Threads.threadpool
Base.Threads.nthreadpools
Base.Threads.nthreadpool
Base.Threads.threadpoolsize
```

See also [Multi-Threading](@ref man-multithreading).
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ int main()
jl_eval_string("func(i) = ccall(:c_func, Float64, (Int32,), i)");

// Call func() multiple times, using multiple threads to do so
jl_eval_string("println(Base.nthreadpool())");
jl_eval_string("println(Base.threadpoolsize())");
jl_eval_string("use(i) = println(\"[J $(Threads.threadid())] i = $(i) -> $(func(i))\")");
jl_eval_string("Threads.@threads for i in 1:5 use(i) end");

Expand Down
8 changes: 4 additions & 4 deletions doc/src/manual/multi-threading.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ of Julia multi-threading features.
## Starting Julia with multiple threads

By default, Julia starts up with a single thread of execution. This can be verified by using the
command [`Threads.nthreadpool()`](@ref):
command [`Threads.threadpoolsize()`](@ref):

```jldoctest
julia> Threads.nthreadpool()
julia> Threads.threadpoolsize()
1
```

Expand Down Expand Up @@ -38,7 +38,7 @@ $ julia --threads 4
Let's verify there are 4 threads at our disposal.

```julia-repl
julia> Threads.nthreadpool()
julia> Threads.threadpoolsize()
4
```

Expand Down Expand Up @@ -267,7 +267,7 @@ avoid the race:
```julia-repl
julia> using Base.Threads
julia> Threads.nthreadpool()
julia> Threads.threadpoolsize()
4
julia> acc = Ref(0)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ function versioninfo(io::IO=stdout)
println(io, indent, "--> ", lib.libname, " (", interface, ")")
end
println(io, "Threading:")
println(io, indent, "Threads.nthreadpool() = ", Threads.nthreadpool())
println(io, indent, "Threads.threadpoolsize() = ", Threads.threadpoolsize())
println(io, indent, "Threads.maxthreadid() = ", Base.Threads.maxthreadid())
println(io, indent, "LinearAlgebra.BLAS.get_num_threads() = ", BLAS.get_num_threads())
println(io, "Relevant environment variables:")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ function getdict!(dict::LineInfoDict, data::Vector{UInt})
n_unique_ips = length(unique_ips)
n_unique_ips == 0 && return dict
iplookups = similar(unique_ips, Vector{StackFrame})
@sync for indexes_part in Iterators.partition(eachindex(unique_ips), div(n_unique_ips, Threads.nthreadpool(), RoundUp))
@sync for indexes_part in Iterators.partition(eachindex(unique_ips), div(n_unique_ips, Threads.threadpoolsize(), RoundUp))
Threads.@spawn begin
for i in indexes_part
iplookups[i] = _lookup_corrected(unique_ips[i])
Expand Down
4 changes: 2 additions & 2 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
@test errors_not_signals(`$exename --cpu-target=invalidtarget`)

# -t, --threads
code = "print(Threads.nthreadpool())"
code = "print(Threads.threadpoolsize())"
cpu_threads = ccall(:jl_effective_threads, Int32, ())
@test string(cpu_threads) ==
read(`$exename --threads auto -e $code`, String) ==
Expand Down Expand Up @@ -256,7 +256,7 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`

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

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ cd(@__DIR__) do
println("""
Running parallel tests with:
nworkers() = $(nworkers())
nthreads() = $(Threads.nthreadpool())
nthreads() = $(Threads.threadpoolsize())
Sys.CPU_THREADS = $(Sys.CPU_THREADS)
Sys.total_memory() = $(Base.format_bytes(Sys.total_memory()))
Sys.free_memory() = $(Base.format_bytes(Sys.free_memory()))
Expand Down
2 changes: 1 addition & 1 deletion test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ end

function get_nthreads(options = ``; cpus = nothing)
cmd = `$(Base.julia_cmd()) --startup-file=no $(options)`
cmd = `$cmd -e "print(Threads.nthreadpool())"`
cmd = `$cmd -e "print(Threads.threadpoolsize())"`
cmd = addenv(cmd, "JULIA_EXCLUSIVE" => "0", "JULIA_NUM_THREADS" => "auto")
if cpus !== nothing
cmd = setcpuaffinity(cmd, cpus)
Expand Down
Loading

0 comments on commit 7e4006c

Please sign in to comment.