Topics Map > •Research Computing

CRC Inheriting Environment Variables in SLURM Batch Scripts

CRC Inheriting Environment Variables in SLURM Batch Scripts

Inheriting Environment Variables in SLURM Batch Scripts

Background

In order to use certain software packages on the Shared Compute Clusters, it is often necessary to set one or more environment variables. This is accomplished automatically with the module command associated with the software package.  However, it might also be necessary for these environment variables to be visible from within a SLURM batch script, yet the module command will not work with a SLURM batch script on a compute node. The following document describes the preferred way of setting environment variables inside a SLURM batch script.

Inheriting Environment Variables

The preferred way of setting environment variables in a SLURM batch script is to simply have the script inherit the environment of the parent shell from the login node. For example, you might execute the following command on login node:

login1# module load mpich

This will set the necessary environment variables to use the mpich package.

In order for these variables to be inherited in the SLURM batch script that will execute on a compute node, include the #SBATCH --export=ALL option in the batch script as follows:

Sample Job Script
#!/bin/bash #SBATCH --job-name=YourJobNameHere #SBATCH --ntasks=24 #SBATCH --mail-user=YourEmailAddress #SBATCH --mail-type=ALL #SBATCH --export=ALL
echo "I ran on: $SLURM_NODELIST"
mpiexec /path/to/myMPIprogram

When the job is submitted it will inherit all environment variables that were set in the parent shell on the login node, not just those set by the module command . Care should be taken to make sure that there are no other environment variables in the parent shell that could cause problems in the batch script.



KeywordsCRC Inheriting Environment Variables in SLURM Batch Scripts   Doc ID108482
OwnerJoseph G.GroupRice U
Created2021-01-21 10:27:18Updated2024-04-22 15:08:14
SitesRice University
Feedback  7   8