This lesson is in the early stages of development (Alpha version)

Accessing software via Modules

Overview

Teaching: 30 min
Exercises: 15 min
Questions
  • How do we load and unload software packages?

Objectives
  • Load and use a software package.

  • Explain how the shell environment changes when the module mechanism loads or unloads packages.

On a high-performance computing system, it is seldom the case that the software we want to use is available when we log in. It is installed, but we will need to “load” it before it can run.

Before we start using individual software packages, however, we should understand the reasoning behind this approach. The three biggest factors are:

Software incompatibility is a major headache for programmers. Sometimes the presence (or absence) of a software package will break others that depend on it. Two well known examples are Python and C compiler versions. Python 3 famously provides a python command that conflicts with that provided by Python 2. Software compiled against a newer version of the C libraries and then run on a machine that has older C libraries installed will result in a nasty 'GLIBCXX_3.4.20' not found error.

Software versioning is another common issue. A team might depend on a certain package version for their research project - if the software version was to change (for instance, if a package was updated), it might affect their results. Having access to multiple software versions allows a set of researchers to prevent software versioning issues from affecting their results.

Dependencies are where a particular software package (or even a particular version) depends on having access to another software package (or even a particular version of another software package). For example, the VASP materials science software may depend on having a particular version of the FFTW (Fastest Fourier Transform in the West) software library available for it to work.

Environment Modules

Environment modules are the solution to these problems. A module is a self-contained description of a software package – it contains the settings required to run a software package and, usually, encodes required dependencies on other software packages.

There are a number of different environment module implementations commonly used on HPC systems: the two most common are TCL modules and Lmod. Both of these use similar syntax and the concepts are the same so learning to use one will allow you to use whichever is installed on the system you are using. In both implementations the module command is used to interact with environment modules. An additional subcommand is usually added to the command to specify what you want to do. For a list of subcommands you can use module -h or module help. As for all commands, you can access the full help on the man pages with man module.

On login you may start out with a default set of modules loaded or you may start out with an empty environment; this depends on the setup of the system you are using.

Listing Available Modules

To see available software modules, use module avail:

[yourUsername@login12 ~]$  module avail
--------------------- /shared/ucl/apps/modulefiles/core -----------------------
gerun             ops-tools/1.1.0   screen/4.2.1      userscripts/1.3.0
lm-utils/1.0      ops-tools/2.0.0   userscripts/1.0.0 userscripts/1.4.0
mrxvt/0.5.4       rcps-core/1.0.0   userscripts/1.1.0
ops-tools/1.0.0   rlwrap/0.43       userscripts/1.2.0

----------------- /shared/ucl/apps/modulefiles/applications -------------------
abaqus/2017
adf/2014.10
afni/20151030
afni/20181011
amber/14/mpi/intel-2015-update2
amber/14/openmp/intel-2015-update2
amber/14/serial/intel-2015-update2
amber/16/mpi/gnu-4.9.2

[output truncated]

Listing Currently Loaded Modules

You can use the module list command to see which modules you currently have loaded in your environment. If you have no modules loaded, you will see a message telling you so

[yourUsername@login12 ~]$  module list
No Modulefiles Currently Loaded.

Loading and Unloading Software

To load a software module, use module load. In this example we will use Python 3.

Initially, Python 3 is not loaded. We can test this by using the which command. which looks for programs the same way that Bash does, so we can use it to tell us where a particular piece of software is stored.

[yourUsername@login12 ~]$  which python3
/usr/bin/which: no python3 in (
/shared/ucl/apps/python/3.6.3/gnu-4.9.2/bin:
/shared/ucl/apps/cluster-bin:
/shared/ucl/apps/cluster-scripts:
/shared/ucl/apps/mrxvt/0.5.4/bin:
/shared/ucl/apps/tmux/2.2/gnu-4.9.2/bin:
/shared/ucl/apps/emacs/24.5/gnu-4.9.2/bin:
/shared/ucl/apps/giflib/5.1.1/gnu-4.9.2/bin:
/shared/ucl/apps/dos2unix/7.3/gnu-4.9.2/bin:
/shared/ucl/apps/nano/2.4.2/gnu-4.9.2/bin:
/shared/ucl/apps/apr-util/1.5.4/bin:
/shared/ucl/apps/apr/1.5.2/bin:
/shared/ucl/apps/git/2.19.1/gnu-4.9.2/bin:
/shared/ucl/apps/flex/2.5.39/gnu-4.9.2/bin:
/shared/ucl/apps/cmake/3.13.3/gnu-4.9.2/bin:
/shared/ucl/apps/gcc/4.9.2/bin:/opt/sge/bin:
/opt/sge/bin/lx-amd64:/usr/local/bin:/usr/bin:
/usr/local/sbin:/usr/sbin:/opt/ibutils/bin)

We can load the python3 command with module load:

[yourUsername@login12 ~]$  module load python
[yourUsername@login12 ~]$  which python3
/shared/ucl/apps/python/3.6.3/gnu-4.9.2/bin/python3

So, what just happened?

To understand the output, first we need to understand the nature of the $PATH environment variable. $PATH is a special environment variable that controls where a UNIX system looks for software. Specifically $PATH is a list of directories (separated by :) that the OS searches through for a command before giving up and telling us it can’t find it. As with all environment variables we can print it out using echo.

[yourUsername@login12 ~]$  echo $PATH
/shared/ucl/apps/python/3.6.3/gnu-4.9.2/bin:/shared/ucl/apps/intel-mpi/ucl-wrapper/bin:/shared/ucl/apps/intel/2018.Update3/impi/2018.3.222/intel64/bin:/shared/ucl/apps/intel/2018.Update3/debugger_2018/gdb/intel64_mic/bin:/shared/ucl/apps/intel/2018.Update3/compilers_and_libraries_2018.3.222/linux/mpi/intel64/bin:/shared/ucl/apps/intel/2018.Update3/compilers_and_libraries_2018.3.222/linux/bin/intel64:/shared/ucl/apps/cluster-bin:/shared/ucl/apps/cluster-scripts:/shared/ucl/apps/mrxvt/0.5.4/bin:/shared/ucl/apps/tmux/2.2/gnu-4.9.2/bin:/shared/ucl/apps/emacs/24.5/gnu-4.9.2/bin:/shared/ucl/apps/giflib/5.1.1/gnu-4.9.2/bin:/shared/ucl/apps/dos2unix/7.3/gnu-4.9.2/bin:/shared/ucl/apps/nano/2.4.2/gnu-4.9.2/bin:/shared/ucl/apps/apr-util/1.5.4/bin:/shared/ucl/apps/apr/1.5.2/bin:/shared/ucl/apps/git/2.19.1/gnu-4.9.2/bin:/shared/ucl/apps/flex/2.5.39/gnu-4.9.2/bin:/shared/ucl/apps/cmake/3.13.3/gnu-4.9.2/bin:/shared/ucl/apps/gcc/4.9.2/bin:/opt/sge/bin:/opt/sge/bin/lx-amd64:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/ibutils/bin

You’ll notice a similarity to the output of the which command. In this case, there’s only one difference: the different directory at the beginning. When we ran the module load command, it added a directory to the beginning of our $PATH. Let’s examine what’s there:

[yourUsername@login12 ~]$  ls /shared/ucl/apps/python/3.6.3/gnu-4.9.2/bin
[output truncated]

conda-convert           glib-compile-schemas     lconvert           rst2man.py
conda-develop           glib-genmarshal          libpng16-config    tiff2rgba
conda-env               glib-gettextize          libpng-config      tiffcmp
conda-index             glib-mkenums             patchelf           tiffcp
conda-inspect           gobject-query            python             tiffcrop
conda-metapackage       gresource                python3            tiffdither
conda-render            hb-view                  python3.6          tiffdump
conda-server            jupyter-run              python3.6-config   tiffinfo
conda-skeleton          jupyter-serverextension  python3.6m         tiffmedian
elbadmin                jupyter-troubleshoot     python3.6m-config  tiffset
gio-querymodules        jupyter-trust            python3-config
glacier                 kill_instance            pyuic5
glib-compile-resources  launch_instance          pyvenv

[output truncated]

Taking this to its conclusion, module load will add software to your $PATH. It “loads” software. A special note on this - depending on which version of the module program that is installed at your site, module load will also load required software dependencies.

To demonstrate, let’s use module list. module list shows all loaded software modules.

[yourUsername@login12 ~]$  module list
Currently Loaded Modulefiles:
 1) gcc-libs/4.9.2     10) nano/2.4.2         19) compilers/intel/2018/update3     
 2) cmake/3.21.1       11) nedit/5.6-aug15    20) mpi/intel/2018/update3/intel     
 3) flex/2.5.39        12) dos2unix/7.3       21) default-modules/2018             
 4) git/2.32.0         13) giflib/5.1.1       22) python/3.9.10                    
 5) apr/1.7.0          14) emacs/28.1         23) openblas/0.3.7-serial/gnu-4.9.2  
 6) apr-util/1.6.1     15) tmux/3.3a          24) python3/3.9                      
 7) subversion/1.14.1  16) mrxvt/0.5.4        25) python3/recommended              
 8) screen/4.9.0       17) userscripts/1.4.0  
 9) gerun              18) rcps-core/1.0.0
[yourUsername@login12 ~]$  module load matlab
[yourUsername@login12 ~]$  module list
Currently Loaded Modulefiles:
 1) gcc-libs/4.9.2     10) nano/2.4.2         19) compilers/intel/2018/update3     
 2) cmake/3.21.1       11) nedit/5.6-aug15    20) mpi/intel/2018/update3/intel     
 3) flex/2.5.39        12) dos2unix/7.3       21) default-modules/2018             
 4) git/2.32.0         13) giflib/5.1.1       22) python/3.9.10                    
 5) apr/1.7.0          14) emacs/28.1         23) openblas/0.3.7-serial/gnu-4.9.2  
 6) apr-util/1.6.1     15) tmux/3.3a          24) python3/3.9                      
 7) subversion/1.14.1  16) mrxvt/0.5.4        25) python3/recommended              
 8) screen/4.9.0       17) userscripts/1.4.0  26) xorg-utils/X11R7.7               
 9) gerun              18) rcps-core/1.0.0    27) matlab/full/r2023a/9.14

So in this case, loading the matlab module also loaded xorg-utils/X11R7.7, software for supporting a graphic user interface. Let’s try unloading the matlab package.

[yourUsername@login12 ~]$  module unload matlab
[yourUsername@login12 ~]$  module list
Currently Loaded Modulefiles:
 1) gcc-libs/4.9.2     10) nano/2.4.2         19) compilers/intel/2018/update3     
 2) cmake/3.21.1       11) nedit/5.6-aug15    20) mpi/intel/2018/update3/intel     
 3) flex/2.5.39        12) dos2unix/7.3       21) default-modules/2018             
 4) git/2.32.0         13) giflib/5.1.1       22) python/3.9.10                    
 5) apr/1.7.0          14) emacs/28.1         23) openblas/0.3.7-serial/gnu-4.9.2  
 6) apr-util/1.6.1     15) tmux/3.3a          24) python3/3.9                      
 7) subversion/1.14.1  16) mrxvt/0.5.4        25) python3/recommended              
 8) screen/4.9.0       17) userscripts/1.4.0  
 9) gerun              18) rcps-core/1.0.0

So using module unload “un-loads” a module, and depending on how a site is configured it may also unload all of the dependencies (in our case it does not). If we wanted to unload everything at once, we could run module purge (unloads everything).

[yourUsername@login12 ~]$  module purge
[yourUsername@login12 ~]$  module list
No Modulefiles Currently Loaded.

Note that module purge is informative. It will also let us know if a default set of “sticky” packages cannot be unloaded (and how to actually unload these if we truly so desired).

Note that this module loading process happens principally through the manipulation of environment variables like $PATH. There is usually little or no data transfer involved.

The module loading process manipulates other special environment variables as well, including variables that influence where the system looks for software libraries, and sometimes variables which tell commercial software packages where to find license servers.

The module command also restores these shell environment variables to their previous state when a module is unloaded.

Software Versioning

So far, we’ve learned how to load and unload software packages. This is very useful. However, we have not yet addressed the issue of software versioning. At some point or other, you will run into issues where only one particular version of some software will be suitable. Perhaps a key bugfix only happened in a certain version, or version X broke compatibility with a file format you use. In either of these example cases, it helps to be very specific about what software is loaded.

Let’s examine the output of module avail more closely.

[yourUsername@login12 ~]$  module avail
--------------------- /shared/ucl/apps/modulefiles/core -----------------------
gerun             ops-tools/1.1.0   screen/4.2.1      userscripts/1.3.0
lm-utils/1.0      ops-tools/2.0.0   userscripts/1.0.0 userscripts/1.4.0
mrxvt/0.5.4       rcps-core/1.0.0   userscripts/1.1.0
ops-tools/1.0.0   rlwrap/0.43       userscripts/1.2.0

----------------- /shared/ucl/apps/modulefiles/applications -------------------
abaqus/2017
adf/2014.10
afni/20151030
afni/20181011
amber/14/mpi/intel-2015-update2
amber/14/openmp/intel-2015-update2
amber/14/serial/intel-2015-update2
amber/16/mpi/gnu-4.9.2

[output truncated]

To be more specific, you can specify the particular software you want. e.g.,

[yourUsername@login12 ~]$  module avail stata
~~~~~~~~~~~~~ /shared/ucl/apps/modulefiles/applications ~~~~~~~~~~~~
stata/14 stata/15

Let’s take a closer look at the matlab module. Matlab is a widely-used piece of software which uses matrix multiplication. As we shall see, there are different versions available, and we want to make sure the one we use is the correct one for our purposes.

Let’s see which versions we have access to.

[yourUsername@login12 ~]$  module avail matlab
~~~~~~~~~~~~~ /shared/ucl/apps/modulefiles/applications ~~~~~~~~~~~~
matlab/full/r2015b/8.6 matlab/full/r2017a/9.2 matlab/full/r2018b/9.5
matlab/full/r2016b/9.1 matlab/full/r2018a/9.4 matlab/full/r2019b/9.7

In this case, there are seven different versions. How do we load each copy, and which copy is the default?

Sometimes, on some systems, a module might have a (default) next to it. This indicates that it is the default (i.e. which would be loaded if we type module load matlab). In this case, we don’t see this, so we will have to load matlab and see what we get.

[yourUsername@login12 ~]$  module load matlab

~/.matlab is a symbolic link pointing to /home/yourUsername/Scratch/.matlab

Matlab setup complete type matlab to start Matlab.


Loading matlab/full/r2023a/9.14
  Loading requirement: gcc-libs/10.2.0 xorg-utils/X11R7.7

Here, we see that the default version of Matlab on the system is r2023a/9.14, which in this case is the most recent version. However, you should not assume that the default version is necessarily the latest.

As we saw in the earlier example, there are one or more dependencies.

Suppose we decide to load an earlier version of Matlab, e.g. r2017a/9.2. You cannot load two different versions of the same software at once. Currently, we have loaded matlab/full/r2023a/9.14. Let’s try also loading matlab/full/r2021a/9.10:

[yourUsername@login12 ~]$  module load matlab/full/r2021a/9.10
Loading matlab/full/r2021a/9.10
  ERROR: Module cannot be loaded due to a conflict.
    HINT: Might try "module unload matlab" first.

As we can see, we get an error message about conflicts. If we do indeed wish to load version r2021a/9.10, we can say

[yourUsername@login12 ~]$  module unload matlab
[yourUsername@login12 ~]$  module load matlab/full/r2021a/9.10

or, in one step:

[yourUsername@login12 ~]$  module swap matlab/full/r2021a/9.10

Check that this module has been loaded:

[yourUsername@login12 ~]$  module list
Currently Loaded Modulefiles:
 1) gcc-libs/10.2.0   2) xorg-utils/X11R7.7   3) matlab/full/r2021a/9.10

Using Software Modules in Scripts

Create a job that is able to run python3 --version. Remember, no software is loaded by default! Running a job is just like logging on to the system (you should not assume a module loaded on the login node is loaded on a compute node).

Solution

[yourUsername@login12 ~]$  nano python-module.sh
[yourUsername@login12 ~]$  cat python-module.sh
#!/bin/bash -l
#$ -l h_rt=00:00:30

module load python3

python3 --version
[yourUsername@login12 ~]$  qsub python-module.sh

Key Points

  • Load software with module load softwareName.

  • Unload software with module unload

  • The module system handles software versioning and package conflicts for you automatically.