hidden_stop_all Subroutine

subroutine hidden_stop_all(sub_name, error_msg)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: sub_name
character(len=*), intent(in) :: error_msg

Contents

Source Code


Source Code

subroutine hidden_stop_all(sub_name, error_msg)
    ! Do not call this directly
    use constants, only: stdout, stderr
    use error_handling_neci, only: neci_flush, neci_backtrace
    use Parallel_neci, only: iProcIndex, MPIStopAll

    ! Stop calculation due to an error. Exit with code 222?
    !
    ! In: sub_name    - Calling routine
    !     error_msg   - Error message
    character(*), intent(in) :: sub_name, error_msg

    ! I found problems when the error code is larger 2^8 - 1 == 255
    integer, parameter :: error_code = 222

    call neci_flush(stdout)
    write(stdout,'(/a7)') 'ERROR.'
    write(stdout,'(a27,a)') 'NECI stops in subroutine: ',adjustl(sub_name)
    write(stdout,'(a9,18X,a)') 'Reason: ',adjustl(error_msg)
#ifdef USE_MPI
    write(stdout,'(a12,15X,i5)') 'Processor: ', iProcIndex
#endif
    write(stdout,'(a11)') 'EXITING...'

    ! Also push this to the stderr unit, so it hopefully ends up somewhere
    ! more useful.
    call neci_flush(stderr)
    write(stderr,'(/a7)') 'ERROR.'
    write(stderr,'(a27,a)') 'NECI stops in subroutine: ',adjustl(sub_name)
    write(stderr,'(a9,18X,a)') 'Reason: ',adjustl(error_msg)
#ifdef USE_MPI
    write(stderr,'(a12,15X,i5)') 'Processor: ', iProcIndex
#endif
    write(stderr,'(a11)') 'EXITING...'

    call neci_backtrace()

#ifdef USE_MPI
    call MPIStopAll(error_code)
#else
    stop error_code
#endif

end subroutine hidden_stop_all