Skip to content

Commit

Permalink
Rename Sys.CPU_CORES => Sys.CPU_THREADS
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm authored and StefanKarpinski committed Jul 12, 2018
1 parent b0f531e commit 9050651
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- image: circleci/python:2.7
environment:
ARCH: i686
JULIA_CPU_CORES: 4
JULIA_CPU_THREADS: 4
JULIA_TEST_MAXRSS_MB: 800
steps: &steps
- run: | # install build dependencies
Expand Down Expand Up @@ -81,6 +81,6 @@ jobs:
- image: circleci/python:2.7
environment:
ARCH: x86_64
JULIA_CPU_CORES: 4
JULIA_CPU_THREADS: 4
JULIA_TEST_MAXRSS_MB: 800
steps: *steps
2 changes: 1 addition & 1 deletion .freebsdci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ runtests(){
export FORCE_ASSERTIONS=1
export LLVM_ASSERTIONS=1
export JULIA_TEST_MAXRSS_MB=600
export JULIA_CPU_CORES=$MAKE_JOBS_NUMBER
export JULIA_CPU_THREADS=$MAKE_JOBS_NUMBER

./usr/bin/julia --check-bounds=yes test/runtests.jl all
./usr/bin/julia --check-bounds=yes test/runtests.jl \
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ before_install:
BUILDOPTS="-j5 VERBOSE=1 FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1 USECCACHE=1";
echo "override ARCH=$ARCH" >> Make.user;
sudo sh -c "echo 0 > /proc/sys/net/ipv6/conf/lo/disable_ipv6";
export JULIA_CPU_CORES=4;
export JULIA_CPU_THREADS=4;
export JULIA_TEST_MAXRSS_MB=1200;
TESTSTORUN="all";
elif [ `uname` = "Darwin" ]; then
Expand All @@ -90,7 +90,7 @@ before_install:
export JULIA_MACOS_SPAWN="DYLD_FALLBACK_LIBRARY_PATH=\"$spawn_DYLD_FALLBACK_LIBRARY_PATH\" \$1";
export BUILDOPTS="$BUILDOPTS spawn=\$(JULIA_MACOS_SPAWN)";
make $BUILDOPTS -C contrib -f repackage_system_suitesparse4.make;
export JULIA_CPU_CORES=2;
export JULIA_CPU_THREADS=2;
export JULIA_TEST_MAXRSS_MB=600;
TESTSTORUN="all --skip linalg/triangular subarray"; fi # TODO: re enable these if possible without timing out
- echo "override JULIA_CPU_TARGET=generic;native" >> Make.user
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ testall: check-whitespace $(JULIA_BUILD_MODE)
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/test all JULIA_BUILD_MODE=$(JULIA_BUILD_MODE)

testall1: check-whitespace $(JULIA_BUILD_MODE)
@env JULIA_CPU_CORES=1 $(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/test all JULIA_BUILD_MODE=$(JULIA_BUILD_MODE)
@env JULIA_CPU_THREADS=1 $(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/test all JULIA_BUILD_MODE=$(JULIA_BUILD_MODE)

test-%: check-whitespace $(JULIA_BUILD_MODE)
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/test $* JULIA_BUILD_MODE=$(JULIA_BUILD_MODE)
Expand Down
6 changes: 3 additions & 3 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,12 @@ function __init__()
end
# And try to prevent openblas from starting too many threads, unless/until specifically requested
if !haskey(ENV, "OPENBLAS_NUM_THREADS") && !haskey(ENV, "OMP_NUM_THREADS")
cpu_cores = Sys.CPU_CORES::Int
cpu_cores = Sys.CPU_THREADS::Int
if cpu_cores > 8 # always at most 8
ENV["OPENBLAS_NUM_THREADS"] = "8"
elseif haskey(ENV, "JULIA_CPU_CORES") # or exactly as specified
elseif haskey(ENV, "JULIA_CPU_THREADS") # or exactly as specified
ENV["OPENBLAS_NUM_THREADS"] = cpu_cores
end # otherwise, trust that openblas will pick CPU_CORES anyways, without any intervention
end # otherwise, trust that openblas will pick CPU_THREADS anyways, without any intervention
end
# for the few uses of Libc.rand in Base:
Libc.srand()
Expand Down
16 changes: 8 additions & 8 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Provide methods for retrieving information about hardware and the operating syst

export BINDIR,
STDLIB,
CPU_CORES,
CPU_THREADS,
CPU_NAME,
WORD_SIZE,
ARCH,
Expand Down Expand Up @@ -47,15 +47,15 @@ STDLIB = "$BINDIR/../share/julia/stdlib/v$(VERSION.major).$(VERSION.minor)" # fo

# helper to avoid triggering precompile warnings

global CPU_CORES
global CPU_THREADS
"""
Sys.CPU_CORES
Sys.CPU_THREADS
The number of logical CPU cores available in the system.
See the Hwloc.jl package for extended information, including number of physical cores.
See Hwloc.jl or CpuId.jl for extended information, including number of physical cores.
"""
:CPU_CORES
:CPU_THREADS

"""
Sys.ARCH
Expand Down Expand Up @@ -87,11 +87,11 @@ Standard word size on the current machine, in bits.
const WORD_SIZE = Core.sizeof(Int) * 8

function __init__()
env_cores = get(ENV, "JULIA_CPU_CORES", "")
global CPU_CORES = if !isempty(env_cores)
env_cores = get(ENV, "JULIA_CPU_THREADS", "")
global CPU_THREADS = if !isempty(env_cores)
env_cores = tryparse(Int, env_cores)
if !(env_cores isa Int && env_cores > 0)
Core.print(Core.stderr, "WARNING: couldn't parse `JULIA_CPU_CORES` environment variable. Defaulting Sys.CPU_CORES to 1.\n")
Core.print(Core.stderr, "WARNING: couldn't parse `JULIA_CPU_THREADS` environment variable. Defaulting Sys.CPU_THREADS to 1.\n")
env_cores = 1
end
env_cores
Expand Down
6 changes: 3 additions & 3 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ kwdef_val(::Type{T}) where {T} = T()
# testing

"""
Base.runtests(tests=["all"]; ncores=ceil(Int, Sys.CPU_CORES / 2),
Base.runtests(tests=["all"]; ncores=ceil(Int, Sys.CPU_THREADS / 2),
exit_on_error=false, [seed])
Run the Julia unit tests listed in `tests`, which can be either a string or an array of
Expand All @@ -731,7 +731,7 @@ when `exit_on_error == true`.
If a seed is provided via the keyword argument, it is used to seed the
global RNG in the context where the tests are run; otherwise the seed is chosen randomly.
"""
function runtests(tests = ["all"]; ncores = ceil(Int, Sys.CPU_CORES / 2),
function runtests(tests = ["all"]; ncores = ceil(Int, Sys.CPU_THREADS / 2),
exit_on_error=false,
seed::Union{BitInteger,Nothing}=nothing)
if isa(tests,AbstractString)
Expand All @@ -740,7 +740,7 @@ function runtests(tests = ["all"]; ncores = ceil(Int, Sys.CPU_CORES / 2),
exit_on_error && push!(tests, "--exit-on-error")
seed != nothing && push!(tests, "--seed=0x$(string(seed % UInt128, base=16))") # cast to UInt128 to avoid a minus sign
ENV2 = copy(ENV)
ENV2["JULIA_CPU_CORES"] = "$ncores"
ENV2["JULIA_CPU_THREADS"] = "$ncores"
try
run(setenv(`$(julia_cmd()) $(joinpath(Sys.BINDIR::String,
Base.DATAROOTDIR, "julia", "test", "runtests.jl")) $tests`, ENV2))
Expand Down
2 changes: 1 addition & 1 deletion doc/src/base/constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Base.C_NULL
Base.VERSION
Base.LOAD_PATH
Base.Sys.BINDIR
Base.Sys.CPU_CORES
Base.Sys.CPU_THREADS
Base.Sys.WORD_SIZE
Base.Sys.KERNEL
Base.Sys.ARCH
Expand Down
4 changes: 2 additions & 2 deletions doc/src/manual/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ exists, or `emacs` otherwise.

## Parallelization

### `JULIA_CPU_CORES`
### `JULIA_CPU_THREADS`

Overrides the global variable [`Base.Sys.CPU_CORES`](@ref), the number of
Overrides the global variable [`Base.Sys.CPU_THREADS`](@ref), the number of
logical CPU cores available.

### `JULIA_WORKER_TIMEOUT`
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Distributed/src/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ end
"""
addprocs(; kwargs...) -> List of process identifiers
Equivalent to `addprocs(Sys.CPU_CORES; kwargs...)`
Equivalent to `addprocs(Sys.CPU_THREADS; kwargs...)`
Note that workers do not run a `.julia/config/startup.jl` startup script, nor do they synchronize
their global state (such as global variables, new method definitions, and loaded modules) with any
of the other running processes.
"""
addprocs(; kwargs...) = addprocs(Sys.CPU_CORES; kwargs...)
addprocs(; kwargs...) = addprocs(Sys.CPU_THREADS; kwargs...)

"""
addprocs(np::Integer; restrict=true, kwargs...) -> List of process identifiers
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/process_messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function handle_msg(msg::JoinPGRPMsg, header, r_stream, w_stream, version)
for wt in wait_tasks; Base._wait(wt); end

send_connection_hdr(controller, false)
send_msg_now(controller, MsgHeader(RRID(0,0), header.notify_oid), JoinCompleteMsg(Sys.CPU_CORES, getpid()))
send_msg_now(controller, MsgHeader(RRID(0,0), header.notify_oid), JoinCompleteMsg(Sys.CPU_THREADS, getpid()))
end

function connect_to_peer(manager::ClusterManager, rpid::Int, wconfig::WorkerConfig)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ if Sys.isunix() # aka have ssh

print("\nMixed ssh addprocs with :auto\n")
new_pids = addprocs_with_testenv(["localhost", ("127.0.0.1", :auto), "localhost"]; sshflags=sshflags)
@test length(new_pids) == (2 + Sys.CPU_CORES)
@test length(new_pids) == (2 + Sys.CPU_THREADS)
test_n_remove_pids(new_pids)

print("\nMixed ssh addprocs with numeric counts\n")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/InteractiveUtils/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ end
@test !occursin("Environment:", read(setenv(`$exename -e 'using InteractiveUtils; versioninfo()'`,
String[]), String))
@test occursin("Environment:", read(setenv(`$exename -e 'using InteractiveUtils; versioninfo()'`,
String["JULIA_CPU_CORES=1"]), String))
String["JULIA_CPU_THREADS=1"]), String))
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ let exename = `$(Base.julia_cmd()) --sysimage-native-code=yes --startup-file=no`
@test startswith(v[3], "┌ Warning: Failed to insert InteractiveUtils into module Main\n")
end
for nc in ("0", "-2", "x", "2x", " ")
v = readchomperrors(setenv(`$exename -i -E 'Sys.CPU_CORES'`, "JULIA_CPU_CORES" => nc))
v = readchomperrors(setenv(`$exename -i -E 'Sys.CPU_THREADS'`, "JULIA_CPU_THREADS" => nc))
@test v[1]
@test v[2] == "1"
@test v[3] == "WARNING: couldn't parse `JULIA_CPU_CORES` environment variable. Defaulting Sys.CPU_CORES to 1."
@test v[3] == "WARNING: couldn't parse `JULIA_CPU_THREADS` environment variable. Defaulting Sys.CPU_THREADS to 1."
end
real_cores = string(ccall(:jl_cpu_cores, Int32, ()))
for nc in ("1", " 1 ", " +1 ", " 0x1 ", "")
v = readchomperrors(setenv(`$exename -i -E 'Sys.CPU_CORES'`, "JULIA_CPU_CORES" => nc))
v = readchomperrors(setenv(`$exename -i -E 'Sys.CPU_THREADS'`, "JULIA_CPU_THREADS" => nc))
@test v[1]
@test v[2] == (isempty(nc) ? real_cores : "1")
@test isempty(v[3])
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import LinearAlgebra
cd(dirname(@__FILE__)) do
n = 1
if net_on
n = min(Sys.CPU_CORES, length(tests))
n = min(Sys.CPU_THREADS, length(tests))
n > 1 && addprocs_with_testenv(n)
LinearAlgebra.BLAS.set_num_threads(1)
end
Expand Down

0 comments on commit 9050651

Please sign in to comment.