Skip to content

Commit

Permalink
fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
metdyn committed May 22, 2024
1 parent d546b93 commit 68998b8
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions base/MAPL_SwathGridFactory.F90
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ 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'
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'
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'
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 @@ -1173,44 +1173,50 @@ subroutine generate_newnxy(this,unusable,rc)
class (KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc
integer :: n

integer :: pet_count
integer :: j, fac

_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

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

end subroutine generate_newnxy
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)

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

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
end subroutine generate_newnxy


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

0 comments on commit 68998b8

Please sign in to comment.