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

Fix a bug for Nx Ny in swath grid #2840

Merged
merged 5 commits into from
May 23, 2024
Merged
Changes from 3 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
57 changes: 29 additions & 28 deletions base/MAPL_SwathGridFactory.F90
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,8 @@ function make_new_grid(this, unusable, rc) result(grid)

_UNUSED_DUMMY(unusable)

!!if (mapl_am_I_root()) write(6,*) 'MAPL_SwathGridFactory.F90: bf this%create_basic_grid'
grid = this%create_basic_grid(_RC)
!!if (mapl_am_I_root()) write(6,*) 'MAPL_SwathGridFactory.F90: af this%create_basic_grid'
call this%add_horz_coordinates_from_file(grid,_RC)
!!if (mapl_am_I_root()) write(6,*) 'MAPL_SwathGridFactory.F90: af this%add_horz_coordinates_from_file'

_RETURN(_SUCCESS)
end function make_new_grid

Expand Down Expand Up @@ -482,6 +478,7 @@ subroutine initialize_from_config_with_prefix(this, config, prefix, unusable, rc
_ASSERT (this%lm /= MAPL_UNDEFINED_INTEGER, 'LM: is undefined in swath grid')

call lgr%debug(' %a %a', 'CurrTime =', trim(tmp))
call lgr%debug(' %a %i5 %i5', 'nx, ny = ', this%nx, this%ny)

if ( index(tmp, 'T') /= 0 .OR. index(tmp, '-') /= 0 ) then
call ESMF_TimeSet(currTime, timeString=tmp, _RC)
Expand Down Expand Up @@ -864,7 +861,6 @@ subroutine check_and_fill_consistency(this, unusable, rc)
call this%generate_newnxy(_RC)
end if
end if

_RETURN(_SUCCESS)

contains
Expand Down Expand Up @@ -1145,43 +1141,48 @@ subroutine generate_newnxy(this,unusable,rc)
class (KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc
integer :: n
integer :: j, pet_count

_UNUSED_DUMMY(unusable)

pet_count = this%nx * this%ny
n = this%im_world/this%nx
if (n < 2) then
this%nx = generate_new_decomp(this%im_world,this%nx)
deallocate(this%ims)
allocate(this%ims(0:this%nx-1))
call MAPL_DecomposeDim(this%im_world, this%ims, this%nx)
do j = int(sqrt(real(this%im_world))), 1, -1
if ( mod(pet_count, j) == 0 .and. this%im_world/j >= 2 ) then
exit
end if
end do
this%nx = j
this%ny = pet_count/j
end if

n = this%jm_world/this%ny
if (n < 2) then
this%ny = generate_new_decomp(this%jm_world,this%ny)
deallocate(this%jms)
allocate(this%jms(0:this%ny-1))
call MAPL_DecomposeDim(this%jm_world, this%jms, this%ny)
do j = int(sqrt(real(this%jm_world))), 1, -1
if ( mod(pet_count, j) == 0 .and. this%jm_world/j >=2 ) then
exit
end if
end do
this%ny = j
this%nx = pet_count/j
end if

if ( this%im_world/this%nx < 2 .and. this%jm_world/this%ny < 2 ) then
_FAIL ('Algorithm failed')
end if

deallocate(this%ims)
allocate(this%ims(0:this%nx-1))
call MAPL_DecomposeDim(this%im_world, this%ims, this%nx)
deallocate(this%jms)
allocate(this%jms(0:this%ny-1))
call MAPL_DecomposeDim(this%jm_world, this%jms, this%ny)

_RETURN(_SUCCESS)

end subroutine generate_newnxy

function generate_new_decomp(im,nd) result(n)
integer, intent(in) :: im, nd
integer :: n
logical :: canNotDecomp

canNotDecomp = .true.
n = nd
do while(canNotDecomp)
if ( (im/n) < 2) then
n = n/2
else
canNotDecomp = .false.
end if
enddo
end function generate_new_decomp

subroutine init_halo(this, unusable, rc)
class (SwathGridFactory), target, intent(inout) :: this
Expand Down
Loading