Skip to content

Commit

Permalink
Propagate Base.active_project() from the "manager" process to the w…
Browse files Browse the repository at this point in the history
…orker processes
  • Loading branch information
DilumAluthge committed Dec 31, 2024
1 parent 24ccc4a commit facbf03
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/slurmmanager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,48 @@ mutable struct SlurmManager <: ClusterManager
end

function launch(manager::SlurmManager, params::Dict, instances_arr::Array, c::Condition)
# Note: In the comments in this function, the phrase "manager Julia process" refers to the
# currently-active Julia process, i.e. the process that is running this Julia code.
try
exehome = params[:dir]
exename = params[:exename]
exeflags = params[:exeflags]

# Pass the key-value pairs from `params[:env]` to the `srun` command:
srun_cmd_without_env = `srun -D $exehome $exename $exeflags --worker`
the_user_specified_JULIA_PROJECT_in_params_env = false
env2 = Dict{String,String}()
for (name, value) in pairs(Dict{String,String}(params[:env]))
env2[name] = value
if name == "JULIA_PROJECT"
the_user_specified_JULIA_PROJECT_in_params_env = true
end
end
# If the user DID provide `JULIA_PROJECT` in `params[:env]`,
# then we respect that value and we do not override it.
#
# If the user did NOT provide `JULIA_PROJECT` in `params[:env]`,
# then we set `JULIA_PROJECT` to the value of `Base.active_project()`.
# https://github.com/kleinhenz/SlurmClusterManager.jl/issues/16
#
# Note that we use `Base.active_project()`.
# We intentionally do NOT use `Base.ACTIVE_PROJECT[]`.
# The reason is this: `Base.active_project()` is documented in the Julia manual.
# `Base.ACTIVE_PROJECT[]` is not documented in the Julia manual.
#
# Observe that there are three possible ways for a user to specify the active project
# for the "manager" process:
# 1. The user could have started the "manager" process with `JULIA_PROJECT=something julia`.
# 2. The user could have started the "manager" process with `julia --project` or `julia --project=something`.
# 3. The user could have started the "manager" process with `julia`, and then they used either
# `Pkg.activate()` or `Base.set_active_project()` to activate a different project.
if the_user_specified_JULIA_PROJECT_in_params_env
@debug "Passing the user-provided value for JULIA_PROJECT to the worker processes" env2["JULIA_PROJECT"]
else
env2["JULIA_PROJECT"] = Base.active_project()
@debug "Passing JULIA_PROJECT=Base.active_project() for the worker processes" env2["JULIA_PROJECT"]
end
###
srun_cmd_with_env = addenv(srun_cmd_without_env, env2)

# Pass cookie as stdin to srun; srun forwards stdin to process
Expand Down

0 comments on commit facbf03

Please sign in to comment.