250 words
1 minute
Custom Command

I. sr — Custom SLURM Interactive Job Launcher#

Overview: sr is a small wrapper script around srun that lets you launch an interactive GPU session on an HPC cluster with a short, memorable command — optionally targeting a specific node.

1. Write the Script#

Create a file named sr with the following content:

#!/bin/bash
# ===== Argument check =====
if [ -z "$1" ]; then
echo "Usage:"
echo " sr <gpu_type> [node_id]"
echo ""
echo "Examples:"
echo " sr h100"
echo " sr h100 007"
echo " sr a100"
exit 1
fi
GPU_TYPE="$1"
PARTITION="gpucompute-$GPU_TYPE"
NODE_ARG=""
# ===== Optional node targeting =====
if [ -n "$2" ]; then
NODE_ARG="--nodelist=ghpc$2"
fi
# ===== Launch interactive session =====
srun \
--gpus-per-node=1 \
--cpus-per-gpu=4 \
$NODE_ARG \
--partition=$PARTITION \
--time=12:00:00 \
--pty /bin/bash

2. Install the Script#

Move the script to ~/bin and make it executable:

Terminal window
mkdir -p ~/bin
mv sr ~/bin/
chmod +x ~/bin/sr

Ensure ~/bin is on your PATH:

Terminal window
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

3. Usage#

Terminal window
sr h100 # Request any H100 node
sr h100 007 # Request H100 node ghpc007 specifically
sr a100 # Request any A100 node

💡 One-line Takeaway
Drop sr into ~/bin, add ~/bin to your PATH, and replace verbose srun commands with sr h100 or sr h100 007 to spin up an interactive GPU session instantly.
Custom Command
https://lxy-alexander.github.io/blog/posts/tools/custom-command/
Author
Alexander Lee
Published at
2026-02-05
License
CC BY-NC-SA 4.0