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

Added optional flag to time_interp_external to speedup initialization #1427

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
47 changes: 37 additions & 10 deletions time_interp/time_interp_external2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ module time_interp_external2_mod
integer, private :: num_io_buffers = 2 ! set -1 to read all records from disk into memory
logical, private :: module_initialized = .false.
logical, private :: debug_this_module = .false.
logical, private :: check_uniform_times=.false. !< If true, check for uniform time axis
!! in all files in order to speedup initialization for
!! large files.

public init_external_field, time_interp_external, time_interp_external_init, &
time_interp_external_exit, get_external_field_size, get_time_axis, get_external_field_missing
Expand Down Expand Up @@ -183,7 +186,7 @@ subroutine time_interp_external_init()
integer :: io_status, logunit, ierr

namelist /time_interp_external_nml/ num_io_buffers, debug_this_module, &
max_fields, max_files
max_fields, max_files, check_uniform_times

! open and read namelist

Expand Down Expand Up @@ -285,11 +288,10 @@ function init_external_field(file,fieldname,domain,desired_units,&
logical, optional :: ongrid !< Optional flag indicating if the data is ongrid

logical :: ongrid_local !< Flag indicating if the data is ongrid

integer :: init_external_field

real(r8_kind) :: slope, intercept
integer :: ndim,ntime,i,j
real(r8_kind) :: slope, intercept, dtime
integer :: ndim,ntime,i,j,n
integer :: iscomp,iecomp,jscomp,jecomp,isglobal,ieglobal,jsglobal,jeglobal
integer :: isdata,iedata,jsdata,jedata, dxsize, dysize,dxsize_max,dysize_max
logical :: verb, transpose_xy,use_comp_domain1
Expand Down Expand Up @@ -323,7 +325,6 @@ function init_external_field(file,fieldname,domain,desired_units,&
if (debug_this_module) verb = .true.
numwindows = 1
if(present(nwindows)) numwindows = nwindows

units = 'same'
if (PRESENT(desired_units)) then
units = desired_units
Expand Down Expand Up @@ -384,11 +385,37 @@ function init_external_field(file,fieldname,domain,desired_units,&
allocate(pes(mpp_npes()))
call mpp_get_current_pelist(pes)
allocate(tstamp(ntime),tstart(ntime),tend(ntime),tavg(ntime))

!< Only root reads the unlimited dimension and broadcasts it to the other ranks
if (mpp_root_pe() .eq. mpp_pe()) call read_data(fileobj, timename, tstamp)
call mpp_broadcast(tstamp, size(tstamp), mpp_root_pe(), pelist=pes)
deallocate(pes)
if (check_uniform_times .and. ntime .gt. 4) then
if (mpp_root_pe() .eq. mpp_pe()) &
call read_data(fileobj,timename,tstamp,corner=(/1/),edge_lengths=(/3/))
call mpp_broadcast(tstamp(1:3), 3, mpp_root_pe(), pelist=pes)
if((tstamp(3)-tstamp(2)).eq.(tstamp(2)-tstamp(1))) then
if (mpp_root_pe() .eq. mpp_pe()) &
call read_data(fileobj,timename,tstamp(ntime),unlim_dim_level=ntime)
call mpp_broadcast(tstamp(ntime:ntime), 1, mpp_root_pe(), pelist=pes)
dtime=tstamp(2)-tstamp(1)
do n=2,ntime-1
tstamp(n)=tstamp(n-1)+dtime
enddo
if (abs(tstamp(ntime)-tstamp(ntime-1)-dtime).gt.0.01*dtime) then
call mpp_error(WARNING,"init_external_field:"//&
" Uniform time check failed. Reverting to slow initialization ")
if (mpp_root_pe() .eq. mpp_pe()) &
call read_data(fileobj,timename,tstamp)
call mpp_broadcast(tstamp, size(tstamp), mpp_root_pe(), pelist=pes)
endif
deallocate(pes)
else
if (mpp_root_pe() .eq. mpp_pe()) call read_data(fileobj, timename, tstamp)
call mpp_broadcast(tstamp, size(tstamp), mpp_root_pe(), pelist=pes)
deallocate(pes)
endif
else
!< Only root reads the unlimited dimension and broadcasts it to the other ranks
if (mpp_root_pe() .eq. mpp_pe()) call read_data(fileobj, timename, tstamp)
call mpp_broadcast(tstamp, size(tstamp), mpp_root_pe(), pelist=pes)
deallocate(pes)
endif

transpose_xy = .false.
isdata=1; iedata=1; jsdata=1; jedata=1
Expand Down
Loading