0%

Environment Modules

Environment Modules

Environment Modules 给用户提供了一个通过modulefiles动态的修改环境变量的方法。

什么是 Environment Modules?

通常,用户在登录时通过为会话期间要引用的每个应用程序设置环境信息来初始化其环境。Environment Modules包是一个简化shell初始化的工具,它允许用户在使用modulefile进行会话期间轻松地修改环境。

每个modulefile包含为应用程序配置shell所需的信息。初始化Modules包后,可以使用modulefiles的module命令在每个模块的基础上修改环境。通常,modulefiles 可以使用module命令更改或设置shell环境变量,如PATH、MANPATH等。modulefile可以由系统上的许多用户共享,用户可以有自己的集合来补充或替换共享的modulefile。

模块可以使用 loadedunloaded 动态操作。支持所有主流的shell,比如 bash, ksh, zsh, sh, csh, tcsh, fish, 还有一些其他的脚本语言,如 perl, ruby, tcl, python, cmakeR.

模块在管理不同版本的应用程序时非常有用。模块也可以绑定到元模块中,元模块将加载一整套不同的应用程序。

快速示例

Here is an example of loading a module on a Linux machine under bash.

1
2
3
$ module load gcc/8.3
$ which gcc
/usr/local/gcc/8.3/linux-x86_64/bin/gcc

Now we’ll switch to a different version of the module

1
2
3
$ module switch gcc gcc/9.2
$ which gcc
/usr/local/gcc/9.2/linux-x86_64/bin/gcc

And now we’ll unload the module altogether

1
2
3
$ module unload gcc
$ which gcc
gcc not found

Now we’ll log into a different machine, using a different shell (tcsh).

1
2
3
% module load gcc/9.2
% which gcc
/usr/local/gcc/9.2/linux-aarch64/bin/gcc

Note that the command line is exactly the same, but the path has automatically configured to the correct architecture.

开始使用 Modules

Download latest version of Modules. Learn how to install it on Unix or how to install it on Windows. You may alternatively automatically retrieve and install Modules with your preferred package manager as Environment Modules is widely available. If you are upgrading from an older version of Modules, read the MIGRATING guide to learn all new features recently introduced.

Reference manual page for the module(1) and ml(1) commands and for modulefile(4) script provide details on all supported options. If you have questions, comments or development suggestions for the Modules community, please read the CONTRIBUTING guide.

搜索路径问题

1
2
3
4
5
6
7
#这个是关于引用博主和我自己的使用情况的一些总结:
#查看MODULEPATH
echo $MODULEPATH

#修改路径
#在默认的/usr/share/module/init/bash中添加最后一行
export MODULEPATH=/YOUR/PATH/:$MODULEPATH

modulefiles文件的书写

  • 文件的开头一定是#%Module1.0开始
  • 有几个命令
    • prepend 要修改的环境变量 路径
    • setenv 修改环境变量的值
    • conflict modulefile 如果这个modulefile已经被加载,则当前的modulefile不能被加载

一个模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#%Module1.0
proc ModulesHelp { } {
global version prefix

puts stderr "\t Loads the environment for my installed home folder HOME/local"
}

module-whatis "Loads the environment for my installed home folder HOME/local"

set HOME /home/svu/a0081742

prepend-path PATH $HOME/local/bin
prepend-path LIBRARY_PATH $HOME/local/lib
prepend-path LD_LIBRARY_PATH $HOME/local/lib
prepend-path LD_INCLUDE_PATH $HOME/local/include
prepend-path MANPATH $HOME/local/share/man

使用方法

  • module avail 显示可以使用的模块
  • module load 加载模块
  • module unload 卸载模块
  • module list 显示已经加载的模块
处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!

欢迎关注我的其它发布渠道