Kahibaro
Discord Login Register

Environment modules

What Environment Modules Are in an HPC Context

On HPC systems, you rarely install software yourself into system directories. Instead, many versions of compilers, MPI stacks, math libraries, and applications are pre-installed and exposed through environment modules.

An environment module is a small configuration file that, when loaded, modifies your shell environment (e.g. PATH, LD_LIBRARY_PATH) so that a particular software stack becomes available. The most common implementations are Environment Modules and Lmod, but from a user’s perspective they behave similarly and are driven by the module command.

Key ideas:

Modules are central to how software environments are managed on clusters and supercomputers.

Basic `module` Command Usage

Most systems provide a module command that works similarly across sites.

Common subcommands:

Examples:

# List all modules that are currently loaded in your session
module list
# See what modules are available (may be long)
module avail
# Search for modules whose name or description contains "fft"
module spider fft
# Load a specific compiler and MPI stack
module load gcc/12.1.0
module load openmpi/4.1.5
# Unload a module
module unload openmpi/4.1.5
# Remove all currently loaded modules
module purge
# Inspect what environment changes a module will apply
module show openmpi/4.1.5

Exact syntax may vary slightly depending on your system, but this pattern is widespread.

How Modules Modify Your Environment

When you module load something, several environment variables are typically adjusted:

A simplified view:

Then when you type gcc, the system finds /path/to/gcc/12.1.0/bin/gcc first.

Inspect with:

module show gcc/12.1.0

This will print operations like:

You normally do not need to modify these variables manually; rely on modules instead.

Module Naming Conventions and Hierarchies

HPC sites use naming schemes to manage complexity. You will commonly see:

Larger systems often use module hierarchies:

This hierarchical approach reduces conflicts and keeps you from mixing incompatible components.

Managing Conflicts and Incompatible Modules

Modules that cannot be used together may conflict. Common patterns:

If a conflict arises, you might see a message like:

$ module load intel/2023.1
Lmod has detected the following error:  These module(s) exist but cannot be loaded ...
   "intel/2023.1" is not compatible with the currently loaded "gcc/12.1.0"

Typical resolutions:

  module purge
  module load intel/2023.1
  module load impi/2021.9
  module unload gcc/12.1.0
  module load intel/2023.1

To avoid confusion, keep your environment minimal: load only what you need.

Typical Usage Patterns in Day-to-Day Work

In a normal HPC session, your workflow might look like:

  1. Start from a clean environment:
   module purge
  1. Load a compiler (and optionally a toolchain):
   module load gcc/12.1.0
   # or a bundle/toolchain
   module load foss/2022a
  1. Load MPI and libraries (often part of the toolchain, but sometimes separate):
   module load openmpi/4.1.5
   module load fftw/3.3.10
   module load hdf5/1.12.2-mpi
  1. Compile your application using the compilers and libraries from the loaded modules.
  2. Record loaded modules for reproducibility (see below).

You might use different module combinations for different projects, compilers, or architectures.

Saving and Restoring Module Environments

To ensure you can later recreate a working setup, you should save the module state or at least document it.

Saving a list manually

Simple and robust:

module list

Copy the output into your notes, a README, or your job script as comments.

Using built-in save/restore (if available)

Many systems with Lmod offer environment collections:

  module save myproject-env
  module savelist
  module restore myproject-env

This reloads the same module set in new sessions, which is particularly useful for long-lived projects.

Using Modules in Shell Startup Files

To avoid typing the same module load commands repeatedly, you might add some to your shell startup file (e.g. ~/.bashrc, ~/.bash_profile, ~/.profile), but there are trade-offs.

Example

In ~/.bashrc:

# Minimal default environment
module purge
module load gcc/12.1.0
module load openmpi/4.1.5

This ensures that interactive logins start with a consistent baseline.

Pros

Cons / caveats

A common best practice for HPC is:

Modules Inside Job Scripts

On HPC systems, batch job scripts (e.g. for SLURM) should explicitly define the software environment they need, so that:

A typical job script fragment:

#!/bin/bash
#SBATCH --job-name=myjob
#SBATCH --time=01:00:00
#SBATCH --nodes=1
#SBATCH --ntasks=4
# Start from a clean environment
module purge
# Load exactly the modules needed for this job
module load gcc/12.1.0
module load openmpi/4.1.5
module load hdf5/1.12.2-mpi
# Optionally record for debugging:
module list
# Compile or run your program
srun ./my_program

Key points:

Site-Specific Module Collections and Defaults

Many HPC centers define system-wide module collections or default environments:

Things to be aware of:

Discovering and Searching for Software

When you need a piece of software but don’t know whether it’s available:

  1. Try module avail with a substring:
   module avail fftw
   module avail cuda
   module avail python
  1. Use module spider (Lmod):
   module spider gromacs
   module spider mumps

This often shows:

  1. If you can’t find a package:
    • Check system documentation or a site-specific software list.
    • Contact the support team; they may:
      • Tell you which module provides it under a non-obvious name.
      • Install it for you.
      • Suggest alternatives.

Best Practices for Working with Modules

To use environment modules effectively on HPC systems:

  1. Be explicit in scripts:
    • Always load required modules in your job scripts.
    • Prefer module purge at the start of scripts for cleanliness.
  2. Keep environments simple:
    • Load only what you need.
    • Avoid mixing multiple compilers or MPI libraries in the same environment.
  3. Record your setup:
    • Copy module list output into logs or README files.
    • Use module save if your site supports it.
  4. Avoid hidden magic:
    • Don’t rely heavily on complex startup files that automatically load many modules.
    • Be wary of blindly copying someone else’s module load sequence without understanding it.
  5. Use site documentation:
    • Many centers have recommended module sets for particular applications or workflows.
    • Follow their examples as starting points.

Environment modules are the primary tool for managing software on HPC clusters; mastering basic module commands and practices is essential for building, running, and reproducing scientific applications in this environment.

Views: 15

Comments

Please login to add a comment.

Don't have an account? Register now!