Environment Modules (eMod)

What are environment modules (eMod)?

On CS Linux systems, additional software is made available via Linux Environment Modules. This helps us to provide and maintain multiple versions of a variety of software. Users do not have to deal with details such as environment paths to different software versions or libraries. Modules will set or unset the appropriate paths for you.

How to see all available modules?

To see all available modules run module available command. Here is an example output:

$ module available
--------------------------------- /usr/local/modules ---------------------------------------
courses/cs356         cuda/9.1   cuda/11.2     gcc/6.5.0   java/8       maven/3.6.3         opencv/4.5.1       user/python-3.8
courses/cs415         cuda/10.0  cuda/11.3     gcc/7.4.0   java/11      mentor/2022         python/anaconda
courses/cs435/hadoop  cuda/10.1  cuda/11.4     gcc/8.2.0   java/15      mpi/mpich-4.0.1     python/bundle-3.6
courses/cs556         cuda/10.2  cuda/11.6     gcc/9.3.0   java/17      mpi/openmpi-i386    python/bundle-3.8
cuda/7.5              cuda/11.0  cuda/11.7     gcc/10.2.0  maven/3.3.9  mpi/openmpi-slurm   python/bundle-3.9
cuda/8.0              cuda/11.1  ffmpeg/4.3.1  gcc/11.2.0  maven/3.5.4  mpi/openmpi-x86_64  user/python-3.6
How to use a software via modules?

To use a specific software package, load the corresponding module. For instance, if you would like to use NVIDIA CUDA 11.4, use the command:

$ module load cuda/11.4

As a good practice, when loading an environment module you must specify the full name of the module. Just like in the above example we used the complete name of the CUDA module (along with the version number). The full name for modules can be found in the output of module available command.

How to know which modules I have loaded?

To see which specific modules are loaded, run module list command:

$ module list
Currently Loaded Modulefiles:
 1) cuda/11.4   2) gcc/11.2.0

In the above example, we see that the user has loaded two modules: CUDA v11.4 and GCC v11.2.0

How to unload a module?

To remove a module from your environment, use the module unload <module-name> command. Let us unload the CUDA 11.4 module which we loaded before:

$ module unload cuda/11.4

To verify, list the presently loaded modules:

$ module list
Currently Loaded Modulefiles:
 1) gcc/11.2.0

We see that the CUDA module is not loaded anymore.

How to unload all loaded modules?

Use the module purge command to unload all loaded modules.

$ module purge

Now as a check:

$ module list
No Modulefiles Currently Loaded.
How to switch between software versions?

Use the module switch <module-name> command to switch to a different version of the software package. For example, let us assume we want to switch to CUDA version 10.2 from 11.4 (which we have already loaded).

First, confirm we have CUDA 11.4 loaded:

$ module list
Currently Loaded Modulefiles:
 1) cuda/11.4

We can also check the version of the nvcc compiler:

$ nvcc --version | grep release
Cuda compilation tools, release 11.4, V11.4.152

This confirms that we are indeed using CUDA v11.4 Now, let us switch to CUDA v10.2

$ module switch cuda/10.2

Let us see what modules are loaded now:

$ module list
Currently Loaded Modulefiles:
 1) cuda/10.2

We now see CUDA 10.2 loaded instead of 11.4 Let us confirm by checking the version of the nvcc compiler:

$ nvcc --version | grep release
Cuda compilation tools, release 10.2, V10.2.89

So, this confirms that we have switched CUDA version from 11.4 to 10.2.

How can I make this persistent?

Most modules can be made to load at every login by adding the appropriate module load <module-name> statement in your shell configuration files (.bashrc or .cshrc).

Note that in non-login shells, the modules configuration environment can not automatically load.

If you need to use environment modules in non-login shells, non-interactive SLURM jobs, or other similar sessions, you will need to include the following in your shell config files:

BASH

source /etc/profile.d/modules.sh
module purge

TCSH

source /etc/profile.d/modules.csh
module purge

These statements must be added before any module load statements. Following these, you could add any module load <modulename> statements.