发布于: Oct 10, 2022
以下流程图可以看出,WRF 模式系统主要包含的组件有:
• WRF Preprocessing System(WPS)
• OBSGRID
• WRF-DA
• ARW Solver(WRF 计算主程序)
• 后处理和可视化
以下步骤包含了对 WRF 主程序,WPS,WRFDA,OBSGRID 的安装:
首先 WRF 依赖于 gfortan 编译器和 gcc、cpp 的库,在此基础之上依赖于基本库 NetCDF 和用于并行计算的库 MPICH,在运行 WRF 任务之前,还需要通过WPS(WRF Pre-processing System)做数据的预处理。所以在 WRF 的安装过程中,首先要更新依赖的编译器和库,然后安装 NetCDF 和 MPICH,然后安装和编译 WRF,设定好目录后安装和编译 WPS。
在本次实验中,为了获得更好的性能,我们将会使用 GCC 10.2 进行编译。GCC 10 包含了大量的新架构特性,相比 GCC 旧版本,性能更好。下图是 GCC 8/9/10 相对 GCC7 的性能提升
打开 Amazon Web Service 控制台,选择 EC2 服务,找到集群主节点(默认标签为Master),ssh登录。登录后,可以看到 Amazon FSx for Lustre 高性能文件系统已经挂载在 /fsx。该实验会将软件的源码下载 /fsx/tools,编译后的二进制文件则存放在 /fsx/wrf-arm。创建相关目录
$ mkdir /fsx/wrf-arm $ mkdir /fsx/tools
为了安装方便,我们将安装过程中的相关变量写在文件
/fsx/wrf-arm/wrf-install.env里 $ view /fsx/wrf-arm/wrf-install.env export DOWNLOAD=/fsx/tools export WRF_INSTALL=/fsx/wrf-arm export WRF_DIR=${WRF_INSTALL}/WRF-4.2.2 export GCC_VERSION=10.2.0 export OPENMPI_VERSION=4.1.0 export PATH=${WRF_INSTALL}/gcc-${GCC_VERSION}/bin:$PATH export LD_LIBRARY_PATH=${WRF_INSTALL}/gcc-${GCC_VERSION}/lib64:$LD_LIBRARY_PATH export CC=gcc export CXX=g++ export FC=gfortran export PATH=${WRF_INSTALL}/openmpi-${OPENMPI_VERSION}/bin:$PATH export LD_LIBRARY_PATH=${WRF_INSTALL}/openmpi-${OPENMPI_VERSION}/lib:$LD_LIBRARY_PATH export CC=mpicc export CXX=mpic++ export FC=mpifort export F90=mpifort export CXX=mpicxx export FC=mpif90 export F77=mpif90 export F90=mpif90 export CFLAGS="-g -O2 -fPIC" export CXXFLAGS="-g -O2 -fPIC" export FFLAGS="-g -fPIC -fallow-argument-mismatch" export FCFLAGS="-g -fPIC -fallow-argument-mismatch" export FLDFLAGS="-fPIC" export F90LDFLAGS="-fPIC" export LDFLAGS="-fPIC" export HDF5=${WRF_INSTALL}/hdf5 export PNET=${WRF_INSTALL}/pnetcdf export ZLIB=${WRF_INSTALL}/zlib export CPPFLAGS="-I$HDF5/include -I${PNET}/include" export CFLAGS="-I$HDF5/include -I${PNET}/include" export CXXFLAGS="-I$HDF5/include -I${PNET}/include" export FCFLAGS="-I$HDF5/include -I${PNET}/include" export FFLAGS="-I$HDF5/include -I${PNET}/include" export LDFLAGS="-I$HDF5/include -I${PNET}/include -L$ZLIB/lib -L$HDF5/lib -L${PNET}/lib" export NCDIR=${WRF_INSTALL}/netcdf export LD_LIBRARY_PATH=${NCDIR}/lib:${LD_LIBRARY_PATH} export CPPFLAGS="-I$HDF5/include -I$NCDIR/include" export CFLAGS="-I$HDF5/include -I$NCDIR/include" export CXXFLAGS="-I$HDF5/include -I$NCDIR/include" export FCFLAGS="-I$HDF5/include -I$NCDIR/include" export FFLAGS="-I$HDF5/include -I$NCDIR/include" export LDFLAGS="-L$HDF5/lib -L$NCDIR/lib" export PHDF5=${WRF_INSTALL}/hdf5 export NETCDF=${WRF_INSTALL}/netcdf export PNETCDF=${WRF_INSTALL}/pnetcdf export PATH=${WRF_INSTALL}/netcdf/bin:${PATH} export PATH=${WRF_INSTALL}/pnetcdf/bin:${PATH} export PATH=${WRF_INSTALL}/hdf5/bin:${PATH} export LD_LIBRARY_PATH=${WRF_INSTALL}/netcdf/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=${WRF_INSTALL}/pnetcdf/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=${WRF_INSTALL}/hdf5/lib:$LD_LIBRARY_PATH export WRFIO_NCD_LARGE_FILE_SUPPORT=1 export NETCDF_classic=1 export F77=mpifort export FFLAGS="-g -fPIC" export FCFLAGS="-g -fPIC" export JASPERLIB=${WRF_INSTALL}/jasper/lib export JASPERINC=${WRF_INSTALL}/jasper/include
$ source /fsx/wrf-arm/wrf-install.env $ wget https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz $ tar -xzvf gcc-${GCC_VERSION}.tar.gz $ cd gcc-${GCC_VERSION} $ ./contrib/download_prerequisites $ mkdir obj.gcc-${GCC_VERSION} $ cd obj.gcc-${GCC_VERSION} $ ../configure --disable-multilib --enable-languages=c,c++,fortran --prefix=${WRF_INSTALL}/gcc-${GCC_VERSION} $ make -j $(nproc) && make install
编译过程大概需要30分钟。
浏览器打开 https://www.open-mpi.org/ 查看最新版本的 open-mpi 源码的下载地址,以下命令下载并编译 OpenMPI 4.1.0
$ source /fsx/wrf-arm/wrf-install.env $ cd $DOWNLOAD $ wget -N https://download.open-mpi.org/release/open-mpi/v4.1/openmpi-4.1.0.tar.gz $ tar -xzvf openmpi-4.1.0.tar.gz $ cd openmpi-4.1.0 $ mkdir build $ cd build $ ../configure --prefix=${WRF_INSTALL}/openmpi-${OPENMPI_VERSION} --enable-mpirun-prefix-by-default $ make -j$(nproc) && make install
$ source /fsx/wrf-arm/wrf-install.env $ cd $DOWNLOAD $ wget -N http://www.zlib.net/zlib-1.2.11.tar.gz $ tar -xzvf zlib-1.2.11.tar.gz $ cd zlib-1.2.11 $ ./configure --prefix=${WRF_INSTALL}/zlib $ make check && make install
浏览器打开 https://www.hdfgroup.org/downloads/hdf5/source-code/ 查看最新版本的 HDF5 源码的下载地址,例如 hdf5-1.12.0 的下载地址为 https://www.hdfgroup.org/package/hdf5-1-12-0-tar-gz/?wpdmdl=14582
$ source /fsx/wrf-arm/wrf-install.env $ cd $DOWNLOAD $ curl -o hdf5-1.12.0.tar.gz -J -L https://www.hdfgroup.org/package/hdf5-1-12-0-tar-gz/?wpdmdl=14582 $ tar -xzvf hdf5-1.12.0.tar.gz $ cd hdf5-1.12.0 $ ./configure --prefix=${WRF_INSTALL}/hdf5 --with-zlib=${WRF_INSTALL}/zlib --enable-parallel --enable-shared --enable-hl --enable-fortran $ make -j$(nproc) && make install
Parallel-NETCDF 可在官网 https://parallel-netcdf.github.io/wiki/Download.html 下载最新版本。
$ source /fsx/wrf-arm/wrf-install.env $ cd $DOWNLOAD $ wget -N https://parallel-netcdf.github.io/Release/pnetcdf-1.12.2.tar.gz $ tar -xzvf pnetcdf-1.12.2.tar.gz $ cd pnetcdf-1.12.2 $ ./configure --prefix=${WRF_INSTALL}/pnetcdf --enable-fortran --enable-large-file-test --enable-shared $ make -j$(nproc) && make install
NETCDF 可在官网 https://www.unidata.ucar.edu/downloads/netcdf/ 下载最新版本。
$ source /fsx/wrf-arm/wrf-install.env $ cd $DOWNLOAD $ wget -N https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-4.7.4.tar.gz $ tar -xzvf netcdf-c-4.7.4.tar.gz $ cd netcdf-c-4.7.4 $ ./configure --prefix=$NCDIR CPPFLAGS="-I$HDF5/include -I$PNET/include" CFLAGS="-DHAVE_STRDUP -O3 -march=armv8.2-a+crypto+fp16+rcpc+dotprod" LDFLAGS="-L$HDF5/lib -L$PNET/lib" --enable-pnetcdf --enable-large-file-tests --enable-largefile --enable-parallel-tests --enable-shared --enable-netcdf-4 --with-pic --disable-doxygen --disable-dap $ make -j$(nproc) && make install
$ source /fsx/wrf-arm/wrf-install.env $ wget -N https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-4.5.3.tar.gz $ tar -xzvf netcdf-fortran-4.5.3.tar.gz $ cd netcdf-fortran-4.5.3 $ ./configure --prefix=$NCDIR --disable-static --enable-shared --with-pic --enable-parallel-tests --enable-large-file-tests --enable-largefile $ make -j$(nproc) && make install
WRF 可以在 Github 上下载 https://github.com/wrf-model/WRF/tree/master
$ source /fsx/wrf-arm/wrf-install.env $ cd ${WRF_INSTALL} $ curl -o WRF-v4.2.2.zip -J -L https://github.com/wrf-model/WRF/archive/v4.2.2.zip $ unzip WRF-v4.2.2.zip $ cd WRF-4.2.2
使用你熟悉的编辑器,例如 view 编辑文件arch/configure.defaults
,在行 #insert new stanza here
与 #ARCH Fujitsu FX10/FX100...
之间添加以下内容:
########################################################### #ARCH Linux aarch64, GCC compiler OpenMPI # serial smpar dmpar dm+sm # DESCRIPTION = GCC ($SFC/$SCC): Aarch64 DMPARALLEL = OMPCPP = -fopenmp OMP = -fopenmp OMPCC = -fopenmp SFC = gfortran SCC = gcc CCOMP = gcc DM_FC = mpif90 DM_CC = mpicc -DMPI2_SUPPORT FC = CONFIGURE_FC CC = CONFIGURE_CC LD = $(FC) RWORDSIZE = CONFIGURE_RWORDSIZE PROMOTION = ARCH_LOCAL = CFLAGS_LOCAL = -w -O3 -c LDFLAGS_LOCAL = -fopenmp FCOPTIM = -Ofast -march=armv8.2-a+fp16+rcpc+dotprod+crypto -fopenmp -frecursive -funroll-loops FCREDUCEDOPT = $(FCOPTIM) FCNOOPT = -O0 -fopenmp -frecursive FCDEBUG = -g $(FCNOOPT) FORMAT_FIXED = -ffixed-form -ffixed-line-length-0 -fallow-argument-mismatch -fallow-invalid-boz FORMAT_FREE = -ffree-form -ffree-line-length-0 -fallow-argument-mismatch -fallow-invalid-boz FCSUFFIX = BYTESWAPIO = -fconvert=big-endian -frecord-marker=4 FCBASEOPTS = -w $(FORMAT_FREE) $(BYTESWAPIO) MODULE_SRCH_FLAG= -I$(WRF_SRC_ROOT_DIR)/main TRADFLAG = -traditional-cpp CPP = /lib/cpp CONFIGURE_CPPFLAGS AR = ar ARFLAGS = ru M4 = m4 -B 14000 RANLIB = ranlib RLFLAGS = CC_TOOLS = $(SCC)
$ ./configure 编译选项选择 8. (dm+sm) GCC (gfortran/gcc): Aarch64 Select Option 1 -Compile for nesting? (1=basic, 2=preset moves, 3=vortex following) [default 1]:
$ ./compile -j $(nproc) em_real 2>&1 | tee compile_wrf.out
编译成功后,你可以在main目录下 WRF-4.2.2/main
找到WRF的EXE文件
main/ndown.exe
main/real.exe
main/tc.exe
main/wrf.exe
下载 Jasper
$ source /fsx/wrf-arm/wrf-install.env $ cd $DOWNLOAD $ wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/jasper-1.900.1.tar.gz $ tar -xzvf jasper-1.900.1.tar.gz
在编译之前,我们需要从 http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD 下载config.guess
文件并覆盖目录 jasper-1.900.1 下的 acaux/config.guess
执行以下命令进行下载并覆盖原config.guess文件
$ cd $DOWNLOAD/jasper-1.900.1 $ wget -N -O acaux/config.guess "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD"
$ cd $DOWNLOAD/jasper-1.900.1 $ ./configure --prefix=${WRF_INSTALL}/jasper $ make -j$(nproc) install
下载最新版本的 WPS https://github.com/wrf-model/WPS/releases/ 以下示例下载并安装4.2版本
$ source /fsx/wrf-arm/wrf-install.env $ cd $DOWNLOAD $ curl -o WPS-v4.2.tar.gz -J -L https://github.com/wrf-model/WPS/archive/refs/tags/v4.2.tar.gz $ tar -xzvf WPS-v4.2.tar.gz -C ${WRF_INSTALL} $ cd ${WRF_INSTALL}/WPS-4.2
使用文本编辑器在文件 arch/configure.defaults 顶部添加以下内容
######################################################################################################################## #ARCH Linux aarch64, Arm compiler OpenMPI # serial smpar dmpar dm+sm# COMPRESSION_LIBS = CONFIGURE_COMP_L COMPRESSION_INC = CONFIGURE_COMP_I FDEFS = CONFIGURE_FDEFS SFC = gfortran SCC = gcc DM_FC = mpif90 DM_CC = mpicc FC = CONFIGURE_FC CC = CONFIGURE_CC LD = $(FC) FFLAGS = -ffree-form -O -fconvert=big-endian -frecord-marker=4 -ffixed-line-length-0 -fallow-argument-mismatch -fallow-invalid-boz F77FLAGS = -ffixed-form -O -fconvert=big-endian -frecord-marker=4 -ffree-line-length-0 -fallow-argument-mismatch -fallow-invalid-boz FCSUFFIX = FNGFLAGS = $(FFLAGS) LDFLAGS = CFLAGS = CPP = /usr/bin/cpp -P -traditional CPPFLAGS = -D_UNDERSCORE -DBYTESWAP -DLINUX -DIO_NETCDF -DBIT32 -DNO_SIGNAL CONFIGURE_MPI RANLIB = ranlib
编译安装
$ ./configure
编译选项选择
Linux aarch64, Arm compiler OpenMPI (dmpar)
若遇到如下的输出提示,忽略即可。
Your versions of Fortran and NETCDF are not consistent.
编译之前, 我们还需要修改WPS-4.2目录下的文件 configure.wps
中的 WRF_LIB 值,将 -L$(NETCDF)/lib -lnetcdf
更改成 -L$(NETCDF)/lib -lnetcdff -lnetcdf -lgomp
如下所示:
WRF_LIB = -L$(WRF_DIR)/external/io_grib1 -lio_grib1 \ -L$(WRF_DIR)/external/io_grib_share -lio_grib_share \ -L$(WRF_DIR)/external/io_int -lwrfio_int \ -L$(WRF_DIR)/external/io_netcdf -lwrfio_nf \ -L$(NETCDF)/lib -lnetcdff -lnetcdf -lgomp
执行编译
$ ./compile | tee compile_wps.out
编译成功后,可以在当前目录下看到3个可执行文件:
geogrid.exe → geogrid/src/geogrid.exe
ungrib.exe → ungrib/src/ungrib.exe
metgrid.exe → metgrid/src/metgrid.exe
WRFDA 是一个统一的模型空间数据同化系统,可以全球或区域,多模型,3/4D-Var。其组成及各组成间的联系如图所示。
在4.0之后的版本,WRFDA 的编译安装可以在 WRF 源码上进行。
解压WRF到目录 WRFDA-4.2.2
$ source /fsx/wrf-arm/wrf-install.env $ cd ${WRF_INSTALL} $ unzip -d /tmp WRF-v4.2.2.zip $ mv /tmp/WRF-4.2.2 ${WRF_INSTALL}/WRFDA-4.2.2 $ cd ${WRF_INSTALL}/WRFDA-4.2.2
编译
$ ./configure wrfda
编译选项选择
3. (dmpar)
执行编译
$ ./compile all_wrfvar 2>&1 | tee compile_wrfda.out
编译成功后,你可以在 ${WRF_INSTALL}/WRFDA-4.2.2/var/build/
目录下找到WRFDA的EXE文件
da_wrfvar.exe
下载 OBSGRID
OBSGRID 可以在 Github 下载 https://github.com/wrf-model/OBSGRID
$ source /fsx/wrf-arm/wrf-install.env $ cd ${WRF_INSTALL} $ git clone https://github.com/wrf-model/OBSGRID $ cd ${WRF_INSTALL}/OBSGRID
编译配置文件
使用你熟悉的编辑器,例如 view 编辑文件 arch/configure.defaults,在顶部添加以下内容:
########################################################### #ARCH Linux aarch64, gfortran compiler # FC = gfortran FFLAGS = -ffree-form -O -fconvert=big-endian -frecord-marker=4 -ffixed-line-length-0 -fallow-argument-mismatch -fallow-invalid-boz F77FLAGS = -ffixed-form -O -fconvert=big-endian -frecord-marker=4 -ffree-line-length-0 -fallow-argument-mismatch -fallow-invalid-boz FNGFLAGS = $(FFLAGS) LDFLAGS = CC = gcc CFLAGS = CPP = /usr/bin/cpp -P -traditional CPPFLAGS = -D_UNDERSCORE -DBYTESWAP -DLINUX -DIO_NETCDF -DBIT32 -DNO_SIGNAL
编译
$ ./configure
选择
Select 1. Linux aarch64, gfortran compiler
修改文件 configure.oa
中 NETCDF_LIBS
的值
NETCDF_LIBS = -L${NETCDF}/lib -lnetcdff -lnetcdf
执行编译
$ ./compile 2>&1 | tee -a compile_oa.out
目前缺乏NCAR Graphics Library, 所以编译plot的程序时会收到失败的信息(但不影响OBSGRID的编译)
gfortran -o plot_soundings.exe plot_soundings.o module_mapinfo.o module_report.o module_skewt.o date_pack_module.o -L/lib -lncarg -lncarg_gks -lncarg_c -lX11 -lm -lcairo -L/fsx/wrf-arm/netcdf/lib -lnetcdff -lnetcdf -I/fsx/wrf-arm/netcdf/include
/usr/bin/ld: cannot find -lncarg
/usr/bin/ld: cannot find -lncarg_gks
/usr/bin/ld: cannot find -lncarg_c
/usr/bin/ld: cannot find -lcairo
collect2: error: ld returned 1 exit status
编译成功后,你可以在 OBSGRID 当前目录下${WRF_INSTALL}/OBSGRID找到 OBSGRID 的EXE文件 obsgrid.exe