Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the reading of ensembles and setup for global multiscale runs #594

Merged
merged 51 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b846b29
GitHub Issue NOAA-EMC/GSI#175. Use the global 127L B-Matrix in regio…
jderber-NOAA Aug 13, 2021
05f1c1f
Merge remote-tracking branch 'upstream/master'
jderber-NOAA Sep 30, 2021
059e402
Merge remote-tracking branch 'upstream/master'
jderber-NOAA Oct 15, 2021
f938842
GitHub Issue NOAA-EMC/GSI#219 Improve Minimization and fix bug in vqc
jderber-NOAA Oct 22, 2021
fafadac
Merge remote-tracking branch 'upstream/master'
jderber-NOAA Nov 3, 2021
52c5ae6
fix setupw
jderber-NOAA Nov 5, 2021
f00e377
Merge remote-tracking branch 'upstream/master'
jderber-NOAA Nov 16, 2021
7703367
Merge remote-tracking branch 'upstream/master'
jderber-NOAA Feb 17, 2022
9eb9606
Merge remote-tracking branch 'upstream/master'
jderber-NOAA Feb 23, 2022
3eb0e13
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Jun 17, 2022
ddced98
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Jun 29, 2022
f60343b
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Jul 11, 2022
8dbfbd1
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Jul 14, 2022
1554f65
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Jul 21, 2022
bf060fd
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Aug 29, 2022
3f073fa
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Nov 4, 2022
7f62d1c
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Jan 25, 2023
85cbdb1
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Feb 23, 2023
51a444b
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Mar 3, 2023
0be4126
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Mar 22, 2023
57fda95
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Apr 13, 2023
6336b79
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Apr 17, 2023
a10841d
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA May 10, 2023
7261674
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA May 30, 2023
2fc7545
Optimization first step
jderber-NOAA Jun 8, 2023
d50ae8d
optimization improvements
jderber-NOAA Jun 8, 2023
254c59d
Optimization changes 2
jderber-NOAA Jun 9, 2023
a899e45
Working version 1
jderber-NOAA Jun 15, 2023
d0b9848
additional optimizations
jderber-NOAA Jun 22, 2023
baf7fa7
Additional optimization changes.
jderber-NOAA Jun 26, 2023
f29716b
More optimization changes.
jderber-NOAA Jun 26, 2023
9bf983b
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Jun 27, 2023
a9bc4df
Merge branch 'develop' into optimize3
jderber-NOAA Jun 27, 2023
a41b258
Optimization changes
jderber-NOAA Jun 30, 2023
7a41cc3
merge of genqsat
jderber-NOAA Jul 2, 2023
7f1c0b8
optimization
jderber-NOAA Jul 2, 2023
dcfda80
Removal of update_halos et al.
jderber-NOAA Jul 14, 2023
e4b5630
A few minor changes.
jderber-NOAA Jul 16, 2023
6ba6024
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Jul 26, 2023
4b3aa5b
Merge branch 'develop' into optimize3
jderber-NOAA Jul 26, 2023
5c0d74d
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Aug 30, 2023
89c975f
Merge branch 'develop' into optimize3
jderber-NOAA Aug 30, 2023
00dc30d
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Sep 3, 2023
813b6bf
Merge branch 'develop' into optimize3
jderber-NOAA Sep 3, 2023
3e918e1
Remove line from build.sh
jderber-NOAA Sep 3, 2023
299a1e5
Final update of branch. Fixes error in control_vectors.
jderber-NOAA Sep 21, 2023
7e4f656
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Sep 21, 2023
0b6bde9
Merge branch 'develop' into optimize3
jderber-NOAA Sep 21, 2023
4639bfe
switch back to slightly non-reproducible version
jderber-NOAA Sep 21, 2023
f8f1bbf
Merge remote-tracking branch 'upstream/develop' into develop
jderber-NOAA Sep 22, 2023
982425d
Merge branch 'develop' into optimize3
jderber-NOAA Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 100 additions & 52 deletions src/gsi/apply_scaledepwgts.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ function fwgtofwvlen (rvlft,rvrgt,rcons,rlen,rinput)
!
!$$$ end documentation block

use kinds, only: r_kind,i_kind,r_single
use kinds, only: r_kind
implicit none

real(r_kind),intent(in) :: rvlft,rvrgt,rcons,rlen,rinput
real(r_kind) :: fwgtofwvlen
real(r_kind) :: rlen1,rtem1,rconshalf

rlen1=rlen/10.0_r_kind ! rlen corresponds to a (-5,5) region
rconshalf=0.5_r_kind*rcons
if(rinput > rvlft .and. rinput < rvrgt) then
fwgtofwvlen=rcons
else
rlen1=rlen/10.0_r_kind ! rlen corresponds to a (-5,5) region
rconshalf=0.5_r_kind*rcons
rtem1=min(abs(rinput-rvlft),abs(rinput-rvrgt))
fwgtofwvlen=rconshalf*(1.0_r_kind+tanh(5.0_r_kind-rtem1/rlen1))
endif
Expand All @@ -41,23 +41,21 @@ subroutine init_mult_spc_wgts(jcap_in)
!
!$$$ end documentation block

use kinds, only: r_kind,i_kind,r_single
use constants, only: zero,half,one,two,three,rearth,pi,tiny_r_kind
use kinds, only: r_kind,i_kind
use constants, only: zero,half,one,rearth,pi,tiny_r_kind
use mpimod, only: mype
use general_sub2grid_mod, only: general_sub2grid_create_info
use egrid2agrid_mod,only: g_create_egrid2agrid
use general_sub2grid_mod, only: sub2grid_info
use hybrid_ensemble_parameters, only: nsclgrp
use hybrid_ensemble_parameters, only: spc_multwgt,spcwgt_params,r_ensloccov4scl
implicit none

integer(i_kind),intent(in ) :: jcap_in

integer(i_kind) i
integer(i_kind) i,l,ks
integer(i_kind) ig
real(r_kind) rwv0,rtem1,rtem2
real (r_kind):: fwgtofwvlen
real(r_kind) :: rwv0,rtem1,rtem2
real(r_kind) :: fwgtofwvlen
real(r_kind) :: totwvlength
real(r_kind),dimension(0:jcap_in,nsclgrp) :: spcwgt
logical :: l_sum_spc_weights

! Spectral scale decomposition is differernt between SDL-cross and SDL-nocross
Expand All @@ -67,9 +65,9 @@ subroutine init_mult_spc_wgts(jcap_in)
l_sum_spc_weights = .true.
end if

spc_multwgt(0,1)=one
spcwgt(0,1)=one
do ig=2,nsclgrp
spc_multwgt(0,ig)=zero
spcwgt(0,ig)=zero
end do


Expand All @@ -79,34 +77,66 @@ subroutine init_mult_spc_wgts(jcap_in)
rtem1=zero
do ig=1,nsclgrp
if(ig /= 2) then
spc_multwgt(i,ig)=fwgtofwvlen(spcwgt_params(1,ig),spcwgt_params(2,ig),&
spcwgt_params(3,ig),spcwgt_params(4,ig),totwvlength)
spc_multwgt(i,ig)=min(max(spc_multwgt(i,ig),zero),one)
spcwgt(i,ig)=fwgtofwvlen(spcwgt_params(1,ig),spcwgt_params(2,ig),&
spcwgt_params(3,ig),spcwgt_params(4,ig),totwvlength)
spcwgt(i,ig)=min(max(spcwgt(i,ig),zero),one)
if(l_sum_spc_weights) then
rtem1=rtem1+spc_multwgt(i,ig)
rtem1=rtem1+spcwgt(i,ig)
else
rtem1=rtem1+spc_multwgt(i,ig)*spc_multwgt(i,ig)
rtem1=rtem1+spcwgt(i,ig)*spcwgt(i,ig)
endif
endif
enddo
rtem2 =1.0_r_kind - rtem1
if(rtem2 >= zero) then

if(l_sum_spc_weights) then
spc_multwgt(i,2)=rtem2
spcwgt(i,2)=rtem2
else
spc_multwgt(i,2)=sqrt(rtem2)
spcwgt(i,2)=sqrt(rtem2)
endif
else
if(mype == 0)write(6,*) ' rtem2 < zero ',i,rtem2,(spc_multwgt(i,ig),ig=1,nsclgrp)
spc_multwgt(i,2)=zero
if(mype == 0)write(6,*) ' rtem2 < zero ',i,rtem2,(spcwgt(i,ig),ig=1,nsclgrp)
spcwgt(i,2)=zero
endif
enddo
!! Code borrowed from spvar in splib

spc_multwgt = zero
do ig=1,nsclgrp
do i=0,jcap_in
ks=2*i
spc_multwgt(ks+1,ig)=spcwgt(i,ig)
end do
do i=0,jcap_in
do l=MAX(1,i-jcap_in),MIN(i,jcap_in)
ks=l*(2*jcap_in+1-l)+2*i
spc_multwgt(ks+1,ig) = spcwgt(i,ig)
spc_multwgt(ks+2,ig) = spcwgt(i,ig)
end do
end do
end do


return
end subroutine init_mult_spc_wgts
subroutine destroy_mult_spc_wgts
!$$$ subprogram documentation block
!
! subprogram: destroy_mult_spc_wgts
!
!$$$ end documentation block

use hybrid_ensemble_parameters, only: spc_multwgt,spcwgt_params
implicit none

deallocate(spc_multwgt,spcwgt_params)

subroutine apply_scaledepwgts(grd_in,sp_in,wbundle,spwgts,wbundle2)
return
end subroutine destroy_mult_spc_wgts


subroutine apply_scaledepwgts(m,grd_in,sp_in)
!
! Program history log:
! 2017-03-30 J. Kay, X. Wang - copied from Kleist's apply_scaledepwgts and
Expand All @@ -115,49 +145,67 @@ subroutine apply_scaledepwgts(grd_in,sp_in,wbundle,spwgts,wbundle2)
!
use constants, only: one
use control_vectors, only: control_vector
use kinds, only: r_kind,i_kind
use kinds, only: r_single
use general_specmod, only: general_spec_multwgt
use kinds, only: r_kind,i_kind,r_single
use gsi_bundlemod, only: gsi_bundle
use general_sub2grid_mod, only: general_sub2grid,general_grid2sub
use general_specmod, only: spec_vars
use general_sub2grid_mod, only: sub2grid_info
use mpimod, only: mpi_comm_world,mype
use hybrid_ensemble_parameters, only: spc_multwgt,en_perts,nsclgrp,n_ens
use mpimod, only: mype
implicit none

! Declare passed variables
type(gsi_bundle),intent(in) :: wbundle
type(gsi_bundle),intent(inout) :: wbundle2
integer,intent(in) :: m
type(spec_vars),intent (in):: sp_in
type(sub2grid_info),intent(in)::grd_in
real(r_kind),dimension(0:sp_in%jcap),intent(in):: spwgts

! Declare local variables
integer(i_kind) kk
integer(i_kind) kk,ig,n,ig2,i,j

real(r_kind),dimension(grd_in%nlat*grd_in%nlon*grd_in%nlevs_alloc) :: hwork
real(r_kind),dimension(grd_in%nlat,grd_in%nlon,grd_in%nlevs_alloc) :: work
real(r_kind),dimension(sp_in%nc):: spc1

! Beta1 first
! Get from subdomains to
call general_sub2grid(grd_in,wbundle%values,hwork)
work=reshape(hwork,(/grd_in%nlat,grd_in%nlon,grd_in%nlevs_alloc/))

do kk=1,grd_in%nlevs_alloc
! Transform from physical space to spectral space
call general_g2s0(grd_in,sp_in,spc1,work(:,:,kk))

! Apply spectral weights
call general_spec_multwgt(sp_in,spc1,spwgts)
! Transform back to physical space
call general_s2g0(grd_in,sp_in,spc1,work(:,:,kk))
real(r_single),dimension(grd_in%nlat,grd_in%nlon,grd_in%nlevs_alloc,nsclgrp) :: hwork2
real(r_kind),dimension(grd_in%nlat,grd_in%nlon) :: work
real(r_kind),dimension(sp_in%nc,grd_in%nlevs_alloc):: spc1
real(r_kind),dimension(sp_in%nc):: spc2

do n=1,n_ens
! Get from subdomains to full grid
call general_sub2grid(grd_in,en_perts(n,1,m)%valuesr4(:),hwork2(:,:,:,1))

!$omp parallel do schedule(static,1) private(i,j,kk,work)
do kk=1,grd_in%nlevs_loc
do j=1,grd_in%nlon
do i=1,grd_in%nlat
work(i,j)=hwork2(i,j,kk,1)
end do
end do
! Transform from physical space to spectral space
call general_g2s0(grd_in,sp_in,spc1(1,kk),work)

end do
!$omp parallel do schedule(static,1) private(kk,ig,ig2,i,j,work,spc2)
do ig2=1,nsclgrp*grd_in%nlevs_loc
ig=(ig2-1)/grd_in%nlevs_loc+1
kk=ig2-(ig-1)*grd_in%nlevs_loc

do i=1,sp_in%nc
spc2(i)=spc1(i,kk)*spc_multwgt(i,ig)
end do
! Apply spectral weights
! Transform back to physical space
call general_s2g0(grd_in,sp_in,spc2,work)

do j=1,grd_in%nlon
do i=1,grd_in%nlat
hwork2(i,j,kk,ig)=work(i,j)
end do
end do
end do
do ig=1,nsclgrp

! Transfer work back to subdomains
call general_grid2sub(grd_in,hwork2(:,:,:,ig),en_perts(n,ig,m)%valuesr4(:))
end do
end do

! Transfer work back to subdomains
hwork=reshape(work,(/grd_in%nlat*grd_in%nlon*grd_in%nlevs_alloc/))
call general_grid2sub(grd_in,hwork,wbundle2%values)

return
end subroutine apply_scaledepwgts
8 changes: 5 additions & 3 deletions src/gsi/control_vectors.f90
Original file line number Diff line number Diff line change
Expand Up @@ -897,21 +897,23 @@ real(r_quad) function qdot_prod_sub(xcv,ycv)
itot=max(m3d,0)+max(m2d,0)
if(l_hyb_ens)itot=itot+n_ens*naensgrp
allocate(partsum(itot))
partsum=zero_quad
do ii=1,nsubwin
!$omp parallel do schedule(dynamic,1) private(i)
do i = 1,m3d
partsum(i) = dplevs(xcv%step(ii)%r3(i)%q,ycv%step(ii)%r3(i)%q,ihalo=1)
partsum(i) = partsum(i)+dplevs(xcv%step(ii)%r3(i)%q,ycv%step(ii)%r3(i)%q,ihalo=1)
enddo
!$omp parallel do schedule(dynamic,1) private(i)
do i = 1,m2d
partsum(m3d+i) = dplevs(xcv%step(ii)%r2(i)%q,ycv%step(ii)%r2(i)%q,ihalo=1)
partsum(m3d+i) = partsum(m3d+i)+dplevs(xcv%step(ii)%r2(i)%q,ycv%step(ii)%r2(i)%q,ihalo=1)
enddo
if(l_hyb_ens) then
do ig=1,naensgrp
nigtmp=n_ens*(ig-1)
!$omp parallel do schedule(dynamic,1) private(i)
do i = 1,n_ens
partsum(m3d+m2d+nigtmp+i) = dplevs(xcv%aens(ii,ig,i)%r3(1)%q,ycv%aens(ii,ig,i)%r3(1)%q,ihalo=1)
partsum(m3d+m2d+nigtmp+i) = partsum(m3d+m2d+nigtmp+i) + &
dplevs(xcv%aens(ii,ig,i)%r3(1)%q,ycv%aens(ii,ig,i)%r3(1)%q,ihalo=1)
end do
end do
end if
Expand Down
Loading