From 7ab15cbf2cb85f91ab954953332e634159d3284e Mon Sep 17 00:00:00 2001 From: TingLei-daprediction Date: Tue, 9 Jul 2024 18:36:18 +0000 Subject: [PATCH 1/2] change to allow USE_MGBF be able to be off --- src/gsi/CMakeLists.txt | 5 ++++- src/gsi/hybrid_ensemble_isotropic.F90 | 28 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/gsi/CMakeLists.txt b/src/gsi/CMakeLists.txt index f894b0a8a8..db5aab3c88 100644 --- a/src/gsi/CMakeLists.txt +++ b/src/gsi/CMakeLists.txt @@ -29,7 +29,7 @@ endif() option(OPENMP "Enable OpenMP Threading" OFF) option(ENABLE_MKL "Use MKL for LAPACK implementation (if available)" ON) option(USE_GSDCLOUD "Use GSD Cloud Analysis library" OFF) -option(USE_MGBF "Use MGBF library" ON) +option(USE_MGBF "Use MGBF library" OFF) set(GSI_VALID_MODES "GFS" "Regional") set(GSI_MODE "GFS" CACHE STRING "Choose the GSI Application.") @@ -132,6 +132,9 @@ endif() if(USE_GSDCLOUD) list(APPEND GSI_Fortran_defs RR_CLOUDANALYSIS) endif() +if(USE_MGBF) + list(APPEND GSI_Fortran_defs USE_MGBF_def) +endif() # Create a library of GSI C sources add_library(gsi_c_obj OBJECT ${GSI_SRC_C}) diff --git a/src/gsi/hybrid_ensemble_isotropic.F90 b/src/gsi/hybrid_ensemble_isotropic.F90 index 87f3605eaf..fb21e2f517 100644 --- a/src/gsi/hybrid_ensemble_isotropic.F90 +++ b/src/gsi/hybrid_ensemble_isotropic.F90 @@ -104,8 +104,10 @@ module hybrid_ensemble_isotropic use string_utility, only: StrUpCase ! For MGBF +#ifdef USE_MGBF use mg_intstate use mg_timers +#endif /* End of USE_MGBF block */ implicit none @@ -182,7 +184,9 @@ module hybrid_ensemble_isotropic integer(r_kind) :: nval_loc_en ! For MGBF +#ifdef USE_MGBF_def type (mg_intstate_type), allocatable, dimension(:) :: obj_mgbf +#endif /* End of USE_MGBF_def block */ real(r_kind), allocatable, dimension(:,:,:) :: work_mgbf ! following is for special subdomain to slab variables used when internally generating ensemble members @@ -1761,7 +1765,9 @@ subroutine destroy_ensemble enddo deallocate(ps_bar) deallocate(en_perts) +#ifdef USE_MGBF_def if(l_mgbf_loc) call print_mg_timers("mgbf_timing_cpu.csv", print_cpu, mype) +#endif /* End of USE_MGBF_def block */ end if return @@ -3735,6 +3741,8 @@ subroutine bkgcov_a_en_new_factorization(ig,a_en) ! because recursive filter is applied for ig>naensgrp ! to separate scales for scale-dependent localization ! even in MGBF-based localization) + +#ifdef USE_MGBF_def if(l_mgbf_loc.and.ig<=naensgrp) then ! Apply vertical smoother on each ensemble member @@ -3774,6 +3782,7 @@ subroutine bkgcov_a_en_new_factorization(ig,a_en) ! Recursive/Spectral filter-based localization(ig<=naensgrp) ! or scale-separation(ig>naensgrp) else +#endif /* End of USE_MGBF_def block */ ! Apply vertical smoother on each ensemble member ! To avoid my having to touch the general sub2grid and grid2sub, @@ -3824,7 +3833,9 @@ subroutine bkgcov_a_en_new_factorization(ig,a_en) enddo deallocate(a_en_work) +#ifdef USE_MGBF_def endif +#endif /* End of USE_MGBF_def block */ return end subroutine bkgcov_a_en_new_factorization @@ -3892,6 +3903,7 @@ subroutine ckgcov_a_en_new_factorization(ig,z,a_en) endif ! MGBF-based localization (now available only in regional=.true.) +#ifdef USE_MGBF_def if(l_mgbf_loc) then ! Apply horizontal smoother for number of horizontal scales @@ -3925,6 +3937,7 @@ subroutine ckgcov_a_en_new_factorization(ig,z,a_en) ! Recursive/Spectral filter-based localization else +#endif /* End of USE_MGBF_def block */ if(grd_loc%kend_loc+1-grd_loc%kbegin_loc==0) then ! no work to be done on this processor, but hwork still has allocated space, since @@ -3973,8 +3986,9 @@ subroutine ckgcov_a_en_new_factorization(ig,z,a_en) call new_factorization_rf_z(a_en(k)%r3(ipnt)%q,iadvance,iback,ig) enddo - +#ifdef USE_MGBF_def endif +#endif /* End of USE_MGBF_def block */ return end subroutine ckgcov_a_en_new_factorization @@ -4047,6 +4061,7 @@ subroutine ckgcov_a_en_new_factorization_ad(ig,z,a_en) endif ! MGBF-based localization (now available only in regional=.true.) +#ifdef USE_MGBF_def if(l_mgbf_loc) then ! Apply vertical smoother on each ensemble member @@ -4080,6 +4095,7 @@ subroutine ckgcov_a_en_new_factorization_ad(ig,z,a_en) ! Recursive/Spectral filter-based localization else +#endif /* End of USE_MGBF_def block */ ! Apply vertical smoother on each ensemble member iadvance=1 ; iback=2 @@ -4125,11 +4141,14 @@ subroutine ckgcov_a_en_new_factorization_ad(ig,z,a_en) end if end if +#ifdef USE_MGBF_def endif +#endif /* End of USE_MGBF_def block */ return end subroutine ckgcov_a_en_new_factorization_ad +#ifdef USE_MGBF_def subroutine map_work_mgbf(f,g,iadvance,ig) !$$$ subprogram documentation block ! . . . @@ -4198,6 +4217,7 @@ subroutine map_work_mgbf(f,g,iadvance,ig) return end subroutine map_work_mgbf +#endif /* End of USE_MGBF_def block */ ! ------------------------------------------------------------------------------ ! ------------------------------------------------------------------------------ @@ -4538,6 +4558,7 @@ subroutine hybens_localization_setup call normal_new_factorization_rf_z if ( regional ) then ! convert s_ens_h from km to grid units. +#ifdef USE_MGBF_def if ( l_mgbf_loc ) then allocate(obj_mgbf(naensgrp)) do ig=1,naensgrp @@ -4545,6 +4566,7 @@ subroutine hybens_localization_setup call obj_mgbf(ig)%mg_initialize(trim(mgbfname)) enddo endif +#endif /* End of USE_MGBF_def block */ ! Even for MGBF-localization, recursive filter is applied for scale-separation ! in scale-dependent localization, so init_rf_[xy] should be called in nsclgrp>1 if( .not. l_mgbf_loc .or. nsclgrp > 1 ) then @@ -4767,13 +4789,17 @@ subroutine hybens_localization_setup ! nval_loc_en is the number of horizontally-filtered variables in the domain of each processor, ! which is the same as nval_lenz_en (horizontally-global and vertically-local) in recursive/spectral filter ! but horizontally-local and vertically-global in MGBF. +#ifdef USE_MGBF_def if ( l_mgbf_loc ) then nval_loc_en = maxval( obj_mgbf(1:naensgrp)%km_all & & * (obj_mgbf(1:naensgrp)%im + obj_mgbf(1:naensgrp)%hx*2) & & * (obj_mgbf(1:naensgrp)%jm + obj_mgbf(1:naensgrp)%hy*2) ) else +#endif /* End of USE_MGBF_def block */ nval_loc_en = nval_lenz_en +#ifdef USE_MGBF_def endif +#endif /* End of USE_MGBF_def block */ ! setup vertical weighting for ensemble contribution to psfc call setup_pwgt From cf3a3a3c6ab19d99b275d7a129830c11e7fa289a Mon Sep 17 00:00:00 2001 From: TingLei-daprediction Date: Fri, 12 Jul 2024 16:11:56 +0000 Subject: [PATCH 2/2] According to Russ' suggestion, using BUILD_MGBF on the top level to control following mgbf option --- CMakeLists.txt | 2 +- src/gsi/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 176a765262..49101ae24e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ endif() option(OPENMP "Enable OpenMP Threading" OFF) option(ENABLE_MKL "Use MKL for LAPACK implementation (if available)" ON) option(BUILD_GSDCLOUD "Build GSD Cloud Analysis Library" OFF) -option(BUILD_MGBF "Build MGBF Library" ON) +option(BUILD_MGBF "Build MGBF Library" OFF) option(BUILD_GSI "Build GSI" ON) option(BUILD_ENKF "Build EnKF" ON) option(BUILD_REG_TESTING "Build the Regression Testing Suite" OFF) diff --git a/src/gsi/CMakeLists.txt b/src/gsi/CMakeLists.txt index db5aab3c88..f2261fc1bd 100644 --- a/src/gsi/CMakeLists.txt +++ b/src/gsi/CMakeLists.txt @@ -29,7 +29,7 @@ endif() option(OPENMP "Enable OpenMP Threading" OFF) option(ENABLE_MKL "Use MKL for LAPACK implementation (if available)" ON) option(USE_GSDCLOUD "Use GSD Cloud Analysis library" OFF) -option(USE_MGBF "Use MGBF library" OFF) +option(USE_MGBF "Use MGBF library" ${BUILD_MGBF}) set(GSI_VALID_MODES "GFS" "Regional") set(GSI_MODE "GFS" CACHE STRING "Choose the GSI Application.")