为什么使用 GCC

GCC 10 不仅包含了大量的新架构特性,也是迄今为止性能最好的 GCC 版本。 Arm与不同的合作伙伴以及GCC社区一起,一直在努力提高编译器生成代码的性能。在GCC 10的开发过程中,Arm合作伙伴与广大GCC社区的合作相当有效。其结果是近年来GCC性能的最大提升之一。详见ARM社区发表的文章 Significant performance improvements in GCC 10 through Vectorization and In-lining

D1:与基于 Intel 的 C5n 实例相比,在基于 Arm 的 AWS Graviton2 (C6g/C6gn) 实例上运行这些 NWP 模拟具有高达 40% 的性价比优势。 所以从成本上的考虑,还是建议选择 ARM的实例类型。

根据D1架构决定选择ARM CPU , 同时根据编译器性能测试结果。 GCC 10.2 用于所有 Graviton2(C6g 和 C6gn)选择 GCC 10.2 编译器。当然,如果Parallel Cluster计算节点选择C5n类型,那么就应该选择Intel编译器。

安装 GCC

export WRF_INSTALL=/shared/wrf-arm
export GCC_VERSION=10.2.0
mkdir $WRF_INSTALL
mkdir -p /shared/tools && cd /shared/tools
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

输出

Libraries have been installed in:
   /shared/wrf-arm/gcc-10.2.0/lib/../lib64

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/shared/tools/gcc-10.2.0/obj.gcc-10.2.0/aarch64-unknown-linux-gnu/libatomic'
make[3]: Leaving directory `/shared/tools/gcc-10.2.0/obj.gcc-10.2.0/aarch64-unknown-linux-gnu/libatomic'
make[2]: Leaving directory `/shared/tools/gcc-10.2.0/obj.gcc-10.2.0/aarch64-unknown-linux-gnu/libatomic'
make[1]: Leaving directory `/shared/tools/gcc-10.2.0/obj.gcc-10.2.0'
[ec2-user@ip-10-60-0-12 obj.gcc-10.2.0]$ mkdir /shared/tools
mkdir: cannot create directory ‘/shared/tools’: File exists

安装 OpenMPI

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 CC=gcc
export CXX=g++
export FC=gfortran
#安装OpenMPI 4.1.0
cd /shard/tools
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

输出

make[3]: Entering directory `/shared/tools/openmpi-4.1.0/build/test'
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/shared/tools/openmpi-4.1.0/build/test'
make[2]: Leaving directory `/shared/tools/openmpi-4.1.0/build/test'
make[1]: Leaving directory `/shared/tools/openmpi-4.1.0/build/test'
make[1]: Entering directory `/shared/tools/openmpi-4.1.0/build'
make[2]: Entering directory `/shared/tools/openmpi-4.1.0/build'
make  install-exec-hook
make[3]: Entering directory `/shared/tools/openmpi-4.1.0/build'
make[3]: Leaving directory `/shared/tools/openmpi-4.1.0/build'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/shared/tools/openmpi-4.1.0/build'
make[1]: Leaving directory `/shared/tools/openmpi-4.1.0/build'

安装 zlib

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
cd /shard/tools
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

输出

uncompress(): hello, hello!
gzread(): hello, hello!
gzgets() after gzseek:  hello!
inflate(): hello, hello!
large_inflate(): OK
after inflateSync(): hello, hello!
inflate with dictionary: hello, hello!
                *** zlib 64-bit test OK ***
rm -f /shared/wrf-arm/zlib/lib/libz.a
cp libz.a /shared/wrf-arm/zlib/lib
chmod 644 /shared/wrf-arm/zlib/lib/libz.a
cp libz.so.1.2.11 /shared/wrf-arm/zlib/lib
chmod 755 /shared/wrf-arm/zlib/lib/libz.so.1.2.11
rm -f /shared/wrf-arm/zlib/share/man/man3/zlib.3
cp zlib.3 /shared/wrf-arm/zlib/share/man/man3
chmod 644 /shared/wrf-arm/zlib/share/man/man3/zlib.3
rm -f /shared/wrf-arm/zlib/lib/pkgconfig/zlib.pc
cp zlib.pc /shared/wrf-arm/zlib/lib/pkgconfig
chmod 644 /shared/wrf-arm/zlib/lib/pkgconfig/zlib.pc
rm -f /shared/wrf-arm/zlib/include/zlib.h /shared/wrf-arm/zlib/include/zconf.h
cp zlib.h zconf.h /shared/wrf-arm/zlib/include
chmod 644 /shared/wrf-arm/zlib/include/zlib.h /shared/wrf-arm/zlib/include/zconf.h

安装 hdf5

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=mpic++
export FC=mpifort
export F90=mpifort
cd /shard/tools
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

输出

+ /usr/bin/install -c ./ex_table_03.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_table_04.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_table_05.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_table_06.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_table_07.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_table_08.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_table_09.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_table_10.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_table_11.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_table_12.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./ex_ds1.c /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./image24pixel.txt /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./image8.txt /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./pal_rgb.h /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c run-hlc-ex.sh /shared/wrf-arm/hdf5/share/hdf5_examples/hl/c/.
+ /usr/bin/install -c ./run-hl-ex.sh /shared/wrf-arm/hdf5/share/hdf5_examples/hl/.
make[2]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/hl/examples'
make[2]: Entering directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/hl/fortran'
make[3]: Entering directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/hl/fortran/examples'
../../../bin/mkdirs /shared/wrf-arm/hdf5/share/hdf5_examples/hl/fortran
+ /usr/bin/install -c ./exlite.f90 /shared/wrf-arm/hdf5/share/hdf5_examples/hl/fortran/.
+ /usr/bin/install -c ./ex_ds1.f90 /shared/wrf-arm/hdf5/share/hdf5_examples/hl/fortran/.
+ /usr/bin/install -c run-hlfortran-ex.sh /shared/wrf-arm/hdf5/share/hdf5_examples/hl/fortran/.
make[3]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/hl/fortran/examples'
make[2]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/hl/fortran'
make[1]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/hl'

安装 parallel-netcdf

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 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"
cd /shard/tools
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

输出

|  To compile your PnetCDF programs, please add the following to the command
|  line, so the compiler can find the PnetCDF header files:
|      -I/shared/wrf-arm/pnetcdf/include
|
|  Add the following line to link your program to PnetCDF library:
|      -L/shared/wrf-arm/pnetcdf/lib -lpnetcdf
|
|  Add the following to your run-time environment variable LD_LIBRARY_PATH,
|  when linking your executable with the PnetCDF shared libraries.
|      /shared/wrf-arm/pnetcdf/lib
|
|
|  PnetCDF is jointly developed by a team at Northwestern University and
|  Argonne National Laboratory.
|
|  Visit PnetCDF project web site for more information
|      https://parallel-netcdf.github.io
|
+----------------------------------------------------------------------------+
make[3]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/pnetcdf-1.12.2'
make[2]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/pnetcdf-1.12.2'
make[1]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/pnetcdf-1.12.2'

安装 NetCDF-C

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
HDF5=${WRF_INSTALL}/hdf5
PNET=${WRF_INSTALL}/pnetcdf
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"
cd /shard/tools
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=${WRF_INSTALL}/netcdf 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

输出

+-------------------------------------------------------------+
| Congratulations! You have successfully installed netCDF!    |
|                                                             |
| You can use script "nc-config" to find out the relevant     |
| compiler options to build your application. Enter           |
|                                                             |
|     nc-config --help                                        |
|                                                             |
| for additional information.                                 |
|                                                             |
| CAUTION:                                                    |
|                                                             |
| If you have not already run "make check", then we strongly  |
| recommend you do so. It does not take very long.            |
|                                                             |
| Before using netCDF to store important data, test your      |
| build with "make check".                                    |
|                                                             |
| NetCDF is tested nightly on many platforms at Unidata       |
| but your platform is probably different in some ways.       |
|                                                             |
| If any tests fail, please see the netCDF web site:          |
| http://www.unidata.ucar.edu/software/netcdf/                |
|                                                             |
| NetCDF is developed and maintained at the Unidata Program   |
| Center. Unidata provides a broad array of data and software |
| tools for use in geoscience education and research.         |
| http://www.unidata.ucar.edu                                 |
+-------------------------------------------------------------+

make[3]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/pnetcdf-1.12.2/netcdf-c-4.7.4'
make[2]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/pnetcdf-1.12.2/netcdf-c-4.7.4'
make[1]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/pnetcdf-1.12.2/netcdf-c-4.7.4

安装 NetCDF-F

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
HDF5=${WRF_INSTALL}/hdf5
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"
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

输出

+-------------------------------------------------------------+
| Congratulations! You have successfully installed the netCDF |
| Fortran libraries.                                          |
|                                                             |
| You can use script "nf-config" to find out the relevant     |
| compiler options to build your application. Enter           |
|                                                             |
|     nf-config --help                                        |
|                                                             |
| for additional information.                                 |
|                                                             |
| CAUTION:                                                    |
|                                                             |
| If you have not already run "make check", then we strongly  |
| recommend you do so. It does not take very long.            |
|                                                             |
| Before using netCDF to store important data, test your      |
| build with "make check".                                    |
|                                                             |
| NetCDF is tested nightly on many platforms at Unidata       |
| but your platform is probably different in some ways.       |
|                                                             |
| If any tests fail, please see the netCDF web site:          |
| http://www.unidata.ucar.edu/software/netcdf/                |
|                                                             |
| NetCDF is developed and maintained at the Unidata Program   |
| Center. Unidata provides a broad array of data and software |
| tools for use in geoscience education and research.         |
| http://www.unidata.ucar.edu                                 |
+-------------------------------------------------------------+

make[3]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/pnetcdf-1.12.2/netcdf-c-4.7.4/netcdf-fortran-4.5.3'
make[2]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/pnetcdf-1.12.2/netcdf-c-4.7.4/netcdf-fortran-4.5.3'
make[1]: Leaving directory `/shared/tools/openmpi-4.1.0/build/zlib-1.2.11/hdf5-1.12.0/pnetcdf-1.12.2/netcdf-c-4.7.4/netcdf-fortran-4.5.3'