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:

[SUNetID@rice-02:~]$ module avail
------------------ /software/modules/linux-ubuntu22.04-x86_64/Core -------------------
   apptainer/1.1.9                        libjpeg-turbo/2.1.5.1
   blast-plus/2.14.1                      libpng/1.5.30
   boost/1.85.0                           llvm/18.1.3
   bowtie2/2.5.2                          micromamba/1.4.2
   cuda/11.4.4                            mpich/4.2.1

[removed most of the output here for clarity]

  Where:
   D:  Default Module

If the avail list is too long consider trying:

"module --default avail" or "ml -d av" to just list the default modules.
"module overview" or "ml ov" to display the number of modules for each name.

Use "module spider" to find all possible modules and extensions.
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

[SUNetID@rice-02:~]$ module list
No modules 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.

[SUNetID@rice-02:~]$ which python3

If the python3 command was unavailable, we would see output like

/usr/bin/which: no python3 in (/home/users/SUNetID/bin:/home/users/SUNetID/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin)

Note that this wall of text is really a list, with values separated by the : character. The output is telling us that the which command searched the following directories for python3, without success:

/home/users/SUNetID/bin
/home/users/SUNetID/.local/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin

However, in our case we do have an existing python3 available so we see

/usr/bin/python3

We need a different Python than the system provided one though, so let us load a module to access it.

We can load the python3 command with module load:

[SUNetID@rice-02:~]$ module load python
[SUNetID@rice-02:~]$ which python3
/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/python-3.11.7-pph34wf44o63tsszsra7m7ihjrmcniaj/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.

[SUNetID@rice-02:~]$ echo $PATH
/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/python-3.11.7-pph34wf44o63tsszsra7m7ihjrmcniaj/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/util-linux-uuid-2.38.1-zaohlkc7x4n5d3fbxpfb672inndarvau/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/sqlite-3.43.2-4hpmcprlw5equdicrtcmacl5psvhhmxf/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/openssl-3.3.0-4gl4yy3vwevsukqvlffjeeyofzrqrsxy/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/gettext-0.22.5-yrjlrvvghvrkmemdgnymjytmqnjydwnf/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/tar-1.34-ddpzee5n4ckjguinf6mvzwdnmhjezjln/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/zstd-1.5.6-77bmnajavm5hebchfmfxhjq3xgp45w7r/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/pigz-2.8-gvcpolzhshratajggf3jptqfnqsufhhn/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/libxml2-2.10.3-pwcbmqyzxybnsdc65wpvi4szbxgs5ywx/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/xz-5.4.6-x7ef77ycuvfkealpqz7efodaehjj2xbm/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/libiconv-1.17-agtuexjs5f4hbr34gniwqgcza6wlsdh5/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/gdbm-1.23-rtgm7swq4xhs6uosx7kd2zbx2lgn4rsy/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/readline-8.2-yy655utp5k7pzjkxjpadu7lnbg2vq3bl/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/ncurses-6.5-l7iqip2kzaxff54gqpuxtqwse222qvea/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/expat-2.6.2-gugyyi4jfqm36v2pvpmz2ij34e77cokg/bin:/software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/bzip2-1.0.8-4z7zft5br5b6o2m7zr5oiqoxxsgv3gxf/bin:/home/users/SUNetID/bin:/home/users/SUNetID/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/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:

[SUNetID@rice-02:~]$ ls /software/spack/opt/spack/linux-ubuntu22.04-x86_64_v3/gcc-13.2.0/python-3.11.7-pph34wf44o63tsszsra7m7ihjrmcniaj/bin
2to3       idle3.11   python         python3-config     python3.11-gdb.py
2to3-3.11  pydoc3     python-config  python3.11
idle3      pydoc3.11  python3        python3.11-config

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.

[SUNetID@rice-02:~]$ module list
Currently Loaded Modules:
  1) glibc/2.35-hwm6jll          13) libxml2/2.10.3-pwcbmqy
  2) gcc-runtime/13.2.0-4b46r64  14) pigz/2.8-gvcpolz
  3) bzip2/1.0.8-4z7zft5         15) zstd/1.5.6-77bmnaj
  4) libmd/1.0.4-zgn4nm3         16) tar/1.34-ddpzee5
  5) libbsd/0.12.1-i7vok2f       17) gettext/0.22.5-yrjlrvv
  6) expat/2.6.2-gugyyi4         18) libffi/3.4.6-3p64pum
  7) ncurses/6.5-l7iqip2         19) libxcrypt/4.4.35-3ofajra
  8) readline/8.2-yy655ut        20) openssl/3.3.0-4gl4yy3
  9) gdbm/1.23-rtgm7sw           21) sqlite/3.43.2-4hpmcpr
 10) libiconv/1.17-agtuexj       22) util-linux-uuid/2.38.1-zaohlkc
 11) xz/5.4.6-x7ef77y            23) python/3.11.7
 12) zlib-ng/2.1.6-4xk6kiq
[SUNetID@rice-02:~]$ module load julia
[SUNetID@rice-02:~]$ module list
Currently Loaded Modules:
  1) glibc/2.35-hwm6jll              27) curl/8.7.1-dilktws
  2) gcc-runtime/13.2.0-4b46r64      28) dsfmt/2.2.5-yrb7poa
  3) bzip2/1.0.8-4z7zft5             29) gmp/6.2.1-brxkiho
  4) libmd/1.0.4-zgn4nm3             30) libblastrampoline/5.8.0-pajuz6u
  5) libbsd/0.12.1-i7vok2f           31) pcre/8.45-bsep6cd
  6) expat/2.6.2-gugyyi4             32) libgit2/1.6.4-6n6p7pm
  7) ncurses/6.5-l7iqip2             33) libunwind/1.6.2-bzhjldn
  8) readline/8.2-yy655ut            34) libuv-julia/1.44.3-mpcmz2j
  9) gdbm/1.23-rtgm7sw               35) binutils/2.42-pyz2his
 10) libiconv/1.17-agtuexj           36) pkgconf/2.2.0-euy2z2u
 11) xz/5.4.6-x7ef77y                37) elfutils/0.190-r6vhdnt
 12) zlib-ng/2.1.6-4xk6kiq           38) libpciaccess/0.17-pfgymna
 13) libxml2/2.10.3-pwcbmqy          39) hwloc/2.9.1-smlej6r
 14) pigz/2.8-gvcpolz                40) libedit/3.1-20230828-ls2cusj
 15) zstd/1.5.6-77bmnaj              41) unzip/6.0-w3hyu2g
 16) tar/1.34-ddpzee5                42) lua/5.3.6-bshf2me
 17) gettext/0.22.5-yrjlrvv          43) swig/4.0.2-fortran-irv7aqc
 18) libffi/3.4.6-3p64pum            44) llvm/15.0.7-aibkinw
 19) libxcrypt/4.4.35-3ofajra        45) mpfr/4.2.1-bpff5zj
 20) openssl/3.3.0-4gl4yy3           46) openlibm/0.8.1-vk6saea
 21) sqlite/3.43.2-4hpmcpr           47) p7zip/17.05-gtsuz3k
 22) util-linux-uuid/2.38.1-zaohlkc  48) pcre2/10.43-lfijy3h
 23) python/3.11.7                   49) metis/5.1.0-jfogols
 24) mbedtls/2.28.2-7husfdf          50) suite-sparse/7.2.1-ybtegdu
 25) libssh2/1.11.0-z7hjcm2          51) utf8proc/2.8.0-ib2ggng
 26) nghttp2/1.52.0-zz56qrn          52) julia/1.10.2

So in this case, loading the julia module (a high-level, high-performance dynamic programming language for numerical computing), also loaded many other dependencies as well. Let’s try unloading the julia package.

[SUNetID@rice-02:~]$ module unload julia
[SUNetID@rice-02:~]$ module list
Currently Loaded Modules:
  1) glibc/2.35-hwm6jll          13) libxml2/2.10.3-pwcbmqy
  2) gcc-runtime/13.2.0-4b46r64  14) pigz/2.8-gvcpolz
  3) bzip2/1.0.8-4z7zft5         15) zstd/1.5.6-77bmnaj
  4) libmd/1.0.4-zgn4nm3         16) tar/1.34-ddpzee5
  5) libbsd/0.12.1-i7vok2f       17) gettext/0.22.5-yrjlrvv
  6) expat/2.6.2-gugyyi4         18) libffi/3.4.6-3p64pum
  7) ncurses/6.5-l7iqip2         19) libxcrypt/4.4.35-3ofajra
  8) readline/8.2-yy655ut        20) openssl/3.3.0-4gl4yy3
  9) gdbm/1.23-rtgm7sw           21) sqlite/3.43.2-4hpmcpr
 10) libiconv/1.17-agtuexj       22) util-linux-uuid/2.38.1-zaohlkc
 11) xz/5.4.6-x7ef77y            23) python/3.11.7
 12) zlib-ng/2.1.6-4xk6kiq

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). If we wanted to unload everything at once, we could run module purge (unloads everything).

[SUNetID@rice-02:~]$ module purge
[SUNetID@rice-02:~]$ module list
No modules 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.

[SUNetID@rice-02:~]$ module avail
------------------ /software/modules/linux-ubuntu22.04-x86_64/Core -------------------
   apptainer/1.1.9                        libjpeg-turbo/2.1.5.1
   blast-plus/2.14.1                      libpng/1.5.30
   boost/1.85.0                           llvm/18.1.3
   bowtie2/2.5.2                          micromamba/1.4.2
   cuda/11.4.4                            mpich/4.2.1

[removed most of the output here for clarity]

  Where:
   D:  Default Module

If the avail list is too long consider trying:

"module --default avail" or "ml -d av" to just list the default modules.
"module overview" or "ml ov" to display the number of modules for each name.

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

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

[SUNetID@rice-02:~]$ nano python-module.sh
[SUNetID@rice-02:~]$ cat python-module.sh
#!/bin/bash
#SBATCH #SBATCH -t 00:00:30

module load python

python3 --version
[SUNetID@rice-02:~]$ sbatch 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.