Creating Your Own Environment Modules

Environment modules make it easy to use pre-installed software by updating the appropriate environment variables. The module avail command shows the environment modules that are provided by Research Computing on a given cluster. This page shows how to write your own environment modules that work in the same way as the system modules.


Creating a Module for Your Own Work

There are two steps required to create your own custom module: (1) write a module file and (2) add a line to your ~/.bashrc file to update the MODULEPATH.

Let's create a new custom module that will be loaded with:

module load solar/1.2

Step 1: Create the module file

First, create a path to store the module file. The path must contain /Modules/modulefiles/ and should have the general form /<path/to>/Modules/modulefiles/<module-name>/<version> where <version> is typically numerical and is the actual module file. Below is a set of example commands for doing this. First, create the path:

$ mkdir -p /home/aturing/Modules/modulefiles/solar

Next, create the module file and save it in the solar directory:

$ cd /home/aturing/Modules/modulefiles/solar
# use a text editor to create the module file called 1.2 (which is the version)
$ cat 1.2

proc ModulesHelp { } {
   puts stderr "This module adds solar to your path"
module-whatis "This module adds solar to your path\n"

set basedir "/home/aturing/software/solar-1.2"
prepend-path PATH "${basedir}/bin"
prepend-path LD_LIBRARY_PATH "${basedir}/lib64"
module load intel/19.1/64/
module load intel-mpi/intel/2019.7/64

The example module file above (with filename 1.2) sets two environment variables and loads two system modules.

Module files are written in the Tcl language. Most people find it best to write new module files based on examples. The module avail command shows the paths to the module files on a given cluster. Try looking in these paths for examples: /usr/local/share/Modules/modulefiles, /opt/share/Modules/modulefiles and /usr/licensed/Modules/modulefiles.

You will see that most modules update the PATH and LD_LIBRARY_PATH. Note that you can load system environment modules within your own module file if needed.

Step 2: Add the module path to MODULEPATH

Now that the module file has been created, one just needs to add the following line to your ~/.bashrc file so that it will be found:

module use --append /home/aturing/Modules/modulefiles

The next time you log in you will be able to run module avail or module load on the new module.


Creating a Module for a Group

If you have software in /tigress/<NAME> or /projects/<NAME> and you would like to make a module that group members (based on Unix group) can use then follow the directions above but with the base path /tigress/<NAME>/Modules/modulefiles-shared/ and skip step 2.

Below are a set of example commands:

$ mkdir -p /tigress/ATURING/Modules/modulefiles-shared/solar
$ cd /tigress/ATURING/Modules/modulefiles-shared/solar
# use a text editor to create the module file called 1.2 (which is the version)

No changes are needed to ~/.bashrc in this case. The module will be found by all group members on their next log in. The details of how this works can be seen by looking in /etc/profile.d/