mp_abort Subroutine

public subroutine mp_abort(msg, to_screen, err_unit_in)

Abort the simulation, logging an error message

Arguments

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

Error message

logical, intent(in), optional :: to_screen

If true, also print msg to screen, as well as to the error file

integer, intent(in), optional :: err_unit_in

Unit of open file to write any error messages to. Defaults to stderr


Contents

Source Code


Source Code

  subroutine mp_abort (msg, to_screen, err_unit_in)
    use, intrinsic :: iso_fortran_env, only : error_unit
    use optionals, only : get_option_with_default
    implicit none
    !> Error message
    character(len=*), intent (in) :: msg
    !> If true, also print [[msg]] to screen, as well as to the error file
    logical, intent(in), optional :: to_screen
    !> Unit of open file to write any error messages to. Defaults to stderr
    integer, intent (in), optional :: err_unit_in
    integer :: err_unit_local
# ifdef MPI
    integer :: ierror
    integer, parameter :: error_code = MPI_ERR_UNKNOWN
# endif
    if (proc0) then
       err_unit_local = get_option_with_default(err_unit_in, err_unit)
       if (get_option_with_default(to_screen, .false.)) write(*, *) "Error: ", msg
       write (err_unit_local, *) "Error: ", msg
       flush (err_unit_local)
    end if

# ifndef MPI
    error stop "Called mp_abort without MPI."
# else
    call mpi_abort(comm_all, error_code, ierror)
# endif
  end subroutine mp_abort