Using Environment Modules
Environment Modules are a useful resource for allowing users to control their Linux environment by loading and unloading modules to modify environment variables. This allows users flexibility in controlling which version of a specific software package will be used when compiling or running a program. Below is a list of common commands for using modules.
Command |
Use |
module avail |
lists all available modules |
module avail <software package> |
shows all available versions of a specific software package |
module display <module> |
shows all the commands executed by specified module |
module load <module> |
loads a software module |
module unload <module> |
unloads a software module |
module switch <module 1> <module 2> |
unloads module 1 and loads module 2 |
module list shows all |
currently loaded modules |
Environment Modules Example
Imagine you wish to compile a C program written with mpi using the compiler mpicc. To see what implementations of mpi are available use the command module avail:
[shesprich@vs-bcmshane ~]$ module avail
----------------------------- /cm/local/modulefiles ------------------------------
cluster-tools/9.0 cmsh luajit python37
cm-image/9.0 dot module-git shared
cm-scale/cm-scale.module freeipmi/1.6.4 module-info slurm/slurm/19.05.5
cm-setup/9.0 gcc/9.2.0 null
cmd ipmitool/1.8.18 openldap
cmjob lua/5.3.5 python3
----------------------------- /cm/shared/modulefiles -----------------------------
blacs/openmpi/gcc/64/1.1patch03 intel-tbb-oss/ia32/2019_20191006oss pgi/18.4
blas/gcc/64/3.8.0 intel-tbb-oss/intel64/2019_20191006oss ucx/1.6.1
bonnie++/1.98 iozone/3_487
cm-pmix3/3.1.4 lapack/gcc/64/3.8.0
default-environment mpich/ge/gcc/64/3.3.2
fftw3/openmpi/gcc/64/3.3.8 mvapich2/gcc/64/2.3.2
gaussian/g16 netcdf/gcc/64/gcc/64/4.7.3
gdb/8.3.1 netperf/2.7.0
globalarrays/openmpi/gcc/64/5.7 openblas/dynamic(default)
hdf5/1.10.1 openblas/dynamic/0.2.20
hdf5_18/1.8.21 openmpi/gcc/64/1.10.7
hwloc/1.11.11 pgi/13.9
We can see here that we have mpich, openmpi and mvapich2 as our options.
Let's use the mpich implementation. First, let's examine the module using module display then add it to our environment using module load.
[shesprich@vs-bcmshane ~]$ module list
Currently Loaded Modulefiles:
1) gcc/9.2.0 2) slurm/slurm/19.05.5
[shesprich@vs-bcmshane ~]$ module display mpich/ge/gcc/64/3.3.2
-------------------------------------------------------------------
/cm/shared/modulefiles/mpich/ge/gcc/64/3.3.2:
module-whatis {adds MPICH-gcc to your environment variables}
prepend-path PATH /cm/shared/apps/mpich/ge/gcc/64/3.3.2/bin
prepend-path MANPATH /cm/shared/apps/mpich/ge/gcc/64/3.3.2/share/man
setenv MPI_HOME /cm/shared/apps/mpich/ge/gcc/64/3.3.2
setenv MPI_RUN /cm/shared/apps/mpich/ge/gcc/64/3.3.2/bin/mpirun
setenv MPICH_USE_SHLIB yes
setenv P4_GLOBMEMSIZE 67108864
prepend-path LD_RUN_PATH /cm/shared/apps/mpich/ge/gcc/64/3.3.2/lib
prepend-path LD_LIBRARY_PATH /cm/shared/apps/mpich/ge/gcc/64/3.3.2/lib
-------------------------------------------------------------------
[shesprich@vs-bcmshane ~]$ module load mpich/ge/gcc/64/3.3.2
[shesprich@vs-bcmshane ~]$ module list
Currently Loaded Modulefiles:
1) gcc/9.2.0 2) slurm/slurm/19.05.5 3) mpich/ge/gcc/64/3.3.2
[shesprich@vs-bcmshane ~]$ which mpicc
/cm/shared/apps/mpich/ge/gcc/64/3.3.2/bin/mpicc
Finally, if during the process of developing your software you realize that openmpi may be a better option for your specific needs. You can easily change implementations using module switch:
[shesprich@vs-bcmshane ~]$ module switch mpich/ge/gcc/64/3.3.2 \
> openmpi/gcc/64/1.10.7
[shesprich@vs-bcmshane ~]$ which mpicc
/cm/shared/apps/openmpi/gcc/64/1.10.7bin/mpicc
Sidebar Photo by Florian Olivo on Unsplash