Modulefiles

Environment modules are a simple way of streamlining what specific programs and environment variables you want set on your shell.

Upon login to the cluster, you will have a bare minimum of resources such as a simple compiler, or the usual text editors. You can use environment modules to have access to more tools that are available and provided for by the HPC Cluster. Also, if provided by the cluster, modulefiles can help you use older versions of programs for compatibility purposes simply by loading the modulefile.



Useful Commands

  • module avail
    This command lists down all the available modules that you can utilize.
    Example:
    [user@hpc ~]$ module avail
    -----------------------------/opt/hpc/modulefiles/-----------------------------
    intel/2014        mvapich/2.2          openmpi/1.8.4          openmpi/1.6.1   
    slurm/14.11.4     torque/5.1.0
    
  • module whatis
    This command can be used to query what the modules can provide.
    Example:
    [user@hpc ~]$ module whatis
    intel/2014             : gives access to the intel compilers (icc, ifort, etc.) and mkl library
    mvapich/2.2            : loads the MVAPICH2 mpi toolset for MPI programming
    openmpi/1.8.4          : loads the OpenMPI 1.8.4 mpi toolset for MPI programming
    openmpi/1.6.1          : loads the OpenMPI 1.6.1 mpi toolset for MPI programming
    slurm/14.11.4          : adds the Slurm resource manager for interaction with cluster
    torque/5.1.0           : adds the Torque resource manager for interaction with cluster
    
    [user@hpc ~]$ module whatis mvapich/2.2
    mvapich/2.2            : loads the MVAPICH2 mpi toolset for MPI programming
    
    
  • module load modulefile
    To load a certain module into your environment, use this function.
    Example:
    [user@hpc ~]$ mpicc
    bash: mpicc: command not found
    [user@hpc ~]$ module load openmpi/1.8.4
    [user@hpc ~]$ mpicc
    mpicc: fatal error: no input files
    compilation terminated.
  • module unload modulefile
    The unloading counterpart for module load.
    Example:
    [user@hpc ~]$ mpicc
    mpicc: fatal error: no input files
    compilation terminated.
    [user@hpc ~]$ module unload openmpi/1.8.4
    [user@hpc ~]$ mpicc
    bash: mpicc: command not found
  • module list
    This command lists down the modules that you already have loaded into your shell in the order that you have loaded them.
    Example:
    [user@hpc ~]$ module list
    Currently Loaded Modulefiles:
      1) intel/2014  2) mvapich/2.2
    [user@hpc ~]$ module load slurm/14.11.4
    [user@hpc ~]$ module unload intel/2014
    [user@hpc ~]$ module list
      1) mvapich/2.2  2) slurm/14.11.4
    
  • module purge
    This unloads all modulefiles from your environment.
    Example:
    [user@hpc ~]$ module list
    Currently Loaded Modulefiles:
      1) intel/2014  2) mvapich/2.2  3) intel/2014
    [user@hpc ~]$ module purge
    [user@hpc ~]$ module list
    No Modulefiles Currently Loaded.
    


Tips on Modulefiles

  1. Modulefiles can not only load executables but also libraries, man pages and set shell variables! If available, you can see what explicit variables are set or modified by invoking:
    module help "modulefile"
  2. If there are conflicting variables between modules that are loaded with the system or other modulefiles, the priority will be given to the last modulefile that is loaded.
    Example:
    [user@hpc ~]$ gcc --version
    gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
    Copyright (C) 2010 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.   There is NO
    warranty; not even for MERCHANTABILITIY or FITNESS FOR A PARTICULAR PURPOSE.
    
    [user@hpc ~]$ module load gcc/4.9.2
    [user@hpc ~]$ gcc --version
    gcc (GCC) 4.9.2 20141030 (Red Hat 4.4.7-11)
    Copyright (C) 2014 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.   There is NO
    warranty; not even for MERCHANTABILITIY or FITNESS FOR A PARTICULAR PURPOSE.
    


Modulefiles and Job Scripts

When submitting a job script, it is important to specify within the job script the modules you need to use to run your program. Otherwise, the jobs will run on default shells without your preferred modules and may fail.

[user@hpc ~]$ cat jobscript.sh
#!/bin/sh
#SBATCH --time=00:10:00
#SBATCH --job-name=jobscript
#SBATCH --ntasks=40

module load openmpi
mpirun -np 40 ./mpi_application
[user@hpc ~]$ sbatch jobscript.sh

In this example, if module load openmpi was not specified, the job will be sent to shells without any knowledge of the mpirun program and the run will fail.



Space.PNG (148 Bytes) Glenda Mae Baldonado, 10/13/2016 10:02 AM