Environment Modules: Difference between revisions

From bwHPC Wiki
Jump to navigation Jump to search
(Viewing the Changes Introduced by a Module)
(78 intermediate revisions by 8 users not shown)
Line 1: Line 1:
<!--<span style="color:red;font-size:105%;">Important note: bwUniCluster is '''not''' in production mode yet.</span>-->


Software on the bwHPC Clusters is provided as '''Software Environment Modules''', or short '''Modules'''.


Modules make it possible to have different versions of a software installed at a the same time.
The complete environments for the software package, compilers and libraries and needed by this specific version is then loaded by a single command. This happens usually in the beginning of the jobscript.


= Basic Usage =
The usage of compilers, libraries and software packages requires by default users to set up
== General Documentation on the Modules Environment Software ==
manually their session environment. The bwHPC clusters (such as [[bwUniCluster]]) provide users the possibility to load and unload ''complete environments''
for compilers, libraries and software packages by single commands. Because of the
convenient modularity this package is called ''Environment Modules'', or short '''Modules'''.


We will provide an overview of the most important commands in the next sections.


For your reference on what is not covered here, the full documentation written by the software developers is available on the cluster via the commands:
<!--{| align="right" {{Table|width=40%}} -->
{|{{Softwarebox}}
|-
! colspan="2" style="text-align:center" | Modules
<!--
|-
| module load
| category/name
-->
|-
| License
| GPL
|-
| Links
| http://modules.sourceforge.net/
|
|}


<code>module help</code>
<!--
{| style="width: 100%; border-spacing: 5px;"
| style="text-align:left; color:#000;vertical-align:top;" |__TOC__
|<br><br>[[File:BwUniCluster_modulefiles.png|center|border|400px]]
|-
|}
-->


<code>man module</code>


Online documentation of the project is available on the [https://lmod.readthedocs.io/en/latest/ Environment Modules Website].
= Description =


== Module categories, versions and defaults ==
The Environment ''Modules'' package enables dynamic modification of your environment by the
The bwHPC clusters categorize ''Modules'', each software can exist in different versions:
use of so-called ''modulefiles''. A ''modulefile'' contains information to configure the shell
for a program/software . Typically, a modulefile contains instructions that alter or set shell
environment variables, such as PATH and MANPATH, to enable access to various installed
software.


category/softwarename/version
One of the key features of using the Environment ''Modules'' software is to allow multiple versions of the same software to be used in your environment in a controlled manner.
For instance the Intel compiler X.Y belongs to the category of compilers, therefore the
For example, two different versions of the Intel C compiler can be installed on the system at the same time - the version used is based upon which Intel C compiler modulefile is loaded.
modulefile ''X.Y'' is placed under the category ''compiler'' and ''intel''.
<br>
In case of multiple software versions, one version will be always defined as the '''default'''
version. The ''Module'' of the default can be addressed by simply omitting the version number:
category/softwarename


e.g. if mathematica is installed, it is in the module
The software stack of bwHPC clusters provides a number of modulefiles. You can also
create your own modulefiles. ''Modulefiles'' may be shared by many users on a system, and
users may have their own collection of modulefiles to supplement or replace the shared
modulefiles.


math/mathematica
A modulefile does not provide configuration of your environment until it is explicitly loaded,
i.e., the specific modulefile for a software product or application must be loaded in your environment before the configuration information in the modulefile is effective. For instance
loading the default Intel C and Fortran compiler you must execute:
<pre>
$ module load compiler/intel
</pre>


Currently all bwHPC software packages are assigned to the following ''Module'' categories:


<code> bio cae chem compiler devel lib math mpi numlib phys system vis </code>
= Usage =


<!--
== Documentation ==
[[:Category:Biology_software|bio]]
[[:Category:Engineering_software|cae]]
[[:Category:Chemistry_software|chem]]
[[:Category:Compiler_software|compiler]]
[[:Category:Debugger_software|devel]]
[[:Category:Mathematics_software|math]]
mpi
[[:Category:Numerical libraries|numlib]]
[[:Category:Physics software|phys]]
[[:Category:System software|system]]
[[:Category:Visualization|vis]]
-->


== Display and search available Modules ==
For help on how to use ''Modules'' software, i.e., the command '''module''',
Available ''Modules'' are modulefiles that can be loaded by the user. A ''Module'' must be loaded before it provides changes to your environment. You can display all available ''Modules'' on the system by executing:
execute:
<pre>
<pre>
$ module help
$ module avail
</pre>
</pre>

or
You can selectively list software in one of those categories using, e.g. for the category "compiler", or just all versions of a certain module:
<pre>
<pre>
$ man module
$ module avail compiler/
$ module avail compiler/gnu
</pre>
</pre>


== module help ==
For help on particular version of ''Module'', e.g. Intel compiler version X.Y, execute:
A help message for a specific ''Module'' can be displayed with ''''module help category/softwarename/version''''.
<br>
The help message usually contains additional information about the software and points to the software website and documentation.
<pre>
<pre>
$ module help compiler/intel/X.Y
$ module help system/example/1.0
----------------- Module Specific Help for "system/example/1.0" ---------------------------
"This module provides a bwhpc-examples job that works on every cluster.

[... rest of the output is omitted in the Wiki for clarity ...]
</pre>
</pre>




== Loading Modules and Check they are loaded ==
== Display all available Modules ==
To load a software ''Module'' and display all loaded modules:

Available ''Module'' are modulefiles that can be loaded by the user. A ''Module'' must be loaded before it provides changes to your environment, as described in the introduction to this
section. You can display all available ''Modules'' on the system by executing:
<pre>
<pre>
$ module avail
$ module list
No Modulefiles Currently Loaded.
</pre>
$ module load system/example/1.0
The short form the command is:
$ module list
<pre>
Currently Loaded Modulefiles:
$ module av
1) system/example/1.0
</pre>
</pre>


Available ''Modules'' can be also displayed in different modes, such as
* each ''Module'' per one line
<pre>
$ module -t avail
</pre>
* long
<pre>
$ module -l avail
</pre>


Module make software available only in your current shell. Whenever you login in, you have to load the software again. Please don not auto-load modules in .bashrc on login, this can lead to problems with other modules you may load later.


== Software job examples ==
== Module categories, versions and defaults ==
bwHPC provides example job scripts for most installed software modules.


For a Software ''Module'' with the sofware called '''SOMESOFTWARE''', you can find the example directory by:
The bwHPC clusters (such as [[bwUniCluster]]) traditionally provide a large variety of
software and software versions. Therefore ''Module'' are divided in category folders
containing subfolders of modulefiles again containing modulefile versions, and must be addressed
as follows:
<pre>
<pre>
$ cd $SOMESOFTWARE_EXA_DIR
category/softwarename/version
</pre>
</pre>

For instance the Intel compiler X.Y belongs to the category of compilers, therefore the
Copy the whole example folder to your $HOME directory, so you can edit those job examples:
modulefile ''X.Y'' is placed under the category ''compiler'' and ''intel''.


In case of multiple software versions, one version will be always defined as the '''default'''
version. The ''Module'' of the default can be addressed by simply omitting the version number:
<pre>
<pre>
$ cd
category/softwarename
$ mkdir softwarename_examples
$ echo $SOMESOFTWARE_EXA_DIR
# Please do not proceed if the command above does not provide any text !
# Otherwise you will start to copy all system data (the directory "/").
$ cp -r $SOMESOFTWARE_EXA_DIR/ softwarename_examples/

</pre>
</pre>


If your specific software isn't installed, there is a dummy software example module "system/example" present on all clusters. For this module, the process looks like this:


<pre>
== Finding software Modules ==
# Load the example module
$ module load system/example/1.0


# Run example in a temporary directory
Currently all bwHPC software packages are assigned to the following ''Module'' categories:
$ mkdir tmp_example_dir
<!-- add wiki category for each of those, possibly just as a link -->
$ cp -r $EXAMPLE_EXA_DIR/ softwarename_examples/
* [[:Category:Biology_software|bio]]
$ cd tmp_example_dir/bwhpc-examples
* cae
* [[:Category:Chemistry_software|chem]]
* [[:Category:Compiler_software|compiler]]
* [[:Category:Debugger_software|devel]]
* dot
* lib
* [[BwHPC_BPG_for_Mathematics|math]]
* mpi
* [[:Category:Numerical libraries|numlib]]
* phys
* [[:Category:System software|system]]
* [[:Category:Visualization|vis]]


# Example jobscript for clusters using the SLURM batch system
You can selectively list software in one of those categories using, e.g. for the category "compiler"
sbatch examples-1.0.slurm
<pre>
# Example jobscript for clusters using PBS
$ module avail compiler/
qsub examples-1.0.pbs
</pre>
Searches are looking for a substring starting at the begin of the name, so this would list all software in categories starting with a "c"
<pre>
$ module avail c
</pre>
while this would find nothing
<pre>
$ module avail hem
</pre>


# Print the results

cat examples_result.txt
== Loading Modules ==
You can load a ''Module'' software in to your environment to enable easier access to software that
you want to use by executing:
<pre>
$ module load category/softwarename/version
</pre>
</pre>
----
or
<pre>
$ module add category/softwarename/version
</pre>
Loading a ''Module'' in this manner affects ONLY your environment for the current session.


= Additional Usage Recommendations =


=== Loading conflicts ===
=== Loading conflicts ===
By default you can not load different versions of same software ''Module'' in same session. Loading for example Intel compiler version X while Intel compiler version Y is loaded results in error message as follows:
By default you can not load different versions of same software ''Module'' in same session. Loading for example Intel compiler version X while Intel compiler version Y is loaded results in error message as follows:
{| style="width: 100%; border:1px solid #d0cfcc; background:#f2f7ff;border-spacing: 2px;"
| style="width:280px; text-align:center; white-space:nowrap; color:#000;" |
<source lang="bash">
<source lang="bash">
ERROR:150: Module 'compiler/intel/X' conflicts with the currently loaded module(s) 'compiler/intel/Y'
Module 'compiler/intel/X' conflicts with the currently loaded module(s) 'compiler/intel/Y'
</source>
</source>
|}
The solution is [[#Unloading Modules|unloading]] or switching ''Modules''.
The solution is [[#Unloading Modules|unloading]] or switching ''Modules''.


=== Showing the changes introduced by a Module ===
Loading a ''Module'' will change the environment of the current shell session. For instance the $PATH variable will be expanded by the software's binary directory. Other ''Module'' variables may even change the behavior of the current shell session or the software program(s) in a more drastic way.
<br>
Loaded ''Modules'' may also invoke an additional set of environment variables, which e.g. point to directories or destinations of documentation and examples. Their nomenclature is systematic:
{| width=600px class="wikitable"
|-
! Variable
! Pointing to
|-
| $SWN_HOME
| Root directory of the software package
|-
| $SWN_DOC_DIR
| Documentation
|-
| $SWN_EXA_DIR
| Examples
|-
| $SWN_BPR_URL
| URL of software's Wiki article
|-
| and many many more...
| &nbsp;
|}
with SWN being the place holder of the software ''Module'' name.
<br>
All the changes to the current shell session to be invoked by loading the ''Module'' can be reviewed using ''''module show category/softwarename/version''''.
<br>
<pre>
$ module show system/example/1.0
---------------------------------------------------------------------------------------------------
/opt/bwhpc/common/modulefiles/Core/system/example/1.0.lua:
---------------------------------------------------------------------------------------------------
whatis("A generic module containing a working bwhpc-examples job.")
setenv("EXAMPLE_VERSION","1.0")
setenv("EXAMPLE_HOME","/opt/bwhpc/common/system/example/1.0")
setenv("EXAMPLE_BIN_DIR","/opt/bwhpc/common/system/example/1.0/bin")
setenv("EXAMPLE_EXA_DIR","/opt/bwhpc/common/system/example/1.0/bwhpc-examples")
prepend_path("PATH","/opt/bwhpc/common/system/example/1.0/bin")
help([["This module provides a bwhpc-examples job that works on every cluster.
The module is used as example in the bwHPC-Wiki and therefore should be installed on every cluster,
such that users can try the commands out.


* The executable of this module can be found in the folder
== Viewing the Changes Introduced by a Module ==
$EXAMPLE_BIN_DIR
Upon loading the module, the binaries are added to PATH.


* Further documentation for using the example can be found in
Loading a module will change the environment of the current shell. The PATH variable will be adjusted to include the program in every module, other variables may change the behavior of the shell or programs being run from it in a more drastic way.
https://wiki.bwhpc.de/e/Environment_Modules


* Examples are located at:
Modules installed on the bwHPC systems will also set a number of convenience variables, pointing to places of the installation that might be of interest.
$EXAMPLE_EXA_DIR
]])


</pre>
All the changes made by the module can be reviewed using

module show category/programname/0.0.0

=== Automatic Loading ===
If you frequently use one or more ''Modules'' that are not loaded when you log in to
the system, you can set up your environment to automatically load those ''Modules'' for
you. A method for doing this is to modify your shell startup script to include instructions to
load the modulefile automatically.

For example, if you want to automatically load the ''Module'' of Intel's default compiler when you log
in, edit your shell startup script to include the following instructions. This example assumes
that you use bash as your login shell. Edit the <tt>$HOME/.bashrc</tt> file as follows:
{| style="width: 100%; border:1px solid #d0cfcc; background:#f2f7ff;border-spacing: 2px;"
| style="width:280px; text-align:center; white-space:nowrap; color:#000;" |
<source lang="bash">
## if the ’module’ command is defined, $MODULESHOME will be set
if [ -n "$MODULESHOME" ]; then
module load compiler/intel
fi
</source>
|}
From now on, whenever you log in, the default version of the Intel compiler is automatically
loaded in your environment.


=== Modules depending on Modules ===
=== Modules depending on Modules ===
Line 213: Line 200:
corresponding ''Modules'' of the software must be loaded together with the ''Modules'' of
corresponding ''Modules'' of the software must be loaded together with the ''Modules'' of
the libraries.
the libraries.
<br>

By default such software ''Modules'' try to load required ''Modules'' and corresponding versions automatically. However, automatic loading might fail if a different version of that required ''Module''
By default such software ''Modules'' try to load required ''Modules'' and corresponding versions automatically. However, automatic loading might fail if a different version of that required ''Module''
is already loaded (cf. [[#Loading conflicts|Loading conflicts]]).
is already loaded (cf. [[#Loading conflicts|Loading conflicts]]).
<br>



== Unloading Modules ==
== Unloading Modules ==

To unload or to remove a software ''Module'' execute:
To unload or to remove a software ''Module'' execute:

<pre>
<pre>
$ module unload category/softwarename/version
$ module unload category/softwarename/version
</pre>
</pre>


=== Unloading all loaded modules ===
or
In order to remove all previously loaded software modules from your environment issue the command 'module purge'.

<pre>
<br>
$ module remove category/softwarename/version
</pre>

Unloading a ''Module'' that has been loaded by default makes it inactive for the current session only - it will be reloaded the next time you log in.

In order to remove all previously loaded software modules from your environment issue the following command:
<pre>
<pre>
$ module list
Currently Loaded Modulefiles:
1) devel/gdb/7.7
2) compiler/intel/14.0
3) mpi/openmpi/1.8-intel-14.0(default)
$
$ module purge
$ module purge
</pre>


== Display your loaded Modules ==
All ''Modules'' that are currently loaded for you can be displayed by the
command:
<pre>
$ module list
$ module list
No Modulefiles Currently Loaded.
$
</pre>
</pre>
Note: you only have to load further ''Modules'', if you want to use additional software
packages or to change the version of an already loaded software.


== Other Module commands ==

=== module whatis ===
= Software job examples =
A short description for a specific ''Module'' can be displayed with ''''module whatis category/softwarename/version''''

The ''Modules'' installed on bwHPC systems provide job examples to help you get started using the software or submitting jobs with this software. Examples can be found via a convenient
variable $FOO_EXA_DIR (for a ''Module'' called '''foo'''). It is advisable to copy the whole example folder to your $HOME directory, so you can edit those job examples.

For copying the entire job examples folder of software '''foo''' to your working directory, execute:
<pre>
<pre>
$ module load catogory/softwarename
$ module whatis system/example/1.0
system/example/1.0 : A generic module containing a working bwhpc-examples job.
$ cp -R $FOO_EXA_DIR .
</pre>
</pre>


= How do Modules work? =

The default shell on the bwHPC clusters is bash, so explanations and examples will be shown for bash. In general, programs cannot modify the environment of the shell they are being run from, so how can the module command do exactly that?

The module command is not a program, but a bash-function.
You can view its content using
<pre>
$ type module
</pre>
and you will get a result like this:
<pre>
$ type module
module is a function
module ()
{
eval `/usr/bin/modulecmd bash $*`
}
</pre>

In this function, modulecmd is called. Its output to stdout is then executed inside your current shell using the bash-internal ''eval'' command. As a consequence, all output that you see from the module is transmitted via stderr (output handle 2) or in some cases even stdin (output handle 0).




----
[[Category:System software]][[Category:bwUniCluster|Environment Modules]]
<!--[[Category:bwHPC|User Environment]]
[[Category:bwUniCluster|Environment Modules]]-->

Revision as of 10:24, 25 March 2024

Software on the bwHPC Clusters is provided as Software Environment Modules, or short Modules.

Modules make it possible to have different versions of a software installed at a the same time. The complete environments for the software package, compilers and libraries and needed by this specific version is then loaded by a single command. This happens usually in the beginning of the jobscript.

Basic Usage

General Documentation on the Modules Environment Software

We will provide an overview of the most important commands in the next sections.

For your reference on what is not covered here, the full documentation written by the software developers is available on the cluster via the commands:

module help

man module

Online documentation of the project is available on the Environment Modules Website.

Module categories, versions and defaults

The bwHPC clusters categorize Modules, each software can exist in different versions:

category/softwarename/version

For instance the Intel compiler X.Y belongs to the category of compilers, therefore the modulefile X.Y is placed under the category compiler and intel.
In case of multiple software versions, one version will be always defined as the default version. The Module of the default can be addressed by simply omitting the version number:

category/softwarename

e.g. if mathematica is installed, it is in the module

math/mathematica

Currently all bwHPC software packages are assigned to the following Module categories:

bio cae chem compiler devel lib math mpi numlib phys system vis


Display and search available Modules

Available Modules are modulefiles that can be loaded by the user. A Module must be loaded before it provides changes to your environment. You can display all available Modules on the system by executing:

$ module avail

You can selectively list software in one of those categories using, e.g. for the category "compiler", or just all versions of a certain module:

$ module avail compiler/
$ module avail compiler/gnu

module help

A help message for a specific Module can be displayed with 'module help category/softwarename/version'.
The help message usually contains additional information about the software and points to the software website and documentation.

$ module help system/example/1.0 
----------------- Module Specific Help for "system/example/1.0" ---------------------------
"This module provides a bwhpc-examples job that works on every cluster.

[... rest of the output is omitted in the Wiki for clarity ...]


Loading Modules and Check they are loaded

To load a software Module and display all loaded modules:

$ module list
No Modulefiles Currently Loaded.
$ module load system/example/1.0
$ module list
Currently Loaded Modulefiles:
  1) system/example/1.0


Module make software available only in your current shell. Whenever you login in, you have to load the software again. Please don not auto-load modules in .bashrc on login, this can lead to problems with other modules you may load later.

Software job examples

bwHPC provides example job scripts for most installed software modules.

For a Software Module with the sofware called SOMESOFTWARE, you can find the example directory by:

$ cd  $SOMESOFTWARE_EXA_DIR

Copy the whole example folder to your $HOME directory, so you can edit those job examples:

$ cd
$ mkdir softwarename_examples
$ echo $SOMESOFTWARE_EXA_DIR
# Please do not proceed if the command above does not provide any text !
# Otherwise you will start to copy all system data (the directory "/").
$ cp -r $SOMESOFTWARE_EXA_DIR/ softwarename_examples/

If your specific software isn't installed, there is a dummy software example module "system/example" present on all clusters. For this module, the process looks like this:

# Load the example module
$ module load system/example/1.0

# Run example in a temporary directory
$ mkdir tmp_example_dir
$ cp -r $EXAMPLE_EXA_DIR/ softwarename_examples/
$ cd tmp_example_dir/bwhpc-examples

# Example jobscript for clusters using the SLURM batch system
sbatch examples-1.0.slurm
# Example jobscript for clusters using PBS
qsub examples-1.0.pbs

# Print the results
cat examples_result.txt

Additional Usage Recommendations

Loading conflicts

By default you can not load different versions of same software Module in same session. Loading for example Intel compiler version X while Intel compiler version Y is loaded results in error message as follows:

Module 'compiler/intel/X' conflicts with the currently loaded module(s) 'compiler/intel/Y'

The solution is unloading or switching Modules.

Showing the changes introduced by a Module

Loading a Module will change the environment of the current shell session. For instance the $PATH variable will be expanded by the software's binary directory. Other Module variables may even change the behavior of the current shell session or the software program(s) in a more drastic way.
Loaded Modules may also invoke an additional set of environment variables, which e.g. point to directories or destinations of documentation and examples. Their nomenclature is systematic:

Variable Pointing to
$SWN_HOME Root directory of the software package
$SWN_DOC_DIR Documentation
$SWN_EXA_DIR Examples
$SWN_BPR_URL URL of software's Wiki article
and many many more...  

with SWN being the place holder of the software Module name.
All the changes to the current shell session to be invoked by loading the Module can be reviewed using 'module show category/softwarename/version'.

$ module show system/example/1.0
---------------------------------------------------------------------------------------------------
   /opt/bwhpc/common/modulefiles/Core/system/example/1.0.lua:
---------------------------------------------------------------------------------------------------
whatis("A generic module containing a working bwhpc-examples job.")
setenv("EXAMPLE_VERSION","1.0")
setenv("EXAMPLE_HOME","/opt/bwhpc/common/system/example/1.0")
setenv("EXAMPLE_BIN_DIR","/opt/bwhpc/common/system/example/1.0/bin")
setenv("EXAMPLE_EXA_DIR","/opt/bwhpc/common/system/example/1.0/bwhpc-examples")
prepend_path("PATH","/opt/bwhpc/common/system/example/1.0/bin")
help([["This module provides a bwhpc-examples job that works on every cluster.
The module is used as example in the bwHPC-Wiki and therefore should be installed on every cluster,
such that users can try the commands out.

* The executable of this module can be found in the folder
  $EXAMPLE_BIN_DIR
  Upon loading the module, the binaries are added to PATH.

* Further documentation for using the example can be found in
  https://wiki.bwhpc.de/e/Environment_Modules

* Examples are located at:
  $EXAMPLE_EXA_DIR
]])

Modules depending on Modules

Some program Modules depend on libraries to be loaded to the user environment. Therefore the corresponding Modules of the software must be loaded together with the Modules of the libraries.
By default such software Modules try to load required Modules and corresponding versions automatically. However, automatic loading might fail if a different version of that required Module is already loaded (cf. Loading conflicts).

Unloading Modules

To unload or to remove a software Module execute:

$ module unload category/softwarename/version

Unloading all loaded modules

In order to remove all previously loaded software modules from your environment issue the command 'module purge'.

$ module list
Currently Loaded Modulefiles:
  1) devel/gdb/7.7
  2) compiler/intel/14.0
  3) mpi/openmpi/1.8-intel-14.0(default)
$
$ module purge
$ module list
No Modulefiles Currently Loaded.
$ 

Other Module commands

module whatis

A short description for a specific Module can be displayed with 'module whatis category/softwarename/version'

$ module whatis system/example/1.0 
system/example/1.0  : A generic module containing a working bwhpc-examples job.