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 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 load the ansys
module and then use the module list
command to show which modules we currently have loaded in our environment.
(ANSYS is an engineering simulation product.)
[yourUsername@login12 ~]$ module load ansys
ansys/2019.r3(73):ERROR:151: Module 'ansys/2019.r3' depends on one of the
module(s) 'giflib/5.1.1'
ansys/2019.r3(73):ERROR:102: Tcl command execution failed:
prereq giflib/5.1.1
This shows that the default ansys
module will not run because it first needs
giflib/5.1.1
to be loaded. Some HPC systems will automatically load
dependencies like this, but at the time of writing (June 2020) UCL’s Myriad
does not.
Let’s load the giflib
module:
[yourUsername@login12 ~]$ module load giflib
giflib/5.1.1(18):ERROR:151: Module 'giflib/5.1.1' depends on one of the
module(s) 'gcc-libs/4.9.2'
giflib/5.1.1(18):ERROR:102: Tcl command execution failed: prereq gcc-libs
Here, we see that the giflib
module itself also has a dependency, gcc-libs
.
So we have to load that first, then load giflib
, and then finally load
ansys
.
[yourUsername@login12 ~]$ module load gcc-libs/4.9.2
[yourUsername@login12 ~]$ module load giflib/5.1.1
[yourUsername@login12 ~]$ module load ansys
~/Scratch/.config is configured
...
...
~/.mw doesn't exist - creating
If you now use the module list
command, you should see these three modules
included in the list.
To unload a specific module, e.g. ansys
, run the command
module unload ansys
. (On some systems, this will also unload the modules it
depends on. Currently this is not the case with Myriad.)
If we wanted to unload everything at once (all modules), we could run
module purge
(unloads everything).
[yourUsername@login12 ~]$ module purge
[yourUsername@login12 ~]$ module list
No Modulefiles Currently Loaded.
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/full/r2019b/9.7(99):ERROR:151: Module 'matlab/full/r2019b/9.7'
depends on one of the module(s) 'gcc-libs/4.9.2'
matlab/full/r2019b/9.7(99):ERROR:102: Tcl command execution failed:
prereq gcc-libs
Here, we see that the default version of Matlab on the system is r2019b/9.7, 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.
[yourUsername@login12 ~]$ module purge
[yourUsername@login12 ~]$ module list
No Modulefiles Currently Loaded.
[yourUsername@login12 ~]$ module load matlab/full/r2017a/9.2
matlab/full/r2017a/9.2(96):ERROR:151: Module 'matlab/full/r2017a/9.2' depends
on one of the module(s) 'gcc-libs/4.9.2'
matlab/full/r2017a/9.2(96):ERROR:102: Tcl command execution failed:
prereq gcc-libs
[yourUsername@login12 ~]$ module load gcc-libs/4.9.2
[yourUsername@login12 ~]$ module load matlab/full/r2017a/9.2
matlab/full/r2017a/9.2(97):ERROR:151: Module 'matlab/full/r2017a/9.2' depends
on one of the module(s) 'xorg-utils/X11R7.7'
matlab/full/r2017a/9.2(97):ERROR:102: Tcl command execution failed:
prereq xorg-utils/X11R7.7
[yourUsername@login12 ~]$ module load xorg-utils/X11R7.7
[yourUsername@login12 ~]$ module load matlab/full/r2017a/9.2
~/.matlab is a symbolic link pointing to /home/yourUsername/Scratch/.matlab
Matlab setup complete type matlab to start Matlab.
[yourUsername@login12 ~]$ matlab -nodisplay -nosplash -nodesktop
< M A T L A B (R) >
Copyright 1984-2017 The MathWorks, Inc.
R2017a (9.2.0.556344) 64-bit (glnxa64)
March 27, 2017
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
>> quit
Note that you cannot load two different versions of the same software at once.
Currently, we have loaded matlab/full/r2017a/9.2
. Let’s try also loading
matlab/full/r2015b/8.6
:
[yourUsername@login12 ~]$ module load matlab/full/r2015b/8.6
matlab/full/r2015b/8.6(108):ERROR:150: Module 'matlab/full/r2015b/8.6'
conflicts with the currently loaded module(s) 'matlab/full/r2017a/9.2'
matlab/full/r2015b/8.6(108):ERROR:102: Tcl command execution failed:
conflict matlab
As we can see, we get an error message about conflicts. If we do indeed wish to load version r2015b/8.6, we can say
[yourUsername@login12 ~]$ module unload matlab/full/r2017a/9.2
[yourUsername@login12 ~]$ module load matlab/full/r2015b/8.6
or, in one step:
[yourUsername@login12 ~]$ module swap matlab matlab/full/r2015b/8.6
Check that this module has been loaded:
[yourUsername@login12 ~]$ module list
Currently Loaded Modulefiles:
1) gcc-libs/4.9.2 9) gerun 17) userscripts/1.4.0
... ... ...
6) apr-util/1.5.4 14) emacs/24.5 22) xorg-utils/X11R7.7
7) subversion/1.8.13 15) tmux/2.2 23) matlab/full/r2015b/8.6
8) screen/4.2.1 16) mrxvt/0.5.4
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.