Skip to content

Commit

Permalink
io_netcdf: do check exit status of nf90_close in final_restart
Browse files Browse the repository at this point in the history
In ice_restart::final_restart, we call nf90_close outside any condition
on 'my_task'. This is very fishy, as the restart file is only opened by
the first MPI rank in init_restart_write. The reason it works is (most
likely) because we do not check the exit status of nf90_close, which
(most likely) fails on all ranks other than the first.

What's more, we always output "Restart read/written" to the log file,
even if the call to nf90_close failed. This means the log file will
always say the restart was written, even if it might not have been
because of an error, which can be very confusing (see [1] and
following).

Move the call to nf90_close inside the existing condition on 'my_task',
and also check the exit status, converting any error code to its textual
representation using 'nf90_strerror'.

[1] https://gitlab.science.gc.ca/Ocean_Data_Assimilation/RIOPS/issues/101#note_790575
  • Loading branch information
phil-blain committed May 31, 2023
1 parent d868ff1 commit 9bee171
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cicecore/cicedynB/infrastructure/io/io_netcdf/ice_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,14 @@ subroutine final_restart()
character(len=*), parameter :: subname = '(final_restart)'

#ifdef USE_NETCDF
status = nf90_close(ncid)

if (my_task == master_task) &
if (my_task == master_task) then
status = nf90_close(ncid)
if (status /= nf90_noerr) call abort_ice(subname// &
'ERROR: closing restart ncfile: ' // trim(nf90_strerror(status)))

write(nu_diag,*) 'Restart read/written ',istep1,idate
endif

#else
call abort_ice(subname//'ERROR: USE_NETCDF cpp not defined', &
Expand Down

0 comments on commit 9bee171

Please sign in to comment.