Skip to content

Commit

Permalink
Ensure PIO calls are not optimized out
Browse files Browse the repository at this point in the history
At least on some machines (mappy + gcc 9.2.0) if the return value
(ierr) from the PIO calls is ignored the PIO calls are optimized
out (values/attributes not written out to the file etc).

So adding a call to handle/touch the return value from the PIO
calls to ensure that values/attributes are updated in the output
file

Thanks [email protected] for the fix.
  • Loading branch information
jayeshkrishna committed Apr 11, 2024
1 parent fa6c6e8 commit 6b407d0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions components/eamxx/src/share/io/scream_scorpio_interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,11 @@ subroutine register_variable(filename,shortname,longname,units, &

if (is_write(pio_atm_file%purpose)) then
ierr = PIO_def_var(pio_atm_file%pioFileDesc, trim(shortname), hist_var%nc_dtype, hist_var%dimid(:numdims), hist_var%piovar)
call errorHandle("PIO ERROR: could not define variable "//trim(shortname),ierr)
call errorHandle("PIO ERROR: could not define variable "//trim(shortname)//" in file "//trim(filename),ierr)
ierr=PIO_put_att(pio_atm_file%pioFileDesc, hist_var%piovar, 'units', hist_var%units )
call errorHandle("PIO ERROR: could not set attribute 'units' for variable "//trim(shortname)//" in file "//trim(filename),ierr)
ierr=PIO_put_att(pio_atm_file%pioFileDesc, hist_var%piovar, 'long_name', hist_var%long_name )
call errorHandle("PIO ERROR: could not set attribute 'long_name' for variable "//trim(shortname)//" in file "//trim(filename),ierr)
else
ierr = PIO_inq_varid(pio_atm_file%pioFileDesc,trim(shortname),hist_var%piovar)
call errorHandle("PIO ERROR: could not retrieve id for variable "//trim(shortname)//" from file "//trim(filename),ierr)
Expand Down Expand Up @@ -778,7 +780,10 @@ subroutine eam_update_time(filename,time)
pio_atm_file%numRecs = pio_atm_file%numRecs + 1
call get_var(pio_atm_file,'time',var)
! Only update time on the file if a valid time is provided
if (time>=0) ierr = pio_put_var(pio_atm_file%pioFileDesc,var%piovar,(/ pio_atm_file%numRecs /), (/ 1 /), (/ time /))
if (time>=0) then
ierr = pio_put_var(pio_atm_file%pioFileDesc,var%piovar,(/ pio_atm_file%numRecs /), (/ 1 /), (/ time /))
call errorHandle("PIO ERROR: something went wrong while writing time var on file="//trim(filename),ierr)
endif
end subroutine eam_update_time
!=====================================================================!
! Assign institutions to header metadata for a specific pio output file.
Expand Down Expand Up @@ -1150,6 +1155,7 @@ subroutine eam_pio_finalize()

#if !defined(SCREAM_CIME_BUILD)
call PIO_finalize(pio_subsystem, ierr)
call errorHandle("PIO ERROR: something went wrong when calling PIO_finalize.",ierr)
nullify(pio_subsystem)
#endif

Expand Down Expand Up @@ -1491,6 +1497,7 @@ function read_time_at_index(filename,time_index) result(val)
ierr = pio_inq_dimid(pio_atm_file%pioFileDesc,trim("time"),dim_id)
call errorHandle("read_time_at_index ERROR: dimension 'time' not found in file "//trim(filename)//".",ierr)
ierr = pio_inq_dimlen(pio_atm_file%pioFileDesc,dim_id,time_len)
call errorHandle("PIO Error! Something went wrong when inquiring time dim length on file file "//trim(filename)//".",ierr)

if (present(time_index)) then
timeidx = time_index
Expand Down

0 comments on commit 6b407d0

Please sign in to comment.