当下需要使用WRF来进行既简单且理想情景的模拟,需要知道的是WRF在1, 2, 4, 8, 16, 32 core(s) 情形下的运算速度以及并行的线性性如何。

  • 环境: 32 Cores - Red Hat Enterprise Linux 8.10 (Ootpa), Kernel version: 4.18.0-553.22.1.el8_10.x86_64
  • 我:WRF小白,女朋友WRF-Chem资深用户。
  • 既然要拿来比较,那就选“最新”的版本,V4.0, 也讲武德。(我也想用稳定版本)
  • 纲领:https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compilation_tutorial.php

环境check

略,按照网站的步骤,下载脚本,运行。
这里说一下, 我的gcc –version :gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-22), 但是不影响安装。

依赖

安装依赖前我的setenv.sh, 记得source一下:

bash
export DIR=/data/jihenghu/WRFv4/Build_WRF/LIBRARIES
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
export LDFLAGS=-L$DIR/grib2/lib
export CPPFLAGS=-I$DIR/grib2/include

按照网站的说明一步步安装,因为之前安装RTTOV13时已经安装了NETCDF,HDF5,PHDF5,有些直接跳过了,我重新安装了zlib2 和mpich, 并且:

bash
export PATH=/data/jihenghu/WRFv4/Build_WRF/LIBRARIES/mpich/bin:$PATH ***
export HDF5=/home/jihenghu/hdf5 ***
export PHDF5=/home/jihenghu/hdf5-parallel-1.14.0/
export LD_LIBRARY_PATH=/home/jihenghu/netcdf/lib:/home/jihenghu/hdf5/lib:/home/jihenghu/zlib/lib:$LD_LIBRARY_PATH
export RTTOV=/home/jihenghu/rttov13

***表示必须设置

最后你的环境大概是这样的:

sh
LD_LIBRARY_PATH=/home/jihenghu/netcdf/lib:/home/jihenghu/hdf5/lib:/home/jihenghu/zlib/lib
RTTOV=/home/jihenghu/rttov13
NETCDF=/home/jihenghu/netcdf
CC=gcc
JASPERINC=/data/jihenghu/WRFv4/Build_WRF/LIBRARIES/grib2/include
DIR=/data/jihenghu/WRFv4/Build_WRF/LIBRARIES
F77=gfortran
FCFLAGS=-m64
HDF5=/home/jihenghu/hdf5
PHDF5=/home/jihenghu/hdf5-parallel-1.14.0/
FC=gfortran
JASPERLIB=/data/jihenghu/WRFv4/Build_WRF/LIBRARIES/grib2/lib
CXX=g++
FFLAGS=-m64
CPPFLAGS=-I/data/jihenghu/WRFv4/Build_WRF/LIBRARIES/grib2/include
LDFLAGS=-L/data/jihenghu/WRFv4/Build_WRF/LIBRARIES/grib2/lib

安装WRF

解压,进入WRF/目录,
配置:

bash
$./configure 
checking for perl5... no
checking for perl... found /usr/bin/perl (perl)
Will use NETCDF in dir: /home/jihenghu/netcdf
Will use HDF5 in dir: /home/jihenghu/hdf5
Will use PHDF5 in dir: /home/jihenghu/hdf5-parallel-1.14.0/
Will use 'time' to report timing information

....
Enter selection [1-75] : 34

选择了 34. (dmpar) GNU (gfortran/gcc) 这个编译器。

接下来编译,我计划只跑理想情景,所以选择 em_tropical_cyclone (3d ideal case)

bash
./compile em_tropical_cyclone >& log.compile 

一般来说,这个过程7分钟会跑完,你会在 WRF/main/下发现 wrf.exe 和 ideal.exe。

极有可能遇到的坑

但是可能是code版本问题,有些库的位置变了,我遇到了以下问题,

bash
log.compile
mpicc -cc=gcc -DFSEEKO64_OK  -o landread.o -c -w -O3 -c  -DDM_PARALLEL -DMAX_HISTORY=25 -DNMM_CORE=0 landread.c
landread.c:68:10: fatal error: rpc/types.h: No such file or directory
#include <rpc/types.h>
^~~~~~~~~~~~~
compilation terminated.
make[2]: [../configure.wrf:372: landread.o] Error 1 (ignored)

这个问题直接google 到(RESOLVED) Problem Compiling WRFV4.0 on Fedora 28: landread error
主要原因是code版本问题,rpc/types.h文件的位置变了,UCAR给出的解决方法是:

Issue a ‘clean -a’ and then reconfigure. Then go into your configure.wrf file and look for the line:
CFLAGS = $(CFLAGS_LOCAL) -DDM_PARALLEL -DSTUBMPI \ -DMAX_HISTORY=$(MAX_HISTORY) -DNMM_CORE=$(WRF_NMM_CORE)

Onto the end of that, add -DLANDREAD_STUFF, so that it now looks like:
CFLAGS = $(CFLAGS_LOCAL) -DDM_PARALLEL -DSTUBMPI \ -DMAX_HISTORY=$(MAX_HISTORY) -DNMM_CORE=$(WRF_NMM_CORE) -DLANDREAD_STUB

Then save that configure file and recompile. This should get your past the problem. Please let us know if that works for you.

解决了这个问题,又出现下个问题:

bash
log.compile
include    module_ra_rrtmg_swk.f90
module_ra_rrtmg_swk.f90:3264:0:

use rrsw_kg20_k, only : absa, ka, absb, kb, forref, selfref, &

internal compiler error: in gfc_trans_use_stmts, at fortran/trans-decl.c:5206
Please submit a full bug report,

这次google到:WRF-V4.1-Known-Problems

Solution: Currently, the solution is to remove the offending code (RRTMG fast for longwave and shortwave). After the user constructs the configure.wrf file (after the configure step, and before the compile step), the configure.wrf file is edited.
Remove this line:
-DBUILD_RRTMG_FAST=1 \
Then the code may be built as usual. Note that in this condition, the WRF code may not be used to run either of the fast RRTMG schemes.

好吧,我能接受。。。

至此,编译问题就成功解决了,是不是很简单?