From d992f828924a3306d7a93882a956f851a9ad04a7 Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Wed, 17 May 2023 10:50:09 -0400 Subject: [PATCH 1/3] fix interpolator? --- interpolator/interpolator.F90 | 37 +++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/interpolator/interpolator.F90 b/interpolator/interpolator.F90 index 843f6e7cdf..7f050abe52 100644 --- a/interpolator/interpolator.F90 +++ b/interpolator/interpolator.F90 @@ -323,9 +323,10 @@ 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 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 @@ -445,6 +446,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 " // & @@ -510,6 +514,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. @@ -520,8 +526,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 @@ -3854,6 +3866,27 @@ end subroutine interp_linear ! !######################################################################## + function mpp_set_pes_group(gpelist, n) & + result(pelist) + integer, intent(in) :: gpelist(:) + integer, intent(in) :: n + + integer, allocatable :: pelist(:) + integer :: i, pe_begin, pe_end + + 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 !> @} From f6e8fae0601038e9cb86b4211e770582c1f5993a Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Wed, 17 May 2023 17:31:04 -0400 Subject: [PATCH 2/3] add missing include statement --- interpolator/interpolator.F90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interpolator/interpolator.F90 b/interpolator/interpolator.F90 index 7f050abe52..015ff917ab 100644 --- a/interpolator/interpolator.F90 +++ b/interpolator/interpolator.F90 @@ -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, & From ee8107d421e8161147abc2f184a2ae1c0fdbe90d Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Thu, 18 May 2023 07:27:02 -0400 Subject: [PATCH 3/3] add documentation --- interpolator/interpolator.F90 | 47 +++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/interpolator/interpolator.F90 b/interpolator/interpolator.F90 index 015ff917ab..6caf281f3d 100644 --- a/interpolator/interpolator.F90 +++ b/interpolator/interpolator.F90 @@ -324,7 +324,8 @@ 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 +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, ngroup @@ -3867,26 +3868,30 @@ end subroutine interp_linear ! !######################################################################## - function mpp_set_pes_group(gpelist, n) & - result(pelist) - integer, intent(in) :: gpelist(:) - integer, intent(in) :: n - - integer, allocatable :: pelist(:) - integer :: i, pe_begin, pe_end - - 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 +!> @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