Topics Map > •Research Computing
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:
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:
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.