JerryYe的个人博客分享 http://blog.sciencenet.cn/u/JerryYe

博文

【MITgcm】MITgcm在集群/超级计算机上的编译环境配置预设

已有 6773 次阅读 2020-5-28 12:19 |个人分类:MITgcm|系统分类:科研笔记| MITgcm, 并行运算, 编译环境, module, 模块

MITgcm是麻省理工学院开发的环流模式,该模式能够完成从海洋小尺度对流过程到大尺度环流过程等多尺度海洋动力过程的模拟,具有很普遍的应用能力。在模拟实践中,不同的服务器提供的编译环境具有很大的不同,为了能够在不同服务器上顺利地运转MITgcm模式,除了正确安装MITgcm软件之外,其次,还要对应配置相关的并行编译环境,否则,模式是无法编译成功的。

【1】编译器安装

MITgcm需要的编译环境包括Intel Compiler/GNU Compiler和MPI Compiler,并行运算需要加载并行编译器,常用的MPI编译器包括Intel MPI、MPICH、OPENMPI等。一般服务器为了满足用户需求都会预安装Intel Compiler/GNU Compiler和MPI Compiler,以及并行运算MPI编译器,我们可以通过以下命令来查看预安装的编译器版本型号:

$ rpm -qa | grep gcc                #查看gcc的版本型号
$ rpm -qa | grep intel              #查看Intel的版本型号
$ rpm -qa | grep openmpi            #查看openmpi的版本型号

微信图片_20200528103738.png

intel.png

openmpi.png

确认上述编译器已经安装之后,下一步是要加载这些模块

【2】编译模块的加载

服务器编译模块的加载需要module工具,首先查看服务器是否安装module工具

$ module

如果屏幕输出“module command: not found”,说明没有安装,此时就需要先安装module工具了;如果显示module命令的使用参数设置,说明已经安装,那么可以忽略下边2.1的安装内容。

<2.1> module工具安装

a. 下载两个安装包(版本可自选):

tcl8.5.9-src.tar.gz   

https://sourceforge.net/projects/tcl/  

https://cfhcable.dl.sourceforge.net/project/tcl/Tcl/8.5.9/tcl8.5.9-src.tar.gz

modules-4.2.4.tar.gz

http://modules.sourceforge.net/

https://sourceforge.net/projects/modules/files/Modules/

https://newcontinuum.dl.sourceforge.net/project/modules/Modules/modules-4.2.4/modules-4.2.4.tar.gz

b. tcl工具安装

tcl是module的依赖工具,所以要首先安装tcl工具,将上述安装包放到$HOME/tools目录下,其中$HOME为用户的根目录,比如:/public/home/zhangsan

$ tar -zxvf tcl8.5.9-src.tar.gz                 #解压包
$ cd tcl8.5.9/unix
$ ./configure --prefix=$HOME/tools/tcl          #--prefix=安装目录
$ make                                          #编译
$ make install                                  #安装

c. module工具安装

$ tar -zxvf modules-4.2.4.tar.gz
$ cd modules-4.2.4
$ ./configure --prefix=$HOME/tools/modules --with-tcl-lib=$HOME/tools/tcl/lib \
                       --with-tcl-inc=$HOME/tools/tcl/include
$ make
$ make install

安装完成之后,你会发现module命令还不能使用,因为没有进行module工具的配置

d. module配置

在上述安装的$HOME/tools/modules/init目录下有profile.sh和profile.csh文件,是用来配置module的脚本文件,如果使用的shell是bash,就对应使用profile.sh,如果使用的shell是cshell,就使用profile.csh。以bash为例,有两种配置方法,

一种是临时配置方法,关闭shell窗口,重新登录后失效,需要重新配置,命令如下:

$ source $HOME/tools/modules/init/profile.sh

source担负了符号“.”的功能

另一种方法是永久性配置方法,关闭shell窗口,重新登录后,后台会自动配置,命令如下:

$ vi $HOME/.bashrc

vi.png

按“Insert”键盘键,会发现shell命令窗口左下角最后一行内容变为“--INSERT--”,此时可以对文件内容进行编辑,我们将上述source命令行加到脚本文件内,然后保存退出(“Esc”--":wq!")(退出不保存“Esc”--":q!"),这样每次登陆之后就可以自动配置module工具了。

<2.2>服务器模块的设置和module加载

安装好module工具之后,我们先看下服务器有哪些模块可以用

$ module avail

avai.png

发现没有什么可以加载的并行编译器模块,为了加载想用的并行编译器模块,我们需要手动设置需要的模块,以加载openmpi-1.10.4为例:

a. 首先在$HOME/tools/modules/modulefiles目录下新建名字为openmpi-1.10.4的配置文件,openmpi-1.10.4配置文件的内容参考该目录下的modules配置文件内容

modules文件内容为:

#%Module1.0#####################################################################
##
## modules modulefile
##
proc ModulesHelp { } {
        global version prefix
        puts stderr "\tmodules - loads the modules software & application environment"
        puts stderr "\n\tThis adds $prefix/* to several of the"
        puts stderr "\tenvironment variables."
        puts stderr "\n\tVersion $version\n"
}

module-whatis"loads the modules environment"

# for Tcl script use only
set    version        4.2.4
set    prefix        /public/home/yeruijie/tools/modules

setenv       MODULESHOME    $prefix
prepend-path    PATH        /public/home/yeruijie/tools/modules/bin
prepend-path    MANPATH        /public/home/yeruijie/tools/modules/man
# enable module versioning modulepath
#module use /public/home/yeruijie/tools/modules/versions

参考modules文件,我们编写openmpi-1.10.4配置文件,首先确定执行命令mpirun所在的位置:

$ locate mpirun

locate.png

将openmpi-1.10.4-hfi的路径添加到openmpi-1.10.4配置文件:

#%Module1.0#####################################################################
##
## modules modulefile
##
proc ModulesHelp { } {
        global version prefix
        puts stderr "\tmodules - loads the modules software & application environment"
        puts stderr "\n\tThis adds $prefix/* to several of the"
        puts stderr "\tenvironment variables."
        puts stderr "\n\tVersion $version\n"
}

module-whatis    "openmpi-1.10.4"

# for Tcl script use only
set    version        openmpi-1.10.4
set    prefix         /usr/mpi/intel/openmpi-1.10.4-hfi
set    exec_prefix    ${prefix}
set    datarootdir    ${prefix}
set    INSTALL_DIR    ${prefix}

prepend-path    PATH                ${prefix}/bin
prepend-path    LD_LIBRARY_PATH        ${prefix}/bin

prepend-path    LIBRARY_PATH           ${prefix}/bin
prepend-path    PKG_CONFIG_PATH        ${prefix}/bin/pkgconfig
prepend-path    C_INCLUDE_PATH         ${prefix}/include
prepend-path    CXX_INCLUDE_PATH       ${prefix}/include
prepend-path    MANPATH                ${datarootdir}/man

然后保存配置文件。

b. 添加配置文件路径

在$HOME/tools/modules/modulefiles目录下新建modulepath配置文件,配置文件内容:

modue use $HOME/tools/modules/modulefiles

然后保存。

此时,我们在命令行输入module avail,发现openmpi-1.10.4模块出现了

aaa.png


然后,我们module load openmpi,就可以使用该模块了

bbb.png

【3】MITgcm算例并行运算-optfile的编写

MITgcm算例并行运算编译过程中有一步需要配置并行脚本文件:

../../../tools/genmake2 -mods=../code -mpi -of=../../../../lib/Linux_m64_mpi

这里的Linux_m64_mpi就是并行脚本文件,这里提供一个参考脚本

#!/bin/bash
#
# $Header: /u/gcmpack/MITgcm/tools/build_options/linux_ia64_ifort+mpi_swell,v 1.4 2010/03/21 17:58:17 jmc Exp $
# $Name: checkpoint62z $

# Build options for Harvard cluster "swell"

FC='mpif90'
CC='mpicc'
DEFINES='-DWORDLENGTH=4'
CPP='cpp -traditional -P'

INCLUDES="$INCLUDES -I/usr/lib64"
#INCLUDES="$INCLUDES -I/usr/local/include"
INCLUDES="$INCLUDES -I/usr/mpi/intel/openmpi-1.10.4-hfi/include"

#LIBS='-L/usr/lib64 -lnetcdf'

#  Note that the -mp switch is for ieee "maintain precision" and is
#  roughly equivalent to -ieee
if test "x$IEEE" = x ; then
    FFLAGS="$FFLAGS -m64 -convert big_endian -assume byterecl -mcmodel large -shared-intel"
    FOPTIM='-O3 -align'
#P3 FOPTIM=$FOPTIM' -tpp6 -xWKM'
#P4 FOPTIM=$FOPTIM' -tpp7 -xWKM'
else
    FOPTIM='-O0 -noalign'
    FFLAGS="$FFLAGS -w95 -W0 -WB -xN -pc64 -convert big_endian -assume byterecl"
   #FFLAGS="$FFLAGS -mp -w95 -W0 -WB"
fi
#- might want to use '-r8' for fizhi pkg:
#FFLAGS="$FFLAGS -r8"

脚本文件里的openmpi路径要与上述统一对应!

注:

在用pbs脚本提交作业时,有时会找不到mpirun:mpirun command not found,一个解决办法是把mpirun执行文件的绝对路径添加上,以Test01.pbs脚本为例:

#!/bin/bash

#PBS -N Test01
#PBS -o out
#PBS -e err
#PBS -q batch
#PBS -l nodes=4:ppn=10

cd  $HOME/MITgcm/verification/flowOnSlope3DTest03/run

/usr/mpi/intel/openmpi-1.10.4-hfi/bin/mpirun -np 40 mitgcmuv

PS: 细节决定成败在模式调试中很适用,多思考多尝试,认真总结。



https://wap.sciencenet.cn/blog-2824237-1235329.html

上一篇:【PPT】如何插入PPT幻灯片页码并调整位置和字体格式
下一篇:【笨方法】如何独立显示多个Excel文件窗口
收藏 IP: 101.71.255.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-17 05:27

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部