How to get Slurm job environment variables?
Apr 2, 2:27pm

To get Slurm job environment variables, you have several options depending on your needs:

1. Print All Environment Variables in Your Job Script

You can print all environment variables inside your Slurm job script using:

bash
#!/bin/bash
#SBATCH --job-name=my_job
#SBATCH --output=output.log

# Print all environment variables
env

or

bash
printenv

This will output all environment variables, including those set by Slurm.


2. Access Slurm-Specific Environment Variables

Slurm sets several environment variables for your job. You can access them directly in your script or after the job completes:

bash
echo $SLURM_JOB_ID
echo $SLURM_JOB_NAME
echo $SLURM_NODELIST
echo $SLURM_NTASKS

Common Slurm environment variables


3. Pass Custom Environment Variables to Your Job

If you want to pass specific environment variables to your job, use the --export option:

bash
sbatch --export=ALL,MY_VAR=value my_script.sh

or export only certain variables:

bash
sbatch --export=MY_VAR1,MY_VAR2=value my_script.sh

4. Check Environment Variables After Job Submission

After submitting your job, you can check the environment variables set for a specific job using:

bash
scontrol show job <job_id> | grep Environment

or

bash
sacct -j <job_id> --format=JobID,JobName,Environment

5. Debugging Environment Issues

If you suspect environment issues, you can run a simple bash job with -s to source your environment:

bash
sbatch -s -o debug.log ./my_script.sh

Apr 2, 2:27pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.