Creating a module
A module file describes the environment that is associated to an application. Using this file you can for example add, using just one command, new access paths to the $PATH environment variable or add library paths to $LD_LIBRARY_PATH.
Module files are written in the Tool Command Language (TCL). However, you do not need to know this language to write one, because only a small subset of commands suffices.
Warning! When you create your own modules, you must specify the complete path to those modules when you load them. For example, if you have a module named ~/modulefiles/apps/myapp/1.0.0, you can load it as follows:
[name@server $] module load /home/user/modulefiles/apps/myapp/1.0.0
. You can omit this complexity if you add the directory /home/user/modulefiles to the environment variable $MODULEPATH. To do this, use the module sub-command 'use:
[name@server $] module use /home/user/modulefiles/
If you use modules automatically, you can put this command at the start of your ~/.modules file. Do not put it in your .bashrc file because when you start a session the .modules file is read before the .bashrc file is ran.
A module file's contents are simple enough, a good starting point is to take an existing file as an example and to modify the variables it contains to adapt it to the module that you would wish to install:
Let us consider this example in detail. This file start with a comment (lines starting with the number sign #), which specifies that it is a module using format 1.0. Other comments show that this is a module for the MPI library OpenMPI. The actual module then starts by defining a function, ModulesHelp. This function is then called when a user runs the following command:
[name@server $] module help mpi/openmpi/1.6.3_intel
This command outputs the message "Adds the OpenMPI library to your environment." to standard error.
Note : All messages that are displayed by the module command use standard error (stderr) instead of standard output (stdout).
The module then continues with a list of commands including the following:
|module-whatis||Allows for a more elaborate description of the module, which is shown using module whatis module_name.|
|conflict||Specifies that this module cannot be loaded if the given module was already loaded.|
|prereq||Specifies a pre-required module.|
|set||Defines a variable that is internal to the module.|
|prepend-path||Prefix an environment variable of the type PATH using the specified path.|
|setenv||Defines an environment variable.|
The above module defines a detailed description using the module-whatis command. Following that, it specifies that the module cannot be loaded together with another mpi module, that means that only one mpi module can be loaded at the same time. After that, it specifies that the Intel compiler, version 2013, is required.
After that, the module adds some directories to various environment variables, and finally defines a new environment variable (an OpenMPI control parameter in this case).