The interactive()
bash function is designed to simplify the submission of interactive jobs using salloc
. It provides default arguments for common resource requests and allows for customization through additional parameters.
interactive ()
{
local DEFAULT_ARGS=(--account="$1" --partition="$2" --nodes=1 --ntasks-per-node=1 --cpus-per-task=4 --mem=64G --time="$3" --gres=gpu:l40s:1);
local EXTRA_ARGS=();
for ((i=1; i<=$#; i++))
do
if [[ "${!i}" == "--" ]]; then
EXTRA_ARGS=("${@:((i+1))}");
break;
fi;
done;
declare -A arg_map;
for arg in "${DEFAULT_ARGS[@]}";
do
key="${arg%%=*}";
arg_map["$key"]="$arg";
done;
for extra_arg in "${EXTRA_ARGS[@]}";
do
key="${extra_arg%%=*}";
arg_map["$key"]="$extra_arg";
done;
local final_args=();
for arg in "${!arg_map[@]}";
do
final_args+=("${arg_map[$arg]}");
done;
if [ -z ${DEBUG+x} ]; then
salloc "${final_args[@]}";
else
echo "salloc ${final_args[@]}";
fi
}
To use the interactive()
function, call it with the required three arguments:
interactive <account> <partition> <time>
<account>
: Your account or project ID.<partition>
: The partition (queue) to submit the job to.<time>
: The requested walltime in the formatHH:MM:SS
.
Example:
interactive my_account main_partition 01:00:00
This will allocate an interactive session with the default resource settings:
- 1 node
- 1 task per node
- 4 CPUs per task
- 64G of memory
- 1 L40s GPU
You can override the default arguments by adding additional parameters after the first three. You must separate the parameters from the first 3 with a --
. The new parameters should also start with --
.
interactive <account> <partition> <time> -- [--nodes=<num_nodes>] [--ntasks-per-node=<num_tasks>] [--cpus-per-task=<num_cpus>] [--mem=<memory>] [--gres=<resource:type:count>]
Example:
interactive my_account main_partition 01:00:00 -- --nodes=2 --mem=128G
This will allocate an interactive session with:
- 2 nodes
- 128G of memory per node
- Other default settings remain unchanged.
To see the generated salloc
command without executing it, set the DEBUG
variable:
DEBUG=true interactive my_account main_partition 01:00:00
This will print the command to the console instead of executing it.
- The function merges default arguments with any additional arguments you provide.
- If you specify an argument that is already in the defaults (e.g.,
--nodes
), your custom value will override the default. - The function assumes you have
salloc
in your PATH. (If running on the CHPC you do)
This function is particularly useful for quickly submitting interactive jobs to a scheduler while allowing flexibility for custom resource requests.