Skip to content

Commit

Permalink
cores => threads: more thorough replacement where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Jul 12, 2018
1 parent 9050651 commit c8bf20b
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ MinGW-w64 compilers available through Cygwin's package manager.

3. Start the build
```sh
make -j 4 # Adjust the number of cores (4) to match your build environment.
make -j 4 # Adjust the number of threads (4) to match your build environment.
```


Expand Down
6 changes: 3 additions & 3 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,11 @@ 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_THREADS::Int
if cpu_cores > 8 # always at most 8
cpu_threads = Sys.CPU_THREADS::Int
if cpu_threads > 8 # always at most 8
ENV["OPENBLAS_NUM_THREADS"] = "8"
elseif haskey(ENV, "JULIA_CPU_THREADS") # or exactly as specified
ENV["OPENBLAS_NUM_THREADS"] = cpu_cores
ENV["OPENBLAS_NUM_THREADS"] = cpu_threads
end # otherwise, trust that openblas will pick CPU_THREADS anyways, without any intervention
end
# for the few uses of Libc.rand in Base:
Expand Down
14 changes: 7 additions & 7 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ Standard word size on the current machine, in bits.
const WORD_SIZE = Core.sizeof(Int) * 8

function __init__()
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)
env_threads = get(ENV, "JULIA_CPU_THREADS", "")
global CPU_THREADS = if !isempty(env_threads)
env_threads = tryparse(Int, env_threads)
if !(env_threads isa Int && env_threads > 0)
Core.print(Core.stderr, "WARNING: couldn't parse `JULIA_CPU_THREADS` environment variable. Defaulting Sys.CPU_THREADS to 1.\n")
env_cores = 1
env_threads = 1
end
env_cores
env_threads
else
Int(ccall(:jl_cpu_cores, Int32, ()))
Int(ccall(:jl_cpu_threads, Int32, ()))
end
global SC_CLK_TCK = ccall(:jl_SC_CLK_TCK, Clong, ())
global CPU_NAME = ccall(:jl_get_cpu_name, Ref{String}, ())
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ julia [switches] -- [programfile] [args...]
|`-e`, `--eval <expr>` |Evaluate `<expr>`|
|`-E`, `--print <expr>` |Evaluate `<expr>` and display the result|
|`-L`, `--load <file>` |Load `<file>` immediately on all processors|
|`-p`, `--procs {N\|auto`} |Integer value N launches N additional local worker processes; `auto` launches as many workers as the number of local cores|
|`-p`, `--procs {N\|auto`} |Integer value N launches N additional local worker processes; `auto` launches as many workers as the number of local CPU threads (logical cores)|
|`--machine-file <file>` |Run processes on hosts listed in `<file>`|
|`-i` |Interactive mode; REPL runs and `isinteractive()` is true|
|`-q`, `--quiet` |Quiet startup: no banner, suppress REPL warnings|
Expand Down
4 changes: 2 additions & 2 deletions doc/src/manual/parallel-computing.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ to as "workers". When there is only one process, process 1 is considered a worke
workers are considered to be all processes other than process 1.

Let's try this out. Starting with `julia -p n` provides `n` worker processes on the local machine.
Generally it makes sense for `n` to equal the number of CPU cores on the machine. Note that the `-p`
Generally it makes sense for `n` to equal the number of CPU threads (logical cores) on the machine. Note that the `-p`
argument implicitly loads module `Distributed`.


Expand Down Expand Up @@ -1200,7 +1200,7 @@ would typically specify only `io` or `host` / `port`:
workers.

* `count` with an integer value `n` will launch a total of `n` workers.
* `count` with a value of `:auto` will launch as many workers as the number of cores on that machine.
* `count` with a value of `:auto` will launch as many workers as the number of CPU threads (logical cores) on that machine.
* `exename` is the name of the `julia` executable including the full path.
* `exeflags` should be set to the required command line arguments for new workers.
* `tunnel`, `bind_addr`, `sshflags` and `max_parallel` are used when a ssh tunnel is required to
Expand Down
2 changes: 1 addition & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2718,7 +2718,7 @@ void jl_gc_init(void)

#ifdef _P64
// on a big memory machine, set max_collect_interval to totalmem * nthreads / ncores / 2
size_t maxmem = (uv_get_total_memory() * jl_n_threads) / jl_cpu_cores() / 2;
size_t maxmem = (uv_get_total_memory() * jl_n_threads) / jl_cpu_threads() / 2;
if (maxmem > max_collect_interval)
max_collect_interval = maxmem;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ void _julia_init(JL_IMAGE_SEARCH rel)


#if defined(__linux__)
int ncores = jl_cpu_cores();
int ncores = jl_cpu_threads();
if (ncores > 1) {
cpu_set_t cpumask;
CPU_ZERO(&cpumask);
Expand Down
4 changes: 2 additions & 2 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static const char opts[] =

// parallel options
" -p, --procs {N|auto} Integer value N launches N additional local worker processes\n"
" \"auto\" launches as many workers as the number of local cores\n"
" \"auto\" launches as many workers as the number of local CPU threads (logical cores)\n"
" --machine-file <file> Run processes on hosts listed in <file>\n\n"

// interactive options
Expand Down Expand Up @@ -385,7 +385,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
case 'p': // procs
errno = 0;
if (!strcmp(optarg,"auto")) {
jl_options.nprocs = jl_cpu_cores();
jl_options.nprocs = jl_cpu_threads();
}
else {
long nprocs = strtol(optarg, &endptr, 10);
Expand Down
2 changes: 1 addition & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ JL_DLLEXPORT jl_value_t *jl_eqtable_get(jl_array_t *h, void *key,
JL_DLLEXPORT int jl_errno(void);
JL_DLLEXPORT void jl_set_errno(int e);
JL_DLLEXPORT int32_t jl_stat(const char *path, char *statbuf);
JL_DLLEXPORT int jl_cpu_cores(void);
JL_DLLEXPORT int jl_cpu_threads(void);
JL_DLLEXPORT long jl_getpagesize(void);
JL_DLLEXPORT long jl_getallocationgranularity(void);
JL_DLLEXPORT int jl_is_debugbuild(void);
Expand Down
4 changes: 2 additions & 2 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ JL_DLLEXPORT uint64_t jl_ios_get_nbyte_int(ios_t *s, const size_t n)
JL_DLLEXPORT int jl_errno(void) { return errno; }
JL_DLLEXPORT void jl_set_errno(int e) { errno = e; }

// -- get the number of CPU cores --
// -- get the number of CPU threads (logical cores) --

#ifdef _OS_WINDOWS_
typedef DWORD (WINAPI *GAPC)(WORD);
Expand All @@ -362,7 +362,7 @@ typedef DWORD (WINAPI *GAPC)(WORD);
#endif
#endif

JL_DLLEXPORT int jl_cpu_cores(void)
JL_DLLEXPORT int jl_cpu_threads(void)
{
#if defined(HW_AVAILCPU) && defined(HW_NCPU)
size_t len = 4;
Expand Down
2 changes: 1 addition & 1 deletion src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ void jl_init_threading(void)
#endif

// how many threads available, usable
int max_threads = jl_cpu_cores();
int max_threads = jl_cpu_threads();
jl_n_threads = JULIA_NUM_THREADS;
cp = getenv(NUM_THREADS_NAME);
if (cp) {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ function setup_launched_worker(manager, wconfig, launched_q)
# same type. This is done by setting an appropriate value to `WorkerConfig.cnt`.
cnt = something(wconfig.count, 1)
if cnt === :auto
cnt = wconfig.environ[:cpu_cores]
cnt = wconfig.environ[:cpu_threads]
end
cnt = cnt - 1 # Removing self from the requested number

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ specified, other workers will connect to this worker at the specified `bind_addr
`port`.
`count` is the number of workers to be launched on the specified host. If specified as
`:auto` it will launch as many workers as the number of cores on the specific host.
`:auto` it will launch as many workers as the number of CPU threads on the specific host.
Keyword arguments:
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct JoinPGRPMsg <: AbstractMsg
lazy::Bool
end
struct JoinCompleteMsg <: AbstractMsg
cpu_cores::Int
cpu_threads::Int
ospid::Int
end

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 @@ -349,7 +349,7 @@ end
function handle_msg(msg::JoinCompleteMsg, header, r_stream, w_stream, version)
w = map_sock_wrkr[r_stream]
environ = something(w.config.environ, Dict())
environ[:cpu_cores] = msg.cpu_cores
environ[:cpu_threads] = msg.cpu_threads
w.config.environ = environ
w.config.ospid = msg.ospid
w.version = version
Expand Down
4 changes: 2 additions & 2 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ let exename = `$(Base.julia_cmd()) --sysimage-native-code=yes --startup-file=no`
@test v[2] == "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, ()))
real_threads = string(ccall(:jl_cpu_threads, Int32, ()))
for nc in ("1", " 1 ", " +1 ", " 0x1 ", "")
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 v[2] == (isempty(nc) ? real_threads : "1")
@test isempty(v[3])
end
end
Expand Down

0 comments on commit c8bf20b

Please sign in to comment.