GSI编译和安装

操作步骤

  1. 执行以下命令进入目录解压安装包。

    cd /path/to/hwrf/wrfrun/sorc/
    tar -xvf ../../HWRF_v4.0a_GSI.tar.gz

  2. 执行以下命令设置编译变量。

    export LAPACK_PATH=${KML_LIB}

  3. 执行以下命令新建补丁patch-GSI。

    vim patch-GSI

    输入以下内容并保存。

    diff -Nru GSI/dtc/arch/configure.defaults GSI_ok/dtc/arch/configure.defaults
    --- GSI/dtc/arch/configure.defaults	2018-11-02 04:54:16.000000000 +0800
    +++ GSI_ok/dtc/arch/configure.defaults	2023-07-21 10:21:37.739770420 +0800
    @@ -844,3 +844,51 @@
    
     ##################################################################
     #ARCH	NULL
    +##################################################################
    +#ARCH Linux aarch64,clang2 HYPERMPI # (dmpar,optimize)
    +#
    +LDFLAGS        =  -Wl,-rpath,CONFIGURE_NETCDF_PATH/lib
    +OMP            =  -fopenmp
    +COREDIR        =  CONFIGURE_CORE_PATH
    +INC_DIR        =  $(COREDIR)/include
    +SFC            =  flang
    +SF90           =  flang
    +SCC            =  clang
    +INC_FLAGS      =  -module $(INC_DIR) -I $(INC_DIR) -I CONFIGURE_NETCDF_PATH/include
    +FFLAGS_i4r4    =
    +FFLAGS_i4r8    =  -r8
    +FFLAGS_i8r8    =  -i8 -r8
    +FFLAGS_DEFAULT =  -fconvert=big-endian
    +FFLAGS_DEBUG   =  -O0 -g
    +FFLAGS_OPT     =  -O3
    +FFLAGS         =  -O3 $(FFLAGS_DEFAULT) $(INC_FLAGS) $(LDFLAGS) -DLINUX -ffree-form
    +# Library build flags
    +FFLAGS_BACIO   =  -O3 $(FFLAGS_DEFAULT)
    +ARFLAGS_BACIO  =
    +FFLAGS_BUFR    =  -O3 $(FFLAGS_DEFAULT) $(FFLAGS_i4r8)
    +CFLAGS_BUFR    =  -O3 -DUNDERSCORE
    +ARFLAGS_BUFR   =
    +FFLAGS_CLOUD   =  -O3 $(FFLAGS_DEFAULT)
    +FFLAGS_CRTM    =  -O2 $(FFLAGS_DEFAULT)
    +LFLAGS_CRTM    =
    +FFLAGS_GFSIO   =  -O3 $(FFLAGS_DEFAULT) $(FFLAGS_i4r4)
    +ARFLAGS_GFSIO  =
    +FFLAGS_SFCIO   =  -O3 $(FFLAGS_DEFAULT) $(FFLAGS_i4r4)
    +FFLAGS_SIGIO   =  -O3 $(FFLAGS_DEFAULT) $(FFLAGS_i4r4)
    +ARFLAGS_SIGIO  =
    +FFLAGS_SP      =  -O3 $(FFLAGS_DEFAULT) $(FFLAGS_i4r8)
    +FFLAGS_W3      =  -O3 $(FFLAGS_DEFAULT)
    +#
    +CPP            =  /lib/cpp
    +CPP_FLAGS      =   -P -D_REAL8_ -DWRF -DLINUX -traditional
    +CPP_F90FLAGS   =
    +DM_FC          =  mpif90
    +DM_F90         =  mpif90
    +DM_CC          =  mpicc
    +FC             =  CONFIGURE_FC
    +F90            =  CONFIGURE_F90
    +CC             =  CONFIGURE_CC
    +CFLAGS         =  -O0 -DLINUX -DUNDERSCORE
    +CFLAGS2        =  -DLINUX -Dfunder -DFortranByte=char -DFortranInt=int -DFortranLlong='long long'
    +MYLIBsys       =  -L$(LAPACK_PATH)/kblas/omp/ -lkblas -L$(LAPACK_PATH) -lklapack_full
    +NETCDF_PATH    =
    diff -Nru GSI/src/mod_vtrans.f90 GSI_ok/src/mod_vtrans.f90
    --- GSI/src/mod_vtrans.f90	2018-11-02 04:54:16.000000000 +0800
    +++ GSI_ok/src/mod_vtrans.f90	2023-07-21 10:19:36.095770420 +0800
    @@ -1300,10 +1300,11 @@
                    iz=n*(j-1)
                    do 20 i=k,n
                       ij=iz+i
    -   10             if(abs(biga)-abs(a(ij))) 15,20,20
    +   10             if((abs(biga)-abs(a(ij))) .lt. zero_quad) then
        15             biga=a(ij)
                       l(k)=i
                       m(k)=j
    +                  endif
        20       continue
     !
     !        interchange rows
    @@ -1333,14 +1334,16 @@
     !        divide column by minus pivot (value of pivot element is
     !        contained in biga)
     !
    -   45             if(biga) 48,46,48
    +   45             if(biga .eq. zero_quad) then
        46             d=zero_quad
                       return
    +                  else
        48             do 55 i=1,n
                          if(i-k) 50,55,50
        50                ik=nk+i
                          a(ik)=a(ik)/(-biga)
        55             continue
    +                  endif
     !
     !        reduce matrix
     !
    diff -Nru GSI/src/m_rerank.f90 GSI_ok/src/m_rerank.f90
    --- GSI/src/m_rerank.f90	2018-11-02 04:54:16.000000000 +0800
    +++ GSI_ok/src/m_rerank.f90	2023-07-21 10:13:31.363770420 +0800
    @@ -1,3 +1,21 @@
    +function rerank_hack_2in1r8_(ln,i2) result(i1)
    +  use kinds, only: r_double,i_kind
    +  implicit none
    +  integer(i_kind),intent(in) :: ln
    +  real(r_double),dimension(ln),target,intent(in):: i2
    +  real(r_double),pointer,dimension(:):: i1
    +  i1 => i2
    +end function rerank_hack_2in1r8_
    +
    +function rerank_hack_2in1r4_(ln,i2) result(i1)
    +  use kinds, only: r_single,i_kind
    +  implicit none
    +  integer(i_kind),intent(in) :: ln
    +  real(r_single),dimension(ln),target,intent(in):: i2
    +  real(r_single),pointer,dimension(:):: i1
    +  i1 => i2
    +end function rerank_hack_2in1r4_
    +
     module m_rerank
     ! From Jing Guo - use kinds for GSI consitency (Todling)
     ! 01Aug2011 - Lueken  - changed F90 to f90 (no machine logic
    @@ -281,23 +299,23 @@
     end module m_rerank
    
     ! These must live outside module to trick compiler
    -function rerank_hack_2in1r8_(ln,i2) result(i1)
    -  use kinds, only: r_double,i_kind
    -  implicit none
    -  integer(i_kind),intent(in) :: ln
    -  real(r_double),dimension(ln),target,intent(in):: i2
    -  real(r_double),pointer,dimension(:):: i1
    -  i1 => i2
    -end function rerank_hack_2in1r8_
    -
    -function rerank_hack_2in1r4_(ln,i2) result(i1)
    -  use kinds, only: r_single,i_kind
    -  implicit none
    -  integer(i_kind),intent(in) :: ln
    -  real(r_single),dimension(ln),target,intent(in):: i2
    -  real(r_single),pointer,dimension(:):: i1
    -  i1 => i2
    -end function rerank_hack_2in1r4_
    +!function rerank_hack_2in1r8_(ln,i2) result(i1)
    +!  use kinds, only: r_double,i_kind
    +!  implicit none
    +!  integer(i_kind),intent(in) :: ln
    +!  real(r_double),dimension(ln),target,intent(in):: i2
    +!  real(r_double),pointer,dimension(:):: i1
    +!  i1 => i2
    +!end function rerank_hack_2in1r8_
    +
    +!function rerank_hack_2in1r4_(ln,i2) result(i1)
    +!  use kinds, only: r_single,i_kind
    +!  implicit none
    +!  integer(i_kind),intent(in) :: ln
    +!  real(r_single),dimension(ln),target,intent(in):: i2
    +!  real(r_single),pointer,dimension(:):: i1
    +!  i1 => i2
    +!end function rerank_hack_2in1r4_
    
     function rerank_hack_1in2r8_(l1,l2,i1) result(i2)
       use kinds, only: r_double,i_kind
    @@ -352,3 +370,4 @@
       real(r_single),pointer,dimension(:,:,:,:):: i4
       i4 => i1
     end function rerank_hack_1in4r4_
    +

  4. 执行以下命令打入补丁patch-GSI。

    patch -p0 < ./patch-GSI

  5. 执行以下命令进入目录配置生成编译文件。

    cd GSI/dtc
    echo 1 | ./configure

  6. 执行以下命令进行编译。

    ./compile 2>&1 | tee -a build.log

  7. 执行以下命令查看二进制文件。

    ls -l run/*.exe

    成功编译后将在目录run中生成可执行文件“gsi.exe”。