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

Fms2 io update: interpolator #1228

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
45 changes: 42 additions & 3 deletions interpolator/interpolator.F90
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ module interpolator_mod
mpp_npes, &
WARNING, &
NOTE, &
input_nml_file
input_nml_file, &
mpp_get_current_pelist
use mpp_domains_mod, only : mpp_domains_init, &
mpp_update_domains, &
mpp_define_domains, &
Expand Down Expand Up @@ -323,9 +324,11 @@ module interpolator_mod
logical :: conservative_interp = .true. !< No description
logical :: retain_cm3_bug = .false. !< No description
logical :: use_mpp_io = .false. !< Set to true to use mpp_io, otherwise fms2io is used
integer :: ngroup = -1 !< Number of groups to divide the current pelist. Each pelist group has a "root" pe that reads
!! and broadcasts the data. The default is to have all ranks reading.

namelist /interpolator_nml/ &
read_all_on_init, verbose, conservative_interp, retain_cm3_bug, use_mpp_io
read_all_on_init, verbose, conservative_interp, retain_cm3_bug, use_mpp_io, ngroup

contains

Expand Down Expand Up @@ -445,6 +448,9 @@ subroutine interpolator_init( clim_type, file_name, lonb_mod, latb_mod, &
read (input_nml_file, nml=interpolator_nml, iostat=io)
ierr = check_nml_error(io,'interpolator_nml')

!< If the ngroup was not set in the namelist, set it to the number of pes to reproduce old behavior
if (ngroup .eq. -1 ) ngroup = mpp_npes()

! retain_cm3_bug is no longer supported.
if (retain_cm3_bug) then
call mpp_error(FATAL, "interpolator_init: You have overridden the default value of " // &
Expand Down Expand Up @@ -510,6 +516,8 @@ subroutine fms2io_interpolator_init(clim_type, file_name, lonb_mod, latb_mod, &
real, allocatable, save :: agrid_mod(:,:,:)
integer :: nx, ny
type(FmsNetcdfFile_t) :: fileobj
integer, dimension(:), allocatable :: global_pes !> Current pelist
integer, dimension(:), allocatable :: pes !> Current pelist

clim_type%separate_time_vary_calc = .false.

Expand All @@ -520,8 +528,14 @@ subroutine fms2io_interpolator_init(clim_type, file_name, lonb_mod, latb_mod, &
!--------------------------------------------------------------------
src_file = 'INPUT/'//trim(file_name)


allocate(global_pes(mpp_npes()))
call mpp_get_current_pelist(global_pes)

pes = mpp_set_pes_group(global_pes, ngroup)

if(fms2_io_file_exist(trim(src_file))) then
if(.not. open_file(clim_type%fileobj, trim(src_file), 'read')) &
if(.not. open_file(clim_type%fileobj, trim(src_file), 'read', pelist=pes)) &
call mpp_error(FATAL, 'Interpolator_init: Error in opening file '//trim(src_file))
fileobj = clim_type%fileobj
else
Expand Down Expand Up @@ -3854,6 +3868,31 @@ end subroutine interp_linear
!
!########################################################################

!> @brief Divide the global pelist into n groups
!! @return Current PEs section of the global pelist
function mpp_set_pes_group(gpelist, n) &
result(pelist)
integer, intent(in) :: gpelist(:) !< Global pelist
integer, intent(in) :: n !< Number of groups to dive the pelist to

integer, allocatable :: pelist(:)
integer :: i !< For do loops
integer :: pe_begin !< The begining pe for the group
integer :: pe_end !< The ending pe for the group

if (mod(size(gpelist), n) .ne. 0) call mpp_error(FATAL, "The global pelist is not divisible by ngroup")
allocate(pelist(int(size(gpelist)/n)))

do i = 1, n
pe_begin = int(size(gpelist)/n) * (i-1)
pe_end = pe_begin + int(size(gpelist)/n) -1
if (mpp_pe() .ge. pe_begin .and. mpp_pe() .le. pe_end) then
pelist=gpelist(pe_begin+1:pe_end+1)
return
endif
enddo
end function

end module interpolator_mod

!> @}
Expand Down