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@aim1 ~]$ module avail
------------------------------------- /shared/software/modules -----------------------------------------------------
anaconda3 nvhpc-nompi/21.9 (D) parabricks/3.8.0-1.ampere (D)
rstudio_singularity/3.6.2 (D)
nvhpc/21.9 (D) parabricks/3.7.0-1.ampere-EXPIRE python3
nvhpc-byo-compiler/21.9 (D) parabricks/3.7.0-1.ampere-extra-tools rstudio_singularity/not-test-yet
--------------------------- /shared/software/software/hpc-sdk/modulefiles ------------------------------------------
nvhpc/21.9 nvhpc-byo-compiler/21.9 nvhpc-nompi/21.9
Where:
D: Default Module
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@aim1 ~]$ 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, default system Python 3 is 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@aim1 ~]$ which python3 --version
/usr/bin/python3
We can load new version of python3
command with module load
:
[yourUsername@aim1 ~]$ module load python3
[yourUsername@aim1 ~]$ which python3
/shared/software/anaconda3/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@aim1 ~]$ echo $PATH
/cvmfs/soft.computecanada.ca/nix/var/nix/profiles/python-3.5.2/bin:/opt/software/slurm/16.05.9/bin:/cvmfs/soft.computecanada.ca/easybuild/software/2017/avx2/Compiler/intel2016.4/openmpi/2.1.1/bin:/cvmfs/soft.computecanada.ca/easybuild/software/2017/Core/imkl/11.3.4.258/mkl/bin:/cvmfs/soft.computecanada.ca/easybuild/software/2017/Core/imkl/11.3.4.258/bin:/cvmfs/soft.computecanada.ca/nix/var/nix/profiles/gcc-5.4.0/bin:/opt/software/bin:/opt/puppetlabs/puppet/bin:/opt/software/slurm/current/bin:/opt/software/slurm/bin:/cvmfs/soft.computecanada.ca/easybuild/bin:/cvmfs/soft.computecanada.ca/nix/var/nix/profiles/16.09/bin:/cvmfs/soft.computecanada.ca/nix/var/nix/profiles/16.09/sbin:/cvmfs/soft.computecanada.ca/custom/bin:/opt/software/slurm/current/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/yourUsername/.local/bin:/home/yourUsername/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@aim1 ~]$ ls /cvmfs/soft.computecanada.ca/nix/var/nix/profiles/python-3.5.2/bin
2to3 idle3.5 pydoc3.5 python3.5m virtualenv
2to3-3.5 pip python python3.5m-config wheel
easy_install pip3 python3 python3-config
easy_install-3.5 pip3.5 python3.5 pyvenv
idle3 pydoc3 python3.5-config pyvenv-3.5
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@aim1 ~]$ module list
Currently Loaded Modules:
1) python3
tungmay@k8smaster1:~/.workshop$ module av
--------------------------------------------------------------- /shared/software/modules --------------------------------------
anaconda3 nvhpc-nompi/21.9 (D) parabricks/3.8.0-1.ampere (D) rstudio_singularity/3.6.2 (D)
nvhpc/21.9 (D) parabricks/3.7.0-1.ampere-EXPIRE python3 (L)
nvhpc-byo-compiler/21.9 (D) parabricks/3.7.0-1.ampere-extra-tools rstudio_singularity/not-test-yet
----------------------------------------------------- /shared/software/software/hpc-sdk/modulefiles ---------------------------
nvhpc/21.9 nvhpc-byo-compiler/21.9 nvhpc-nompi/21.9
Where:
L: Module is loaded
D: Default Module
Use "module spider" to find all possible modules.
Use "module keyword key1 key2 ..." to search for all possible modules matching any of the "keys".
[yourUsername@aim1 ~]$ module load parabricks/3.8.0-1.ampere
[yourUsername@aim1 ~]$ module list
Currently Loaded Modules:
1) python3 2) parabricks/3.8.0-1.ampere
So in this case, loading the parabricks
module (genomic analysis applications
), also loaded python3
as well. Let’s
try unloading the parabricks
package.
[yourUsername@aim1 ~]$ module unload parabricks/3.8.0-1.ampere
[yourUsername@aim1 ~]$ module list
Currently Loaded Modules:
1) python3
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).
[yourUsername@aim1 ~]$ module purge
No modules loaded
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).
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@aim1 ~]$ module avail
------------------------------------- /shared/software/modules -----------------------------------------------------
anaconda3 nvhpc-nompi/21.9 (D) parabricks/3.8.0-1.ampere (D)
rstudio_singularity/3.6.2 (D)
nvhpc/21.9 (D) parabricks/3.7.0-1.ampere-EXPIRE python3
nvhpc-byo-compiler/21.9 (D) parabricks/3.7.0-1.ampere-extra-tools rstudio_singularity/not-test-yet
--------------------------- /shared/software/software/hpc-sdk/modulefiles ------------------------------------------
nvhpc/21.9 nvhpc-byo-compiler/21.9 nvhpc-nompi/21.9
Where:
D: Default Module
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 parabricks
module. Nvidial Parabricks is an extremely widely used.
NVIDIA® Parabricks® is the only GPU-accelerated suite of genomic analysis applications
that delivers fast and accurate analysis of genomes.
It might not run if the wrong version is loaded on specific GPU architecture. In this case, there
are two different versions: parabricks/3.8.0-1.ampere
and parabricks/3.7.0-1.ampere-extra-tools
. How do we load each
copy and which copy is the default?
In this case, parabricks/3.8.0-1.ampere
has a (D)
next to it. This indicates that it is the
default — if we type module load parabricks
, this is the copy that will be
loaded.
[yourUsername@aim1 ~]$ module load parabricks
[yourUsername@aim1 ~]$ pbrun --version
Please visit https://docs.nvidia.com/clara/#parabricks for detailed documentation
pbrun: 3.8.0-1.ampere
Note that three things happened: the default copy of parabricks
was loaded (version
3.8.0-1.ampere)
system turned what might be a super-complex operation into a single command.
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 three parabricks
modules: parabricks/3.8.0-1.ampere
and parabricks/3.7.0-1.ampere-EXPIRE
and parabricks/3.7.0-1.ampere-extra-tools
. To load a
non-default module, the only change we need to make to our module load
command is to leave in the version number after the /
.
[yourUsername@aim1 ~]$ module load parabricks/3.7.0-1.ampere-extra-tools
[yourUsername@aim1 ~]$ pbrun --version
The following have been reloaded with a version change:
1) parabricks/3.8.0-1.ampere => parabricks/3.7.0-1.ampere-extra-tools
We now have successfully switched from parabricks/3.8.0-1.ampere
to parabricks/3.7.0-1.ampere-extra-tools
.
Please visit https://docs.nvidia.com/clara/#parabricks for detailed documentation
pbrun: 3.7.0-1.ampere
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@aim1 ~]$ nano python-module.sh [yourUsername@aim1 ~]$ cat python-module.sh
#!/usr/bin/env bash module load python3 python3 --version
[yourUsername@aim1 ~]$ 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.