Documentation and Information:Modules

From CompudocWiki
Jump to: navigation, search

Introduction

On Math/PACM systems we use Environment Modules (or just Modules) to setup various software packages for proper use on the command line. In particular you will have to use modules in order to start using Intel or PGI compilers, or to compile code with openmpi or mpich.

In essence Environment Modules gives the user the ability to easily modify their unix environment, making it easier to use software packages. No more setting shell environment variables, all the variables can by dynamically loaded to use a particular software package, including finding all the software's dependencies. You can use Environment Modules by running the module command.

How to use

To see all available modules, run module avail. For example:

[mathuser@math ~]$ module avail

------------ /usr/share/Modules/modulefiles ------------ 
dot         module-cvs  module-info modules     null        use.own     
------------ /usr/local/share/Modules/modulefiles ------------ 
mpich-debug/gcc/1.2.7p1/32        mpich/intel-9.1/1.2.7p1/32        
mpich-debug/intel-10.0/1.2.7p1/32 mpich/pgi-7.0/1.2.7p1/32          
mpich-debug/intel-9.1/1.2.7p1/32  openmpi/gcc/1.2.4/32              
mpich-debug/pgi-7.0/1.2.7p1/32    openmpi/intel-10.0/1.2.4/32       
mpich/gcc/1.2.7p1/32              openmpi/intel-9.1/1.2.4/32        
mpich/intel-10.0/1.2.7p1/32       openmpi/pgi-7.0/1.2.4/32          
------------ /opt/share/Modules/modulefiles ------------ 
intel/9.1/32/C/9.1.051         intel/10.0/32/Fortran/10.0.026 
intel/9.1/32/Fortran/9.1.051   intel/10.0/32/Iidb/10.0.026    
intel/9.1/32/Iidb/9.1.051      intel/10.0/32/default          
intel/9.1/32/default           pgi/7.0/32                     
intel/10.0/32/C/10.0.026       

To use a particular module, run module load modulename. You don't need to list the full name of the module, as listed above, if you only use the first component, it will choose the latest version for you. (It actually chooses the last item alphabetically.) For example:

[mathuser@math ~]$ module load openmpi 

To see what modules are loaded, run module list. For example:

[mathuser@math ~]$ module list
Currently Loaded Modulefiles:
 1) pgi/7.0/32                2) openmpi/pgi-7.0/1.2.4/32 

You can see from the above that the openmpi module automatically loaded OpenMPI built with the PGI compilers, because the letter 'p' comes after 'g' and 'i' in the alphabet. Also, the PGI OpenMPI requires the PGI compilers, so they were automatically loaded. If you had wanted to load the OpenMPI built with GCC, you simply run module load openmpi/gcc. If you want to load a specific version of the OpenMPI built with, say, the Intel compiler, run module load openmpi/intel/1.2.4.

Now that the openmpi module is loaded, you can run OpenMPI commands. For example:

[mathuser@math ~]$ which mpicc
/usr/local/openmpi/1.2.4/pgi70/i386/bin/mpicc
[mathuser@math ~]$ mpicc -o program program.c

To unload a module, run module unload modulename. For example:

[mathuser@math ~]$ module unload openmpi
[mathuser@math ~]$ module list
No Modulefiles Currently Loaded.

As you can see, the openmpi module has been unloaded, as well as all its dependencies.

To automatically load modules when you log in to a system, put the module load modulename command in your shell's startup script. For example, if your shell is bash, put the command in your ~/.bashrc, and if your shell is csh, put it in your ~/.cshrc. You can and should also use the module command in your SGE submission script, and it will automatically load the module when the job is run.