@@ -44,17 +44,48 @@ mutable struct SlurmManager <: ClusterManager
4444end
4545
4646function launch (manager:: SlurmManager , params:: Dict , instances_arr:: Array , c:: Condition )
47+ # Note: In the comments in this function, the phrase "manager Julia process" refers to the
48+ # currently-active Julia process, i.e. the process that is running this Julia code.
4749 try
4850 exehome = params[:dir ]
4951 exename = params[:exename ]
5052 exeflags = params[:exeflags ]
5153
5254 # Pass the key-value pairs from `params[:env]` to the `srun` command:
5355 srun_cmd_without_env = ` srun -D $exehome $exename $exeflags --worker`
56+ the_user_specified_JULIA_PROJECT_in_params_env = false
5457 env2 = Dict {String,String} ()
5558 for (name, value) in pairs (Dict {String,String} (params[:env ]))
5659 env2[name] = value
60+ if name == " JULIA_PROJECT"
61+ the_user_specified_JULIA_PROJECT_in_params_env = true
62+ end
5763 end
64+ # If the user DID provide `JULIA_PROJECT` in `params[:env]`,
65+ # then we respect that value and we do not override it.
66+ #
67+ # If the user did NOT provide `JULIA_PROJECT` in `params[:env]`,
68+ # then we set `JULIA_PROJECT` to the value of `Base.active_project()`.
69+ # https://github.com/kleinhenz/SlurmClusterManager.jl/issues/16
70+ #
71+ # Note that we use `Base.active_project()`.
72+ # We intentionally do NOT use `Base.ACTIVE_PROJECT[]`.
73+ # The reason is this: `Base.active_project()` is documented in the Julia manual.
74+ # `Base.ACTIVE_PROJECT[]` is not documented in the Julia manual.
75+ #
76+ # Observe that there are three possible ways for a user to specify the active project
77+ # for the "manager" process:
78+ # 1. The user could have started the "manager" process with `JULIA_PROJECT=something julia`.
79+ # 2. The user could have started the "manager" process with `julia --project` or `julia --project=something`.
80+ # 3. The user could have started the "manager" process with `julia`, and then they used either
81+ # `Pkg.activate()` or `Base.set_active_project()` to activate a different project.
82+ if the_user_specified_JULIA_PROJECT_in_params_env
83+ @debug " Passing the user-provided value for JULIA_PROJECT to the worker processes" env2[" JULIA_PROJECT" ]
84+ else
85+ env2[" JULIA_PROJECT" ] = Base. active_project ()
86+ @debug " Passing JULIA_PROJECT=Base.active_project() for the worker processes" env2[" JULIA_PROJECT" ]
87+ end
88+ # ##
5889 srun_cmd_with_env = addenv (srun_cmd_without_env, env2)
5990
6091 # Pass cookie as stdin to srun; srun forwards stdin to process
0 commit comments