Introduction

Being a multiuser system by definition, a HPC cluster typically has much more software installed compared to a usual Desktop computer. Often these software packages are not installed in standard operating system paths and all software cannot be used simultaneously (conflicts, incompatibilities). A single software package or library may be installed in multiple different versions with different features enabled.

In order to manage all software, the Lmod (= Lua modules) module system is used. Lmod provides a convenient way to dynamically change a user's environment through modules. This includes easily adding or removing directories to/from environment variables (e.g. PATH, LD_LIBRARY_PATH, etc.) or simply defining necessary environment variables.

Basic Usage

Central to using the Lmod system is the module command. The is also the ml command for convenience which accepts all commands module does, plus a few even shorter versions of it.

Show module help
module help
Show all loaded modules
module list
ml
Show all available modules grouped by name
module overview
module ov
ml ov
Show all available modules
module avail
module av
ml av

# show all available modules containing string "cuda"
ml av cuda

This command gives you a list of all available packages and their corresponding flags. The following flags will be shown:

flagmeaning
(D)This is the default module
(O)Obsolete module. Avoid using it as it will be removed soon.
(g)

Build for usage with a GPU


Show all available modules with spider
# List all available modules (Level 0)
module spider
ml spider

# List all available modules containing "openmpi" (Level 1)
module spider openmpi
ml spider openmpi

# Show more details for the module specifying it full name (Level 2)
module spider openmpi/4.1.6
ml spider openmpi/4.1.6

The spider command not only shows all packages containing a specific string (openmpi in the example above), but also those which will only become available when another (dependent) module is loaded. This is typically the case when modules use a hierarchical order. 


Load one or more modules
module load pkg1 pkg2 
ml pkg1 pkg2  
Unload one or more modules
module unload pkg1 pkg2 
ml -pkg1 -pkg2  

The ml command even allows you to combine this: ml pkg1 -pkg2 (loads pkg1 and unloads pkg2)

Unload all modules
module purge
ml purge
Switch out two modules
module swap pkg1 pkg2 # short for module unload pkg1;module load pkg2
ml sw pkg1 pkg2
Switch out two modules
module swap pkg1 pkg2 # short for module unload pkg1;module load pkg2
ml sw pkg1 pkg2
Show Software categories available
module category
module cat
ml cat
Show Software availabe in a specific categories
module category lib
module cat lib
ml cat lib
  • Most modules have no category at the moment.

Using Lmod in SBATCH scripts

In sbatch-scripts, all values and modules in your environment will be propagated to your script and application. While this might seem a good thing at first, this often creates hard to debug errors or conflicts.

It is therefore recommended to purge all modules in your sbatch-script and then load all the modules needed by your program. A sbatch-script should therefore typically look like this:

#!/usr/bin/env bash

#SBATCH ...

module purge
module load pkg1 pkg2

# Then run your programm
srun program

Specifying which version of a module to load

Lmod allows you to load modules with varying specificity.

If only the base name (shortName) is specified, then Lmod will load either the module with the highest version or the module marked as default by the HPC-Team.

module load cuda

You can also increase specificity by providing the major version, the major+minor version or (if existent) the major+minor+bugfix version to load a module. In the first two cases, Lmod will automatically load the highest version compatible.

module load cuda/12
module load cuda/12.1
module load cuda/12.1.1

Disabling Lmod

If you want to disable lmod from being loaded automatically for personal reasons simply create a signaling file in your home directory.

touch ~/.lmod_off

The next time you login, Lmod will not be available.

Alternatively, you can use the clearLmod command to clear all Lmod variables, modules and functions from your environment.