设置环境变量

export WRF_INSTALL=/shared/wrf-arm
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 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=mpicxx
export FC=mpif90
export F77=mpif90
export F90=mpif90
export HDF5=${WRF_INSTALL}/hdf5
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

下载 WRF

cd ${WRF_INSTALL}
curl -o WRF-v4.2.2.zip -J -L https://chunhua-solutions-cn-north-1.s3.cn-north-1.amazonaws.com.cn/wrf_on_aws/v1.0.0/lib/wrf-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

选择 4 (dm+sm) GNU (gfortran/gcc) 和 1=basic,

Please select from among the following Linux aarch64 options:

  1. (serial)   2. (smpar)   3. (dmpar)   4. (dm+sm)   GNU (gfortran/gcc)

Enter selection [1-4] : 4
------------------------------------------------------------------------
Compile for nesting? (1=basic, 2=preset moves, 3=vortex following) [default 1]:

输出

######################
------------------------------------------------------------------------
Settings listed above are written to configure.wrf.
If you wish to change settings, please edit that file.
If you wish to change the default options, edit the file:
     arch/configure.defaults
NetCDF users note:
 This installation of NetCDF supports large file support.  To DISABLE large file
 support in NetCDF, set the environment variable WRFIO_NCD_NO_LARGE_FILE_SUPPORT
 to 1 and run configure again. Set to any other value to avoid this message.


Testing for NetCDF, C and Fortran compiler

This installation of NetCDF is 64-bit
                 C compiler is 64-bit
           Fortran compiler is 64-bit
              It will build in 64-bit

standard location of RPC
*****************************************************************************
This build of WRF will use classic (non-compressed) NETCDF format
*****************************************************************************

编译 WRF

./compile -j $(nproc) em_real 2>&1 | tee compile_wrf.out

输出

( cd run ; /bin/rm -f ndown.exe ; ln -s ../main/ndown.exe . )
( cd run ; if test -f namelist.input ; then \
        /bin/cp -f namelist.input namelist.input.backup.`date +%Y-%m-%d_%H_%M_%S` ; fi ; \
        /bin/rm -f namelist.input ; cp ../test/em_real/namelist.input . )

==========================================================================
build started:   Fri Aug 27 09:55:17 UTC 2021
build completed: Fri Aug 27 10:19:20 UTC 2021

--->                  Executables successfully built                  <---

-rwxrwxr-x 1 ec2-user ec2-user 36384112 Aug 27 10:19 main/ndown.exe
-rwxrwxr-x 1 ec2-user ec2-user 36449328 Aug 27 10:19 main/real.exe
-rwxrwxr-x 1 ec2-user ec2-user 35986648 Aug 27 10:19 main/tc.exe
-rwxrwxr-x 1 ec2-user ec2-user 42367816 Aug 27 10:17 main/wrf.exe