Environment Modules简单使用
Environment Modules简单使用
Environment Modules简介
Typically users initialize their environment when they log in by setting environment information for every application they will reference during the session. The Environment Modules package is a tool that simplify shell initialization and lets users easily modify their environment during the session with modulefiles.
下载安装
安装步骤
$ cat INSTALL.txt
$ ./configure
$ make
$ make install
默认安装目录
/usr/local/Modules
├── bin
│ ├── add.modules
│ ├── envml
│ ├── mkroot
│ └── modulecmd
├── etc
│ └── siteconfig.tcl
├── init
│ ├── bash
│ ├── bash_completion
│ ├── cmake
│ ├── csh
│ ├── fish
│ ├── fish_completion
│ ├── ksh
│ ├── ksh-functions
│ ├── lisp
│ ├── modulerc
│ ├── perl.pm
│ ├── profile-compat.csh
│ ├── profile-compat.sh
│ ├── profile.csh
│ ├── profile.sh
│ ├── python.py
│ ├── r.R
│ ├── ruby.rb
│ ├── sh
│ ├── tcl
│ ├── tcsh
│ ├── tcsh_completion
│ ├── zsh
│ └── zsh-functions
├── lib
│ └── libtclenvmodules.so
├── libexec
│ ├── modulecmd-compat
│ └── modulecmd.tcl
├── modulefiles
│ ├── dot
│ ├── module-git
│ ├── module-info
│ ├── modules
│ └── gcc
└── share
├── doc
└── vim
初始化
刚刚安装好的
Environment Modules
是没有module
这条shell命令的
需要进行简单的配置source
一下环境
- 在
profile.d
下建立软连接,执行下列语句
# 全局初始化(root执行)
$ cd /etc/profile.d
$ ln -s /usr/local/Modules/init/profile.sh module-profile.sh
$ ln -s /usr/local/Modules/init/profile.csh module-profile.csh
# 本地shell初始化
# bash
$ echo "source /usr/local/Modules/init/profile.sh" >> ~/.bashrc
$ source ~/.bashrc
# csh/tcsh
% echo "source /usr/local/Modules/init/tcsh" >> ~/.cshrc
% source ~/.cshrc
$ which module
module is a function
module ()
{
_module_raw "$@" 2>&1
}
bash下支持自动补全
# 确认已经安装bash-completion
$ cd /etc/bash_completion.d
$ ln -s /usr/local/Modules/init/bash_completion modules-compliction.bash
csh/tcsh下支持自动补全
% echo "source /usr/local/Modules/init/tcsh_completion" >> ~/.cshrc
管理工具的不同版本
一个简单的例子
$ cd /usr/local/Modules/modulefiles
$ mkdir riscv_toolchain
$ cd riscv_toolchain
$ touch compile-version
$ touch freedomstudio-version
- compile-verison
#%Module -*- tcl -*-
conflict riscv_toolchain/freedomstudio-version
set tool_home /opt/riscv/toolchain
setenv RISCV $tool_home
append-path PATH $tool_home/bin
append-path LIBRARY_PATH $tool_home/lib
append-path LD_LIBRARY_PATH $tool_home/lib
append-path LD_INCLUDE_PATH $tool_home/include
append-path MANPATH $tool_home/share/man
- freedomstudio-verison
#%Module -*- tcl -*-
conflict riscv_toolchain/compile-version
set tool_home /opt/FreedomStudio/SiFive/riscv64-unknown-elf-gcc-8.3.0-2019.08.0
setenv RISCV $tool_home
append-path PATH $tool_home/bin
append-path LIBRARY_PATH $tool_home/lib
append-path LD_LIBRARY_PATH $tool_home/lib
append-path LD_INCLUDE_PATH $tool_home/include
append-path MANPATH $tool_home/share/man
依赖其他module的例子
#%Module -*- tcl -*-
# conflict sbt/
# 依赖于java环境,先加载此module
module load java/jdk-14.0.1
set tool_home /opt/scala/sbt-1.3.4
prepend-path PATH $tool_home/bin
prepend-path LIBRARY_PATH $tool_home/lib
prepend-path LD_LIBRARY_PATH $tool_home/lib
简单使用
$ module load riscv_toolchain/compile-version
$ which riscv64-unknown-elf-gcc
riscv64-unknown-elf-gcc is /opt/riscv/toolchain/bin/riscv64-unknown-elf-gcc
$ module load riscv_toolchain/freedomstudio-version
Loading riscv_toolchain/freedomstudio-version
ERROR: riscv_toolchain/freedomstudio-version cannot be loaded due to a conflict.
HINT: Might try "module unload riscv_toolchain/compile-version" first.
$ module unload riscv_toolchain/compile-version
$ module load riscv_toolchain/freedomstudio-version
$ which riscv64-unknown-elf-gcc
riscv64-unknown-elf-gcc is /opt/FreedomStudio/SiFive/riscv64-unknown-elf-gcc-8.3.0-2019.08.0/bin/riscv64-unknown-elf-gcc
个人环境管理
~/privatemodules/
与/usr/local/Modules/modulefiles
一样可以包含local的环境设置
$ cd ~/
$ mkdir privatemodules/
自定义路径
增加module搜索的路径
# bash
$ export MODULEPATH=your_modulefiles_path_directory:$MODULEPATH
# csh
$ setenv MODULEPATH your_modulefiles_path_directory:$MODULEPATH
常用命令
命令 | 作用 |
---|---|
module avail 或 module av | 查看系统中可用的资源 |
module add 或 module load | 加载模块 |
module rm 或 unload | 卸载模块 |
module list 或 module li | 显示已加载模块 |
module purge | 卸载所有模块 |
module show | 显示模块配置文件 |
module swap 或 module switch | 将模块1 替换为 模块2 |
module help | 查看具体软件的信息 |
参考资料
[1].超算入门课程4 module命令使用教学
[2].Environment Modules
[3].Linux使用Moduler切换各种MPI环境
[4].Environment Modules
形而上者谓之道 形而下者谓之器。