Skip to content

Commit

Permalink
Deallocate error in prterr subroutine.
Browse files Browse the repository at this point in the history
Previously error was intent(in), error remained allocated after prterr
returns and may trigger 'untrapped error' if W90DEV defined (see
io.F90).

Deallocating the error without triggering the 'untrapped error' case
is done by setting the error code to a special value (neutralising the
error).

prterr() now has error variable to intent(inout) and is deallocated.
  • Loading branch information
Jerome Jackson committed Jan 15, 2025
1 parent 9ab9860 commit fcffe4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/error_base.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ module w90_error_base
end type w90_error_type

integer, parameter :: code_remote = -99 ! special code for error triggered by other mpi rank
integer, parameter :: code_deactivated = -888 ! special code for error triggered by other mpi rank

contains

subroutine untrapped_error(err)
type(w90_error_type), intent(in) :: err
! this routine should never be called, so write to stderr and call "stop" in desparation
if (err%code == code_deactivated) return
write (0, *) "UNTRAPPED ERROR: ", err%code
write (0, *) "UNTRAPPED ERROR: ", err%message
stop
Expand Down
7 changes: 5 additions & 2 deletions src/io.F90
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,13 @@ end function io_wallclocktime

subroutine prterr(error, ie, istdout, istderr, comm)
use w90_comms, only: comms_no_sync_send, comms_no_sync_recv, w90_comm_type, mpirank, mpisize
use w90_error_base, only: code_remote, w90_error_type
use w90_error_base, only: code_deactivated, code_remote, w90_error_type

! arguments
integer, intent(inout) :: ie ! global error value to be returned
integer, intent(in) :: istderr, istdout
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(in) :: error
type(w90_error_type), allocatable, intent(inout) :: error

! local variables
type(w90_error_type), allocatable :: le ! unchecked error state for calls made in this routine
Expand Down Expand Up @@ -449,6 +449,9 @@ subroutine prterr(error, ie, istdout, istderr, comm)
endif
call flush(istdout)
call flush(istderr)

error%code = code_deactivated
deallocate (error) ! else allocated error trips uncaught error mechanism (ifdef W90DEV, see io.F90)
end subroutine prterr

end module w90_io

0 comments on commit fcffe4b

Please sign in to comment.