Accessing software via Modules
Overview
Teaching: 30 min
Exercises: 15 minQuestions
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 incompatibilities
- versioning
- dependencies
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@cirrus-login1 ~]$ module avail
------------------------------------------------------- /mnt/lustre/indy2lfs/sw/modulefiles -------------------------------------------------------
altair-hwsolvers/13.0.213 gdb/10.2 intel-fc-19/19.0.0.117 openfoam/v2106
altair-hwsolvers/14.0.210 git/2.21.0(default) intel-itac-18/2018.5.025 openmpi/4.1.2
anaconda/python3 git/2.37.3 intel-itac-19/19.0.0.117 openmpi/4.1.2-cuda-11.6
ansys/18.0 gmp/6.2.0-intel intel-license openmpi/4.1.4(default)
ansys/19.0 gmp/6.2.1-mpt intel-mpi-18/18.0.5.274 openmpi/4.1.4-cuda-11.6
ant/1.10.8(default) gnu-parallel/20200522-gcc6(default) intel-mpi-19/19.0.0.117 perf/1.0.0
autotools/default gnuplot/5.4.0(default) intel-tbb-18/18.0.5.274 petsc/3.13.2-intel-mpi-18
binutils/2.36(default) gromacs/2020.2 intel-tbb-19/19.0.0.117(default) petsc/3.13.2-mpt
bison/3.6.4 gromacs/2020.2-gpu intel-tools-18/18.0.5.274 pyfr/1.14.0-gpu
boost/1.67.0 gromacs/2022.1(default) intel-tools-19/19.0.0.117 pyfr/1.15.0-gpu(default)
boost/1.73.0(default) gromacs/2022.1-gpu intel-vtune-18/2018.4.0.573462(default) python/3.9.12-gpu
castep/18/(default) gromacs/2022.3-gpu intel-vtune-19/2019.0.2.570779(default) python/3.9.13
castep/18/18.1.0 gsl/2.6-gcc8 java/jdk-14.0.1 python/3.9.13-gpu
castep/19/19.1.1 gsl/2.7-gcc8(default) lammps/3March2020-intel19-mpt pytorch/1.12.1
cmake/3.17.3(default) hdf5parallel/1.10.4-intel18-impi18 lammps/23Jun2022_intel19_mpt pytorch/1.12.1-gpu
cmake/3.22.1 hdf5parallel/1.10.6-gcc6-mpt225 libnsl/1.3.0(default) quantum-espresso/6.5-intel-19
cp2k/7.1 hdf5parallel/1.10.6-gcc8-mpt225 libpng/1.6.30 quantum-espresso/6.5-intel-20.4
CRYSTAL17/1.0.2_intel18 hdf5parallel/1.10.6-intel18-mpt225 libtirpc/1.2.6(default) R/3.6.3
CUnit/2.1.3(default) hdf5parallel/1.10.6-intel19-mpt225 libtool/2.4.6 R/4.0.2(default)
dolfin/2019.1.0-intel-mpi hdf5parallel/1.12.0-nvhpc-openmpi libxkbcommon/1.0.1(default) scalasca/2.6-gcc8-mpt225
dolfin/2019.1.0-mpt hdf5serial/1.10.6-intel18 matlab/R2019a scalasca/2.6-intel19-mpt225
eclipse/2020-09(default) horovod/0.25.0 matlab/R2019b singularity/3.7.2(default)
epcc/deprecated-software horovod/0.25.0-gpu matlab/R2020b(default) specfem3d/3.0(default)
epcc/setup-env htop/3.1.2 matlab/R2021b starccm+/13.06.012(default)
epcc/utils htop/3.2.1(default) metis/5.1.0 starccm+/13.06.012-R8
expat/2.2.9 ImageMagick/7.0.10-22(default) mpc/1.1.0 starccm+/14.04.013-R8
fenics/2019.1.0-intel-mpi intel-19.5/cc mpfr/4.0.2-intel starccm+/14.06.013-R8
fenics/2019.1.0-mpt intel-19.5/cmkl mpfr/4.0.2-mpt starccm+/15.02.009-R8
fftw/3.3.8-gcc8-ompi4 intel-19.5/compilers namd/2.14(default) starccm+/15.04.010-R8
fftw/3.3.8-intel18 intel-19.5/fc namd/2.14-gpu starccm+/15.06.008-R8
fftw/3.3.8-intel19(default) intel-19.5/itac namd/2.14-nosmp starccm+/16.02.009
fftw/3.3.9-impi19-gcc8 intel-19.5/mpi ncl/6.6.2 starccm+/2019.3.1-R8
fftw/3.3.10-intel19-mpt225 intel-19.5/pxse nco/4.9.3 starccm+/2020.1.1-R8
fftw/3.3.10-intel20.4 intel-19.5/tbb ncview/2.1.7 starccm+/2020.2.1-R8
flacs-cfd/20.1 intel-19.5/vtune netcdf-parallel/4.6.2-intel18-impi18 starccm+/2020.3.1-R8
flacs-cfd/20.2 intel-20.4/cc netcdf-parallel/4.6.2-intel19-mpt225 starccm+/2021.1.1
flacs-cfd/21.1 intel-20.4/cmkl ninja/1.10.2(default) strace/5.8(default)
flacs-cfd/21.2 intel-20.4/compilers nvidia/cudnn/8.2.1-cuda-11.6 svn/1.14.0(default)
flacs-cfd/22.1 intel-20.4/fc nvidia/cudnn/8.5.0-cuda-11.6 tensorflow/2.9.1-gpu
flacs/10.9.1 intel-20.4/itac nvidia/cudnn/8.6.0-cuda-11.6(default) tensorflow/2.10.0
flex/2.6.4 intel-20.4/mpi nvidia/nvhpc-byo-compiler/21.2 tmux/3.3a(default)
gaussian/16.A03(default) intel-20.4/psxe nvidia/nvhpc-byo-compiler/21.9 ucx/1.9.0
gcc/6.2.0 intel-20.4/tbb nvidia/nvhpc-byo-compiler/22.2 ucx/1.9.0-cuda-11.6
gcc/6.3.0 intel-20.4/vtune nvidia/nvhpc-nompi/22.2 udunits/2.2.26
gcc/8.2.0(default) intel-cc-18/18.0.5.274 nvidia/nvhpc/22.2 valgrind/3.16.1(default)
gcc/10.2.0 intel-cc-19/19.0.0.117 nvidia/tensorrt/7.2.3.4 vasp/5/5.4.4-intel19-mpt220(default)
gdal/2.1.2-gcc intel-cmkl-18/18.0.5.274 nvidia/tensorrt/8.4.3.1-u2 vasp/6/6.2.1-intel19-mpt220(default)
gdal/2.1.2-intel intel-cmkl-19/19.0.0.117 oneapi/2022.2.0(default) zlib/1.2.11(default)
gdal/2.4.4-gcc intel-compilers-18/18.05.274 openfoam/v8.0
gdal/2.4.4-intel intel-compilers-19/19.0.0.117 openfoam/v9.0
gdb/9.2(default) intel-fc-18/18.0.5.274 openfoam/v2006
--------------------------------------------------------- /usr/share/Modules/modulefiles ----------------------------------------------------------
dot hmpt/2.25 module-git module-info modules mpt/2.25 null perfboost use.own
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@cirrus-login1 ~]$ module list
Currently Loaded Modulefiles:
1) git/2.37.3 2) epcc/utils 3) /mnt/lustre/indy2lfs/sw/modulefiles/epcc/setup-env
Loading and Unloading Software
To load a software module, use module load
. In this example we will use
R.
Initially, R 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@cirrus-login1 ~]$ which R
/usr/bin/which: no R in (/mnt/lustre/indy2lfs/sw/git/2.37.3/bin:/opt/clmgr/sbin:/opt/clmgr/bin:/opt/sgi/sbin:/opt/sgi/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/c3/bin:/sbin:/bin)
We can load the R
command with module load
:
[yourUsername@cirrus-login1 ~]$ module load R
[yourUsername@cirrus-login1 ~]$ which R
/mnt/lustre/indy2lfs/sw/R/4.0.2/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@cirrus-login1 ~]$ echo $PATH
/mnt/lustre/indy2lfs/sw/R/4.0.2/bin/:/mnt/lustre/indy2lfs/sw/gcc/8.2.0/bin:/mnt/lustre/indy2lfs/sw/git/2.37.3/bin:/opt/clmgr/sbin:/opt/clmgr/bin:/opt/sgi/sbin:/opt/sgi/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/c3/bin:/sbin:/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@cirrus-login1 ~]$ ls /mnt/lustre/indy2lfs/sw/R/4.0.2/bin/
R Rscript
In summary, 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 load the gromacs
module and then use the module list
command to show which modules we currently have loaded in our environment.
(Gromacs is an open source molecular dynamics package.)
[yourUsername@cirrus-login1 ~]$ module load gromacs
[yourUsername@cirrus-login1 ~]$ module list
Currently Loaded Modulefiles:
1) git/2.37.3 2) epcc/utils 3) /mnt/lustre/indy2lfs/sw/modulefiles/epcc/setup-env 4) gcc/8.2.0(default) 5) mpt/2.25 6) gromacs/2022.1(default)
So in this case, loading the gromacs
module also loaded a variety of other
modules. Let’s try unloading the gromacs
package.
[yourUsername@cirrus-login1 ~]$ module unload gromacs
[yourUsername@cirrus-login1 ~]$ module list
Currently Loaded Modulefiles:
1) git/2.37.3 2) epcc/utils 3) /mnt/lustre/indy2lfs/sw/modulefiles/epcc/setup-env
So using module unload
“un-loads” a module along with its dependencies.
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@cirrus-login1 ~]$ module avail
------------------------------------------------------- /mnt/lustre/indy2lfs/sw/modulefiles -------------------------------------------------------
altair-hwsolvers/13.0.213 gdb/10.2 intel-fc-19/19.0.0.117 openfoam/v2106
altair-hwsolvers/14.0.210 git/2.21.0(default) intel-itac-18/2018.5.025 openmpi/4.1.2
anaconda/python3 git/2.37.3 intel-itac-19/19.0.0.117 openmpi/4.1.2-cuda-11.6
ansys/18.0 gmp/6.2.0-intel intel-license openmpi/4.1.4(default)
ansys/19.0 gmp/6.2.1-mpt intel-mpi-18/18.0.5.274 openmpi/4.1.4-cuda-11.6
ant/1.10.8(default) gnu-parallel/20200522-gcc6(default) intel-mpi-19/19.0.0.117 perf/1.0.0
autotools/default gnuplot/5.4.0(default) intel-tbb-18/18.0.5.274 petsc/3.13.2-intel-mpi-18
binutils/2.36(default) gromacs/2020.2 intel-tbb-19/19.0.0.117(default) petsc/3.13.2-mpt
bison/3.6.4 gromacs/2020.2-gpu intel-tools-18/18.0.5.274 pyfr/1.14.0-gpu
boost/1.67.0 gromacs/2022.1(default) intel-tools-19/19.0.0.117 pyfr/1.15.0-gpu(default)
boost/1.73.0(default) gromacs/2022.1-gpu intel-vtune-18/2018.4.0.573462(default) python/3.9.12-gpu
castep/18/(default) gromacs/2022.3-gpu intel-vtune-19/2019.0.2.570779(default) python/3.9.13
castep/18/18.1.0 gsl/2.6-gcc8 java/jdk-14.0.1 python/3.9.13-gpu
castep/19/19.1.1 gsl/2.7-gcc8(default) lammps/3March2020-intel19-mpt pytorch/1.12.1
cmake/3.17.3(default) hdf5parallel/1.10.4-intel18-impi18 lammps/23Jun2022_intel19_mpt pytorch/1.12.1-gpu
cmake/3.22.1 hdf5parallel/1.10.6-gcc6-mpt225 libnsl/1.3.0(default) quantum-espresso/6.5-intel-19
cp2k/7.1 hdf5parallel/1.10.6-gcc8-mpt225 libpng/1.6.30 quantum-espresso/6.5-intel-20.4
CRYSTAL17/1.0.2_intel18 hdf5parallel/1.10.6-intel18-mpt225 libtirpc/1.2.6(default) R/3.6.3
CUnit/2.1.3(default) hdf5parallel/1.10.6-intel19-mpt225 libtool/2.4.6 R/4.0.2(default)
dolfin/2019.1.0-intel-mpi hdf5parallel/1.12.0-nvhpc-openmpi libxkbcommon/1.0.1(default) scalasca/2.6-gcc8-mpt225
dolfin/2019.1.0-mpt hdf5serial/1.10.6-intel18 matlab/R2019a scalasca/2.6-intel19-mpt225
eclipse/2020-09(default) horovod/0.25.0 matlab/R2019b singularity/3.7.2(default)
epcc/deprecated-software horovod/0.25.0-gpu matlab/R2020b(default) specfem3d/3.0(default)
epcc/setup-env htop/3.1.2 matlab/R2021b starccm+/13.06.012(default)
epcc/utils htop/3.2.1(default) metis/5.1.0 starccm+/13.06.012-R8
expat/2.2.9 ImageMagick/7.0.10-22(default) mpc/1.1.0 starccm+/14.04.013-R8
fenics/2019.1.0-intel-mpi intel-19.5/cc mpfr/4.0.2-intel starccm+/14.06.013-R8
fenics/2019.1.0-mpt intel-19.5/cmkl mpfr/4.0.2-mpt starccm+/15.02.009-R8
fftw/3.3.8-gcc8-ompi4 intel-19.5/compilers namd/2.14(default) starccm+/15.04.010-R8
fftw/3.3.8-intel18 intel-19.5/fc namd/2.14-gpu starccm+/15.06.008-R8
fftw/3.3.8-intel19(default) intel-19.5/itac namd/2.14-nosmp starccm+/16.02.009
fftw/3.3.9-impi19-gcc8 intel-19.5/mpi ncl/6.6.2 starccm+/2019.3.1-R8
fftw/3.3.10-intel19-mpt225 intel-19.5/pxse nco/4.9.3 starccm+/2020.1.1-R8
fftw/3.3.10-intel20.4 intel-19.5/tbb ncview/2.1.7 starccm+/2020.2.1-R8
flacs-cfd/20.1 intel-19.5/vtune netcdf-parallel/4.6.2-intel18-impi18 starccm+/2020.3.1-R8
flacs-cfd/20.2 intel-20.4/cc netcdf-parallel/4.6.2-intel19-mpt225 starccm+/2021.1.1
flacs-cfd/21.1 intel-20.4/cmkl ninja/1.10.2(default) strace/5.8(default)
flacs-cfd/21.2 intel-20.4/compilers nvidia/cudnn/8.2.1-cuda-11.6 svn/1.14.0(default)
flacs-cfd/22.1 intel-20.4/fc nvidia/cudnn/8.5.0-cuda-11.6 tensorflow/2.9.1-gpu
flacs/10.9.1 intel-20.4/itac nvidia/cudnn/8.6.0-cuda-11.6(default) tensorflow/2.10.0
flex/2.6.4 intel-20.4/mpi nvidia/nvhpc-byo-compiler/21.2 tmux/3.3a(default)
gaussian/16.A03(default) intel-20.4/psxe nvidia/nvhpc-byo-compiler/21.9 ucx/1.9.0
gcc/6.2.0 intel-20.4/tbb nvidia/nvhpc-byo-compiler/22.2 ucx/1.9.0-cuda-11.6
gcc/6.3.0 intel-20.4/vtune nvidia/nvhpc-nompi/22.2 udunits/2.2.26
gcc/8.2.0(default) intel-cc-18/18.0.5.274 nvidia/nvhpc/22.2 valgrind/3.16.1(default)
gcc/10.2.0 intel-cc-19/19.0.0.117 nvidia/tensorrt/7.2.3.4 vasp/5/5.4.4-intel19-mpt220(default)
gdal/2.1.2-gcc intel-cmkl-18/18.0.5.274 nvidia/tensorrt/8.4.3.1-u2 vasp/6/6.2.1-intel19-mpt220(default)
gdal/2.1.2-intel intel-cmkl-19/19.0.0.117 oneapi/2022.2.0(default) zlib/1.2.11(default)
gdal/2.4.4-gcc intel-compilers-18/18.05.274 openfoam/v8.0
gdal/2.4.4-intel intel-compilers-19/19.0.0.117 openfoam/v9.0
gdb/9.2(default) intel-fc-18/18.0.5.274 openfoam/v2006
--------------------------------------------------------- /usr/share/Modules/modulefiles ----------------------------------------------------------
dot hmpt/2.25 module-git module-info modules mpt/2.25 null perfboost use.own
Let’s take a closer look at the gcc
module. GCC is an extremely widely used
C/C++/Fortran compiler. Lots 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 four different versions: gcc/6.2.0
, gcc/6.3.0
, gcc/8.2.0
, gcc/10.2.0
. How do
we load each copy and which copy is the default?
In this case, gcc/8.2.0
has a (default)
next to it. This indicates that it
is the default - if we type module load gcc
, this is the copy that will be
loaded.
[yourUsername@cirrus-login1 ~]$ module load gcc
[yourUsername@cirrus-login1 ~]$ gcc --version
gcc (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
So how do we load the non-default copy of a software package? In this case, the
only change we need to make is be more specific about the module we are
loading. There are four GCC modules: gcc/6.2.0
, gcc/6.3.0
, gcc/8.2.0
and gcc/10.2.0
To load a non-default module, we need to make add the version number after the
/
in our module load
command
[yourUsername@cirrus-login1 ~]$ module load gcc/6.2.0
Loading gcc/6.2.0
ERROR: gcc/6.2.0 cannot be loaded due to a conflict.
HINT: Might try "module unload gcc" first.
What happened? The module command is telling us that we cannot have two gcc
modules loaded at the same time as this could cause confusion about which
version you are using. We need to remove the default version before we load the
new version.
[yourUsername@cirrus-login1 ~]$ module unload gcc
[yourUsername@cirrus-login1 ~]$ module load gcc/6.2.0
[yourUsername@cirrus-login1 ~]$ gcc --version
gcc (GCC) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
We now have successfully switched from GCC 8.2.0 to GCC 6.2.0.
As switching between different versions of the same module is often used you
can use module swap
rather than unloading one version before loading another.
The equivalent of the steps above would be:
[yourUsername@cirrus-login1 ~]$ module swap gcc gcc/8.2.0
[yourUsername@cirrus-login1 ~]$ gcc --version
gcc (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This achieves the same result as unload followed by load but in a single step.
Using Software Modules in Scripts
Create a job that is able to run
R --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@cirrus-login1 ~]$ nano R-module.sh [yourUsername@cirrus-login1 ~]$ cat R-module.sh
#!/bin/bash #SBATCH --partition=standard #SBATCH --qos=standard #SBATCH --time=00:01 module load R R --version
[yourUsername@cirrus-login1 ~]$ sbatch R-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.