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 physics load balancing twin algorithm initialization #1347

Merged
merged 2 commits into from
Mar 31, 2017
Merged
Changes from all commits
Commits
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
24 changes: 15 additions & 9 deletions components/cam/src/physics/cam/phys_grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ module phys_grid


integer, dimension(:), allocatable, private :: clon_p_cnt ! number of repeats for each longitude
integer, dimension(:), allocatable, private :: clon_p_idx ! index in lonlat ordering for first
! occurrence of longitude corresponding to
! given latitude index
real(r8), dimension(:), allocatable :: clon_p ! unique longitudes (radians, increasing)

integer, dimension(:), allocatable, private :: lat_p ! index into list of unique column latitudes
Expand Down Expand Up @@ -703,6 +706,17 @@ subroutine phys_grid_init( )
! Allocate and initialize chunks data structure, then
! assign chunks to processes.
!
if (twin_alg .eq. 1) then
! precompute clon_p_idx: index in lonlat ordering for first
! occurrence of longitude corresponding to given latitude index,
! used in twin option in create_chunks; used in create_chunks
allocate( clon_p_idx(1:clon_p_tot) )
clon_p_idx(1) = 1
do i=2,clon_p_tot
clon_p_idx(i) = clon_p_idx(i-1) + clon_p_cnt(i-1)
enddo
endif

call create_chunks(lbal_opt, chunks_per_thread)

! Early clean-up, to minimize memory high water mark
Expand All @@ -711,6 +725,7 @@ subroutine phys_grid_init( )
deallocate( latlon_to_dyn_gcol_map )
if (twin_alg .eq. 1) deallocate( lonlat_to_dyn_gcol_map )
if (twin_alg .eq. 1) deallocate( clon_p_cnt )
if (twin_alg .eq. 1) deallocate( clon_p_idx )
if ((twin_alg .eq. 1) .or. (lbal_opt .eq. 3)) deallocate( clat_p_cnt )

!
Expand Down Expand Up @@ -4617,22 +4632,13 @@ subroutine find_twin(gcol, smp, proc_smp_mapx, twingcol_f)
integer :: ibtwin(npes) ! global column indices
integer :: twinproc, twinsmp ! process and smp ids

integer :: clon_p_idx(clon_p_tot) ! index in lonlat ordering for first
! occurrence of longitude corresponding to
! given latitude index

real(r8):: twopi ! 2*pi
real(r8):: clat, twinclat ! latitude and twin
real(r8):: clon, twinclon ! longitude and twin

!-----------------------------------------------------------------------
twingcol_f = -1

! precompute clon_p_idx
clon_p_idx(1) = 1
do i=2,clon_p_tot
clon_p_idx(i) = clon_p_idx(i-1) + clon_p_cnt(i-1)
enddo
!
! Try day/night and north/south hemisphere complement first
!
Expand Down