Skip to content

Environment Modules

Environment Modules provide an easy way to tailor a user's environment to use various software.[1] In contrast to login scripts and shell scripts, modulefiles allow for easy unsetting of modifications. Modulefiles are also shell-independent, obviating the need for separate environment-changing scripts for each shell.

Basic Usage

View available modulefiles

[juser@picotte001]$ module avail

View loaded modulefiles

[juser@picotte001]$ module list Currently Loaded Modulefiles: 1) shared      2) DefaultModules     3) gcc/9.2.0     4) slurm/picotte/21.08.8

Load a modulefile

To use a particular software package, load its modulefile:

[juser@picotte001]$ module load fftw3/intel/2020/3.3.9

or

[juser@picotte001]$ module load fftw3/intel/2020

or

[juser@picotte001]$ module add fftw3/intel/2020

If the version string is not specified, the latest one will be loaded.

Then, view the loaded modules:

[juser@picotte001]$ module list Currently Loaded Modulefiles: 1) shared                          4) slurm/picotte/21.08.8 2) DefaultModules                  5) fftw3/intel/2020/3.3.9 3) gcc/9.2.0

Unload a modulefile

[juser@picotte001]$ module unload fftw3/intel/2020

or

[juser@picotte001]$ module rm fftw3/intel/2020

Show what modifications a modulefile will make

[juser@picotte001]$ module display fftw3/intel/2020
-----------------------------------------------------------------------------------------------------
   /ifs/opt/modulefiles/fftw3/intel/2020/3.3.10.lua:
-----------------------------------------------------------------------------------------------------
conflict("fftw")
conflict("fftw3")
try_load("intel/composerxe/2020u4")
whatis("Adds FFTW3 3.3.10 (Intel) to your environment ")
help([[ Adds FFTW3 (Intel) to your environment
]])
setenv("FFTW3DIR","/ifs/opt/fftw3/intel/2020/3.3.10")
prepend_path("PATH","/ifs/opt/fftw3/intel/2020/3.3.10/bin")
prepend_path("LD_LIBRARY_PATH","/ifs/opt/fftw3/intel/2020/3.3.10/lib")
prepend_path("LD_RUN_PATH","/ifs/opt/fftw3/intel/2020/3.3.10/lib")
prepend_path("MANPATH","/ifs/opt/fftw3/intel/2020/3.3.10/share/man")
prepend_path("INFOPATH","/ifs/opt/fftw3/intel/2020/3.3.10/share/info")
prepend_path("PKG_CONFIG_PATH","/ifs/opt/fftw3/intel/2020/3.3.10/lib/pkgconfig")

Switch one module for another

NB Intel Composer XE is Intel's compiler, gcc is the GNU compiler.

[juser@picotte001]$ module list
Currently Loaded Modules:
  1) shared           3) gcc/9.2.0               5) default-environment
  2) DefaultModules   4) slurm/picotte/21.08.8
[juser@picotte001]$ module switch gcc intel/composerxe
[juser@picotte001]$ module list
Currently Loaded Modules:
  1) shared           3) slurm/picotte/21.08.8   5) intel/composerxe/2020u4
  2) DefaultModules   4) default-environment

Online help

[juser@picotte001]$ module help

Creating Your Own Module Files

Instructions here are for the older Tcl-based modules on Proteus. (Tcl, pronounced "tickle" is a scripting language.[2]) Module files on Picotte use the newer Lua-based Lmod,[3] which also accepts Tcl-based module files. Lua is another scripting language.[4]

Creating your own module files[5] will be useful for getting your group members to all use the same version of software. As outlined above, module files are a much better solution than modifying login scripts as any changes to environment variables, etc, need only be made to the module file rather than each user's login script.

Add a New modulefiles Location

We suggest creating a directory within your group directory:

/ifs/groups/myresearchGrp/opt/modulefiles

Then, make sure each user has the following line in their login script (~/.bashrc) to add your group's modulefiles directory to the module search path:

module use --append /ifs/groups/myresearchGrp/opt/modulefiles

All modulefiles that your group creates should be put in that directory.

If you would like your modulefiles to take precendence over all system-installed ones, use the --prepend option, instead.

This should be done within job scripts, as well.

Module File Naming Convention

To avoid confusion over which module is to be loaded by the "module load" command, we suggest you name your modulefiles tagged with your group name. For example, if you have Python 3.3 installed, you would create the modulefile

/ifs/groups/myresearchGrp/opt/modulefiles/myresearchGrp-python33

The contents of that file may be something like:

#%Module -*- tcl -*-
##
## myresearchGrp-python33 modulefile
## /mnt/HA/groups/myresearchGrp/opt/modulefiles/myresearchGrp-python33
##
proc ModulesHelp {} {
  global pythonversion

  puts stderr "\tAdds Python 3.3 (myresearchGrp) to your environment"
}

module-whatis "Adds Python 3.3 (myresearchGrp) to your environment"

set          pythonversion 3.3
set          prefix        /ifs/groups/myresearchGrp/opt

prepend-path PATH            $prefix/bin
prepend-path LD_LIBRARY_PATH $prefix/lib
prepend-path MANPATH         $prefix/share/man

In Lua, modulefile names must end with ".lua". Example:

-- -*- lua -*-
-- myresearchGrp-python39 modulefile
-- /ifs/groups/myresearchGrp/opt/modulefiles/myresearchGrp-python39.lua

local version = "3.9.1"
local prefix  = "/ifs/groups/myresearchGrp/opt/python/" .. version

whatis("Adds Python " .. version .. " to your environment")
help([[ Adds Python to your environment
]])

conflict("python")
conflict("python3")
conflict("python37")

prereq("gcc/9.2.0")

prepend_path("PATH", prefix .. "/bin")
prepend_path("LD_LIBRARY_PATH", prefix .. "/lib")
prepend_path("MANPATH", prefix .. "/share/man")

References

[1] Environment Modules Project website

[2] Tcl Website

[3] Lmod: A New Environment Module System

[4] Lua Programming Language

[5] modulefile(4) man page (also available with the "man modulefile" command on any login node)