Thursday, December 15, 2016

Setting up environment modules

Note: please use Lmod instead. It is a newer project that is backward compatible, but also makes some nice improvements. It is used on many supercomputer systems. See my next article.

The environment modules project is an ideal way to set up (albeit mostly manually) your environment for multiple packages. This is a quick guide on setting it up.
First, install the environment-modules (CentOS) package with yum. You’ll also need to initialize it in the bashrc file, I chose to add source /usr/share/Modules/init/bash (and optionally bash_completion) to /etc/bashrc instead of running /usr/share/Modules/bin/add.modules, but if you only want it locally, that’s also an option.
To set up a module file, you want something like this, for example /usr/share/Modules/modulefiles/cuda/8.0:
#%Module1.0
proc ModulesHelp { } {
        global version prefix name
        puts stderr "$name/$version - loads the environment for $name, in $prefix"
}

set     name      cuda
set     version   8.0

module-whatis   "loads the $name environment"

set prefix /usr/local/cuda-$version

prepend-path     LD_LIBRARY_PATH     $prefix/lib64
prepend-path     PATH                $prefix/bin
You can generate the meat of this file by doing, for example for ROOT:
/usr/share/Modules/bin/createmodule.py /opt/root-6.08.02/bin/thisroot.sh > /usr/share/Modules/modulefiles/root/6.08.02
You can remove most or all the default modules - and yes you’ll need to make modules for each package. The “spider” search does not seem to be in the standard modules package.
Note: I used http://dillinger.io to generate the this page.