Skip to content

Commit

Permalink
Make threads explicitly configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Apr 24, 2023
1 parent 57f72ad commit 0dd5d12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/sandbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,11 @@ function setup_julia_sandbox(config::Configuration, args=``;

cmd = `$(config.julia_install_dir)/bin/$(config.julia_binary)`

# restrict resource usage
if !isempty(config.cpus)
env["JULIA_CPU_THREADS"] = string(length(config.cpus)) # JuliaLang/julia#35787
env["OPENBLAS_NUM_THREADS"] = string(length(config.cpus)) # defaults to Sys.CPU_THREADS
env["JULIA_NUM_PRECOMPILE_TASKS"] = string(length(config.cpus)) # defaults to Sys.CPU_THREADS
end
# configure threads
env["JULIA_CPU_THREADS"] = string(length(config.threads))
## some settings should default to Sys.CPU_THREADS, but it can't hurt to be explicit
env["OPENBLAS_NUM_THREADS"] = string(length(config.threads))
env["JULIA_NUM_PRECOMPILE_TASKS"] = string(length(config.threads))

setup_generic_sandbox(config, `$cmd $(Cmd(config.julia_flags)) $args`;
env, mounts, kwargs...)
Expand Down
5 changes: 3 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ Base.@kwdef struct Configuration
## a list of environment variables to set in the sandbox
env::Setting{Vector{String}} = Default(String[])
## a list of CPUs to restrict the Julia process to (or empty if unconstrained).
## if set, JULIA_CPU_THREADS will also be set to a number equaling the number of CPUs.
cpus::Setting{Vector{Int}} = Default(Int[])
## how many threads the Julia process should use
threads::Setting{Int} = Default(1)
## whether to spawn a virtual X server and expose that to the sandbox
xvfb::Setting{Bool} = Default(true)
## whether to run under record-replay (rr). traces will be uploaded to AWS S3, so you
Expand Down Expand Up @@ -118,7 +119,7 @@ function Base.show(io::IO, cfg::Configuration)
println(io)

println(io, " # Execution properties")
show_setting.(["env", "cpus", "xvfb", "rr", "precompile", "compiled", "process_limit"])
show_setting.(["env", "cpus", "threads", "xvfb", "rr", "precompile", "compiled", "process_limit"])
show_setting.(["log_limit", "memory_limit"], Base.format_bytes)
show_setting.(["time_limit", "compile_time_limit"], durationstring)

Expand Down

0 comments on commit 0dd5d12

Please sign in to comment.