Skip to content
Open
Show file tree
Hide file tree
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
149 changes: 76 additions & 73 deletions GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ subroutine get_enkf_increments( &
integer :: N_obsf_assim, N_obsl_assim
integer :: N_obsl_assim_vec(numprocs)
integer, dimension(:), allocatable :: indObs_ana
integer*8, dimension(:), allocatable :: obs_sort_key
integer, dimension(:), allocatable, target :: ind_obsl_assim
integer, dimension(:), pointer :: ptr2indx => null()
type(varLenIntArr) :: indObsAna_vec(numprocs)
Expand Down Expand Up @@ -877,8 +878,21 @@ subroutine get_enkf_increments( &
end do
if (allocated(tmp_ind_obs)) deallocate(tmp_ind_obs)
if (allocated(select_species)) deallocate(select_species)
! sort obs indices (for layout independence)
if (nObs_ana>1) call MAPL_Sort(indObs_ana(1:nObs_ana))
! sort obs (for layout independence) by global tile_id and species; the order
! of Obs_f_assim follows the processor layout (rank by rank) and matches
! the global tile order only for 1d layouts; index in Obs_f_assim breaks ties
if (nObs_ana>1) then
allocate(obs_sort_key(nObs_ana))
do i=1,nObs_ana
ctr = indObs_ana(i)
obs_sort_key(i) = &
( int(tile_coord_f(Obs_f_assim(ctr)%tilenum)%tile_id,8) &
* int(N_obs_param+1,8) + int(Obs_f_assim(ctr)%species,8) ) &
* int(N_obsf_assim+1,8) + int(ctr,8)
end do
call MAPL_Sort(obs_sort_key, indObs_ana(1:nObs_ana))
deallocate(obs_sort_key)
end if

! Step 3b: nObs_ana -> nObsAna_vec (on root)
call MPI_Gather(nObs_ana,1,MPI_INTEGER, &
Expand Down Expand Up @@ -1647,11 +1661,10 @@ subroutine output_ObsFcstAna(date_time, exp_id, &

#ifdef LDAS_MPI

integer :: this_species, ind_tmp, j
integer :: max_tilenum

integer, dimension(N_obs_param) :: N_per_species
integer, dimension(N_obs_param) :: species_low_ind
integer, dimension(N_obs_param) :: ind_within_species
integer*8, dimension(:), allocatable :: obs_sort_key
integer, dimension(:), allocatable :: obs_sort_ind

#endif

Expand Down Expand Up @@ -1712,78 +1725,47 @@ subroutine output_ObsFcstAna(date_time, exp_id, &

if (root_proc) then

#ifdef LDAS_MPI

! sort observations according to species so that the ObsFcstAna
! file looks the same regardless of the MPI configuration
!
! NOTE: within each species, observations should already be sorted according
! to tilenum because of the loop through species in collect_obs()

! first loop: count how many obs there are per species

N_per_species(1:N_obs_param) = 0

do n=1,N_obsf

this_species = Observations_f(n)%species

N_per_species(this_species) = N_per_species(this_species) + 1

end do

! get starting index of each species in sorted vector Observations_f

species_low_ind(1) = 1

do j=1,N_obs_param-1

species_low_ind(j+1) = species_low_ind(j) + N_per_species(j)

end do

! second loop: re-order Observations_f into Observations_tmp

allocate(Observations_tmp(N_obsf))

ind_within_species(1:N_obs_param) = 0

do n=1,N_obsf

this_species = Observations_f(n)%species

ind_tmp = species_low_ind(this_species) + ind_within_species(this_species)
! reorder tilenum, so it is consistent with the order in tile_coord.bin file
if(present(rf2f)) then
allocate(rf_tilenums(N_obsf), tilenums(N_obsf))
rf_tilenums = Observations_f(:)%tilenum
tilenums = rf2f(rf_tilenums)
Observations_f(:)%tilenum =tilenums
deallocate(rf_tilenums, tilenums)
endif

Observations_tmp(ind_tmp) = Observations_f(n)
#ifdef LDAS_MPI

! NOTE: ind_within_species is "zero-based"
! sort observations according to species and tilenum so that the ObsFcstAna
! file looks the same regardless of the MPI configuration (the gathered obs
! are in tilenum order within each species only for 1d layouts);
! index in gathered vector breaks ties

ind_within_species(this_species) = ind_within_species(this_species) + 1
if (N_obsf>1) then

end do
allocate(obs_sort_key(N_obsf), obs_sort_ind(N_obsf))

! copy back into Observations_f
max_tilenum = maxval(Observations_f(:)%tilenum)

do n=1,N_obsf
do n=1,N_obsf
obs_sort_key(n) = &
( int(Observations_f(n)%species,8) * int(max_tilenum+1,8) &
+ int(Observations_f(n)%tilenum,8) ) * int(N_obsf+1,8) + int(n,8)
obs_sort_ind(n) = n
end do

Observations_f(n) = Observations_tmp(n)
call MAPL_Sort(obs_sort_key, obs_sort_ind)

end do
allocate(Observations_tmp(N_obsf))
Observations_tmp = Observations_f(obs_sort_ind)
Observations_f = Observations_tmp

deallocate(Observations_tmp, obs_sort_key, obs_sort_ind)

deallocate(Observations_tmp)
end if

#endif ! LDAS_MPI

! reorder tilenum, so it is consistent with the order in tile_coord.bin file
if(present(rf2f)) then
allocate(rf_tilenums(N_obsf), tilenums(N_obsf))
rf_tilenums = Observations_f(:)%tilenum
tilenums = rf2f(rf_tilenums)
Observations_f(:)%tilenum =tilenums
deallocate(rf_tilenums, tilenums)
endif

! write to file

if (out_ObsFcstAna == 1 .or. out_ObsFcstAna == 3) then
Expand Down Expand Up @@ -2487,6 +2469,9 @@ subroutine write_smapL4SMaup( option, date_time, exp_id, N_ens, &

real, dimension(:), allocatable :: tile_data_f

integer, dimension(:), allocatable :: f2rf_out
integer*8, dimension(:), allocatable :: tile_id_8

real, dimension( N_catl) :: srfexc, rzexc, catdef
real, dimension( N_catl) :: ar1, ar2, ar4

Expand Down Expand Up @@ -2535,6 +2520,22 @@ subroutine write_smapL4SMaup( option, date_time, exp_id, N_ens, &
open(unitnum, file=fname, form='unformatted', action='write', &
position=position)

! tile_coord_f and the gathered tile data are in the "re-ordered full" (rf) order,
! which follows the processor layout; write tile data in the order of tile_coord.bin
! (ascending tile_id), so the file is the same regardless of the processor layout

allocate(f2rf_out(N_catf), tile_id_8(N_catf))

tile_id_8 = int(tile_coord_f(1:N_catf)%tile_id,8)

do n=1,N_catf
f2rf_out(n) = n
end do

call MAPL_Sort(tile_id_8, f2rf_out)

deallocate(tile_id_8)

end if

! --------------------------------------------------------------
Expand Down Expand Up @@ -3147,8 +3148,8 @@ subroutine write_smapL4SMaup( option, date_time, exp_id, N_ens, &

! write into file

write (unitnum) ( data_h_9km_tile_8(n) , n=1,N_catf)
write (unitnum) ( data_v_9km_tile_8(n) , n=1,N_catf)
write (unitnum) ( data_h_9km_tile_8(f2rf_out(n)) , n=1,N_catf)
write (unitnum) ( data_v_9km_tile_8(f2rf_out(n)) , n=1,N_catf)

else

Expand All @@ -3167,13 +3168,13 @@ subroutine write_smapL4SMaup( option, date_time, exp_id, N_ens, &

! convert to integer before writing to file

write (unitnum) (nint(data_h_9km_tile(n)), n=1,N_catf)
write (unitnum) (nint(data_v_9km_tile(n)), n=1,N_catf)
write (unitnum) (nint(data_h_9km_tile(f2rf_out(n))), n=1,N_catf)
write (unitnum) (nint(data_v_9km_tile(f2rf_out(n))), n=1,N_catf)

else

write (unitnum) ( data_h_9km_tile(n) , n=1,N_catf)
write (unitnum) ( data_v_9km_tile(n) , n=1,N_catf)
write (unitnum) ( data_h_9km_tile(f2rf_out(n)) , n=1,N_catf)
write (unitnum) ( data_v_9km_tile(f2rf_out(n)) , n=1,N_catf)

end if

Expand Down Expand Up @@ -3290,7 +3291,7 @@ subroutine write_smapL4SMaup( option, date_time, exp_id, N_ens, &
call l2f_real( N_catl, N_catf, N_catl_vec, low_ind, &
tile_mean_l(:,k), tile_data_f)

if (root_proc) write(unitnum) (tile_data_f(n), n=1,N_catf)
if (root_proc) write(unitnum) (tile_data_f(f2rf_out(n)), n=1,N_catf)

end do

Expand All @@ -3311,7 +3312,7 @@ subroutine write_smapL4SMaup( option, date_time, exp_id, N_ens, &
call l2f_real( N_catl, N_catf, N_catl_vec, low_ind, &
tile_std_l(:,k), tile_data_f)

if (root_proc) write(unitnum) (tile_data_f(n), n=1,N_catf)
if (root_proc) write(unitnum) (tile_data_f(f2rf_out(n)), n=1,N_catf)

end do

Expand All @@ -3327,6 +3328,8 @@ subroutine write_smapL4SMaup( option, date_time, exp_id, N_ens, &

if (root_proc) close(unitnum,status='keep')

if (allocated(f2rf_out)) deallocate(f2rf_out)

end subroutine write_smapL4SMaup

! -----------------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3261,9 +3261,13 @@ subroutine get_tiles_in_halo( N_catl, N_fields, N_ens, tile_data_l, tile_coord_l
! processor i needs tile_data_l from processor j
! if bounding box around tile_data_l(j) overlaps
! with bounding box plus halo of processor i
!
! use ">=" because the bounding box of processor j has zero width if all
! of its tiles are in a single row or column (e.g., coastal blocks of
! a 2d layout on EASE grids)

if ( (min(ur_lon,maxlon) - max(ll_lon,minlon))>0. .and. &
(min(ur_lat,maxlat) - max(ll_lat,minlat))>0. ) &
if ( (min(ur_lon,maxlon) - max(ll_lon,minlon))>=0. .and. &
(min(ur_lat,maxlat) - max(ll_lat,minlat))>=0. ) &
need_catl(i,j) = .true.

need_catl(j,i) = need_catl(i,j)
Expand Down
1 change: 1 addition & 0 deletions GEOSldas_App/ldas.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def _rc_out_txt(kind):
MY_ENSEMBLE_FORCING= self.ExeInputs.get('ENSEMBLE_FORCING', 'NO').upper(),
MY_ADAS_EXPDIR = self.adas_expdir,
MY_EXPDIR = self.expdir,
MY_TILE_TYPES = '_'.join(self.tile_types),
DETECTED_MPI_STACK = "@MPI_STACK@",
)

Expand Down
9 changes: 9 additions & 0 deletions GEOSldas_App/ldas_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ def _read_resource_inputs(self, cmdLineArgs):

self._verifyResourceInputs()

# optional 2d processor layout: ntasks_model = NX*NY
if 'NX' in self.RmInputs or 'NY' in self.RmInputs:
require('NX' in self.RmInputs and 'NY' in self.RmInputs, 'NX and NY must be specified together')
npes_nx = int(self.RmInputs['NX'])
npes_ny = int(self.RmInputs['NY'])
require(npes_nx >= 1 and npes_ny >= 1, 'NX and NY must be >= 1')
require(npes_nx*npes_ny == int(self.RmInputs['ntasks_model']),
'ntasks_model (%s) must equal NX*NY (%d*%d)' % (self.RmInputs['ntasks_model'], npes_nx, npes_ny))

# print rm inputs
if self.verbose:
print ('\n\nInputs for resource manager:')
Expand Down
37 changes: 27 additions & 10 deletions GEOSldas_App/ldas_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,41 @@ def _copy_nml(self, etcdir):
# -----------------------------------------------------------------------------------
def _optimize_layout(self):
"""
Run preprocess_ldas.x optimize: writes IMS.rc/JMS.rc to rundir and returns the
NX/NY layout (dict). For cube-sphere tile space, ntasks_model may be adjusted.
Run preprocess_ldas.x optimize (1d) or optimize_2d (NX-by-NY): writes IMS.rc and/or
JMS.rc to rundir and returns the NX/NY layout (dict). ntasks_model may be adjusted.
"""
# 2d decomposition (NX-by-NY) unless NX and NY are not specified or the requested layout is
# the 1d layout (cube-sphere: NX=1; lat-lon/EASE: NY=1)
decomp_2d = False
if 'NX' in self.RmInputs:
is_cs = '-CF' in self.ExeInputs['GRIDNAME']
npes_nx = int(self.RmInputs['NX'])
npes_ny = int(self.RmInputs['NY'])
decomp_2d = not ((is_cs and npes_nx == 1) or (not is_cs and npes_ny == 1))
if is_cs:
require(npes_ny % 6 == 0, 'NY (%d) must be a multiple of 6 for cube-sphere grid' % npes_ny)

tmp_ = tempfile.NamedTemporaryFile(delete=False)
tmp_.close()
try:
print ("Optimizing... decomposition of processes.... \n")
print ("IMS.rc or JMS.rc would be generated on " + self.rundir)
run_cmd(self.bindir + '/preprocess_ldas.x optimize '+ self.inpdir+'/tile.data '
+ str(self.RmInputs['ntasks_model']) + ' ' + tmp_.name + ' ' + self.rundir + ' '
+ '_'.join(self.tile_types))
print ("IMS.rc and/or JMS.rc would be generated on " + self.rundir)
if decomp_2d:
run_cmd(self.bindir + '/preprocess_ldas.x optimize_2d '+ self.inpdir+'/tile.data '
+ str(npes_nx) + ' ' + str(npes_ny) + ' ' + tmp_.name + ' ' + self.rundir + ' '
+ '_'.join(self.tile_types))
else:
run_cmd(self.bindir + '/preprocess_ldas.x optimize '+ self.inpdir+'/tile.data '
+ str(self.RmInputs['ntasks_model']) + ' ' + tmp_.name + ' ' + self.rundir + ' '
+ '_'.join(self.tile_types))
optinxny = parseInputFile(tmp_.name)
finally:
os.remove(tmp_.name)
if (int(optinxny['NX']) == 1):
if int(optinxny['NY']) != int(self.RmInputs['ntasks_model']):
self.RmInputs['ntasks_model']=optinxny['NY']
print ('adjust ntasks_model %d for cubed-sphere grid' % int(self.RmInputs['ntasks_model']))
require('NX' in optinxny and 'NY' in optinxny, 'Optimization of domain decomposition failed')
ntasks_opt = int(optinxny['NX'])*int(optinxny['NY'])
if ntasks_opt != int(self.RmInputs['ntasks_model']):
self.RmInputs['ntasks_model'] = ntasks_opt
print ('adjust ntasks_model %d for cubed-sphere grid' % int(self.RmInputs['ntasks_model']))
return optinxny

# -----------------------------------------------------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion GEOSldas_App/ldas_setup
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ def parseCmdLine():

def main():

resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
# raise the stack limit to the hard limit (unlimited at NCCS, NAS); macOS rejects
# changes of the stack limit from within python, in which case keep the default
_, stack_hard = resource.getrlimit(resource.RLIMIT_STACK)
try:
resource.setrlimit(resource.RLIMIT_STACK, (stack_hard, stack_hard))
except (ValueError, OSError):
print('WARNING: cannot raise stack limit; using current limit', file=sys.stderr)
#convert command line to dictionary
args = vars(parseCmdLine())

Expand Down
Loading
Loading