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
  • Understand how to load and use a software package.

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 of the most famous examples are Python 2 and 3 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 used when they are not present will result in a nasty 'GLIBCXX_3.4.20' not found error, for instance.

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 allow 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@login-1.SAGA ~]$ module avail
---------------------- /cluster/modulefiles/all -------------------------
4ti2/1.6.9-GCC-8.2.0-2.31.1            gmsh/4.5.6-foss-2019b-Python-3.7.4
ABySS/2.0.2-gompi-2019a                gnuplot/5.2.6-GCCcore-8.2.0
AdapterRemoval/2.3.1-foss-2018b        gnuplot/5.2.8-GCCcore-8.3.0
AdapterRemoval/2.3.1-GCC-8.2.0-2.31.1  Go/1.13.1
ADF/2019.103+StaticMKL                 gompi/2018b
AdmixTools/5.1-GCC-7.3.0-2.30          gompi/2019a
ADMIXTURE/1.3.0                        gompi/2019b

[removed most of the output here for clarity]

----------------------- /cluster/modulefiles/external ---------------------
   appusage/1.0    hpcx/2.4    hpcx/2.5    hpcx/2.6

  Where:
   S:        Module is Sticky, requires --force to unload or purge
   L:        Module is loaded
   Aliases:  Aliases exist: foo/1.2.3 (1.2) means that "module load foo/1.2"
             will load foo/1.2.3

Use "module spider" to find all possible modules.
Use "module keyword key1 key2 ..." to search for all possible modules matching
any of the "keys".

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@login-1.SAGA ~]$ 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@login-1.SAGA ~]$ which R
[SAGA ~/teaching]$ which R
/usr/bin/which: no R in (/cluster/home/user/bin:
/node/bin:/usr/local/bin:/usr/bin:
/usr/local/sbin:/usr/sbin:/cluster/bin:
/cluster/home/user/.local/bin:/cluster/home/user/bin)

We can load the R command with module load:

 module load R/4.1.0-foss-2021a
 which R

/cluster/software/R/4.1.0-foss-2021a/bin/R

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@login-1.SAGA ~]$ echo $PATH
[user@login-5.SAGA ~/teaching]$ echo $PATH
/cluster/software/R/4.1.0-foss-2021a/bin:
/cluster/software/PCRE/8.44-GCCcore-10.3.0/bin:
/cluster/software/GDAL/3.3.0-foss-2021a/bin:
/cluster/software/HDF/4.2.15-GCCcore-10.3.0/bin:
/cluster/software/SciPy-bundle/2021.05-foss-2021a/bin:
/cluster/software/pybind11/2.6.2-GCCcore-10.3.0/bin:
/cluster/software/libgeotiff/1.6.0-GCCcore-10.3.0/bin:
/cluster/software/PROJ/8.0.1-GCCcore-10.3.0/bin:
/cluster/software/GEOS/3.9.1-GCC-10.3.0/bin:
/cluster/software/netCDF/4.8.0-gompi-2021a/bin:
..............................
..............................
..............................
/cluster/software/GCCcore/10.3.0/bin:
/cluster/home/user/bin:
/node/bin:
/usr/local/bin:
....
/cluster/bin:
/cluster/home/user/.local/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:

 ls /cluster/software/R/4.1.0-foss-2021a/bin
R  Rscript

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.

 module purge
 module load Python/3.7.2-GCCcore-8.2.0
 module list

Currently Loaded Modules:
  1) StdEnv                     (S)      6) libreadline/8.0-GCCcore-8.2.0 (H)
  2) GCCcore/8.2.0                       7) XZ/5.2.4-GCCcore-8.2.0        (H)
  3) bzip2/1.0.6-GCCcore-8.2.0  (H)      8) GMP/6.1.2-GCCcore-8.2.0       (H)
  4) zlib/1.2.11-GCCcore-8.2.0  (H)      9) libffi/3.2.1-GCCcore-8.2.0    (H)
  5) ncurses/6.1-GCCcore-8.2.0  (H)     10) Python/3.7.2-GCCcore-8.2.0

  Where:
   S:  Module is Sticky, requires --force to unload or purge
   H:             Hidden Module

 module load Beast/2.5.2-GCC-8.2.0-2.31.1
 module list
Currently Loaded Modules:
  1) StdEnv                        (S)   9) libffi/3.2.1-GCCcore-8.2.0
  2) GCCcore/8.2.0                      10) Python/3.7.2-GCCcore-8.2.0
  3) bzip2/1.0.6-GCCcore-8.2.0     (H)  11) binutils/2.31.1-GCCcore-8.2.0
  4) zlib/1.2.11-GCCcore-8.2.0     (H)  12) GCC/8.2.0-2.31.1
  5) ncurses/6.1-GCCcore-8.2.0     (H)  13) Java/11.0.2
  6) libreadline/8.0-GCCcore-8.2.0 (H)  14) beagle-lib/3.1.2-GCC-8.2.0-2.31.1
  7) XZ/5.2.4-GCCcore-8.2.0        (H)  15) Beast/2.5.2-GCC-8.2.0-2.31.1
  8) GMP/6.1.2-GCCcore-8.2.0       (H)

  Where:
   S:  Module is Sticky, requires --force to unload or purge
   H:             Hidden Module

So in this case, loading the beast module (a bioinformatics software package), also loaded Java/11.0.2 and beagle-lib/3.1.2-GCC-8.2.0-2.31.1 as well. Let’s try unloading the beast package.

 module unload Beast/2.5.2-GCC-8.2.0-2.31.1
 module list
Currently Loaded Modules:
  1) StdEnv                        (S)   8) GMP/6.1.2-GCCcore-8.2.0       (H)
  2) GCCcore/8.2.0                       9) libffi/3.2.1-GCCcore-8.2.0    (H)
  3) bzip2/1.0.6-GCCcore-8.2.0     (H)  10) Python/3.7.2-GCCcore-8.2.0
  4) zlib/1.2.11-GCCcore-8.2.0     (H)  11) binutils/2.31.1-GCCcore-8.2.0 (H)
  5) ncurses/6.1-GCCcore-8.2.0     (H)  12) GCC/8.2.0-2.31.1
  6) libreadline/8.0-GCCcore-8.2.0 (H)  13) Java/11.0.2
  7) XZ/5.2.4-GCCcore-8.2.0        (H)  14) beagle-lib/3.1.2-GCC-8.2.0-2.31.1

  Where:
   S:  Module is Sticky, requires --force to unload or purge
   H:             Hidden Module

So using module unload “un-loads” a module along with its dependencies. If we wanted to unload everything at once, we could run module purge (unloads everything).

 module purge
The following modules were not unloaded:
  (Use "module --force purge" to unload all):

  1) StdEnv

Note that module purge is informative. It lets us know that all but a default set of packages have been unloaded (and how to actually unload these if we truly so desired).

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@login-1.SAGA ~]$ module avail
---------------------- /cluster/modulefiles/all -------------------------
4ti2/1.6.9-GCC-8.2.0-2.31.1            gmsh/4.5.6-foss-2019b-Python-3.7.4
ABySS/2.0.2-gompi-2019a                gnuplot/5.2.6-GCCcore-8.2.0
AdapterRemoval/2.3.1-foss-2018b        gnuplot/5.2.8-GCCcore-8.3.0
AdapterRemoval/2.3.1-GCC-8.2.0-2.31.1  Go/1.13.1
ADF/2019.103+StaticMKL                 gompi/2018b
AdmixTools/5.1-GCC-7.3.0-2.30          gompi/2019a
ADMIXTURE/1.3.0                        gompi/2019b

[removed most of the output here for clarity]

----------------------- /cluster/modulefiles/external ---------------------
   appusage/1.0    hpcx/2.4    hpcx/2.5    hpcx/2.6

  Where:
   S:        Module is Sticky, requires --force to unload or purge
   L:        Module is loaded
   Aliases:  Aliases exist: foo/1.2.3 (1.2) means that "module load foo/1.2"
             will load foo/1.2.3

Use "module spider" to find all possible modules.
Use "module keyword key1 key2 ..." to search for all possible modules matching
any of the "keys".

Let’s take a closer look at the gcc module. GCC is an extremely widely used C/C++/Fortran compiler. Tons of software is dependent on the GCC version, and might not compile or run if the wrong version is loaded. In this case, there are few different versions:

GCC/7.3.0-2.30 GCC/8.2.0-2.31.1 GCC/8.3.0 GCC/9.3.0

How do we load each copy and which copy is the default?

On SAGA and Fram we do not have default modules and we must use the full name to load it.

 module load gcc
Lmod has detected the following error:  The following module(s) are unknown:
"gcc"

Please check the spelling or version number. Also try "module spider ..."
It is also possible your cache file is out-of-date; it may help to try:
  $ module --ignore-cache load "gcc"

To load a software module we must specify the full module name:

 module load GCC/8.2.0-2.31.1
 gcc --version

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@login-1.SAGA ~]$ nano python-module.sh
[yourUsername@login-1.SAGA ~]$ cat python-module.sh
#!/usr/bin/env bash

module load Python/3.9.5-GCCcore-10.3.0

python3 --version
[yourUsername@login-1.SAGA ~]$ sbatch  --account=nn9997k --mem=1G --time=01:00  python-module.sh

Key Points

  • Load software with module load softwareName.

  • Unload software with module purge

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