Skip to content

Commit 618a08e

Browse files
authored
Add pio_finalize calls for CICE history and restart files (#995)
* Add pio_finalize calls for CICE history and restart files when running with PIO. This cleans up some PIO internal data. The code was aborting when trying to write lots of files (>600) because we reinitialize PIO for each file. This is a short term fix. A longer term fix is to initialize PIO once and reuse as much as possible. Add a new test that runs CICE for a year writing hourly files (>8000 files). Test with pio2 and netcdf. * Add error checks and CESMCOUPLED cpp to new ice_pio_finalize method.
1 parent b3d5813 commit 618a08e

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,12 @@ subroutine ice_write_hist (ns)
12551255
write(nu_diag,*) 'Finished writing ',trim(ncfile)
12561256
endif
12571257

1258+
!-----------------------------------------------------------------
1259+
! clean up PIO
1260+
!-----------------------------------------------------------------
1261+
1262+
call ice_pio_finalize()
1263+
12581264
first_call = .false.
12591265

12601266
end subroutine ice_write_hist

cicecore/cicedyn/infrastructure/io/io_pio2/ice_pio.F90

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module ice_pio
2727

2828
public ice_pio_init
2929
public ice_pio_initdecomp
30+
public ice_pio_finalize
3031
public ice_pio_check
3132

3233
#ifdef CESMCOUPLED
@@ -529,6 +530,27 @@ subroutine ice_pio_initdecomp_4d (ndim3, ndim4, iodesc, precision)
529530
end subroutine ice_pio_initdecomp_4d
530531

531532

533+
!================================================================================
534+
535+
! PIO Finalize
536+
537+
subroutine ice_pio_finalize()
538+
539+
integer(kind=int_kind) :: status
540+
character(len=*), parameter :: subname = '(ice_pio_finalize)'
541+
542+
status = PIO_NOERR
543+
#ifndef CESMCOUPLED
544+
call pio_seterrorhandling(ice_pio_subsystem, PIO_RETURN_ERROR)
545+
call pio_finalize(ice_pio_subsystem,status)
546+
call ice_pio_check( status, subname//' ERROR: Failed to finalize ', &
547+
file=__FILE__,line=__LINE__)
548+
! do not call this, ice_pio_subsystem does not exist anymore
549+
! call pio_seterrorhandling(ice_pio_subsystem, PIO_INTERNAL_ERROR)
550+
#endif
551+
552+
end subroutine ice_pio_finalize
553+
532554
!================================================================================
533555

534556
! PIO Error handling

cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ subroutine final_restart()
905905
call PIO_freeDecomp(File,iodesc2d)
906906
call PIO_freeDecomp(File,iodesc3d_ncat)
907907
call pio_closefile(File)
908+
call ice_pio_finalize()
908909

909910
if (my_task == master_task) then
910911
write(nu_diag,'(a,i8,4x,i4.4,a,i2.2,a,i2.2,a,i5.5)') &
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
histfreq = 'm','h','x','x','x'
2+
histfreq_n = 1,1,1,1,1
3+
histfreq_base = 'zero','zero','zero','zero','zero'
4+
write_ic = .true.
5+
f_aice = 'mh'
6+
f_hi = 'hm'
7+
f_hs = 'mh'
8+
f_Tsfc = 'mh'

configuration/scripts/tests/io_suite.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Test Grid PEs Sets BFB-compare
2+
smoke gx3 32x1 run1year,histhrly,ionetcdf,iocdf2,short
3+
smoke gx3 32x1 run1year,histhrly,iopio2,iocdf5,short
4+
25
# some iobinary configurations fail due to bathymetry netcdf file requirement, remove them
36
# iobinary cannot work with JRA55 because netcdf is turned off
47
restart gx3 8x4 gx3ncarbulk,debug,histall,iobinary,precision8

0 commit comments

Comments
 (0)