Abort the code giving an error message
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | error_msg |
subroutine io_error(error_msg)
!========================================
!! Abort the code giving an error message
!========================================
implicit none
character(len=*), intent(in) :: error_msg
#ifdef MPI
character(len=50) :: filename
integer :: stderr, ierr, whoami, num_nodes
call mpi_comm_rank(mpi_comm_world, whoami, ierr)
call mpi_comm_size(mpi_comm_world, num_nodes, ierr)
if (num_nodes > 1) then
if (whoami > 99999) then
write (filename, '(a,a,I0,a)') trim(seedname), '.node_', whoami, '.werr'
else
write (filename, '(a,a,I5.5,a)') trim(seedname), '.node_', whoami, '.werr'
endif
stderr = io_file_unit()
open (unit=stderr, file=trim(filename), form='formatted', err=105)
write (stderr, '(1x,a)') trim(error_msg)
close (stderr)
end if
105 write (*, '(1x,a)') trim(error_msg)
106 write (*, '(1x,a,I0,a)') "Error on node ", &
whoami, ": examine the output/error files for details"
if (whoami == 0) then
write (stdout, *) 'Exiting.......'
write (stdout, '(1x,a)') trim(error_msg)
close (stdout)
end if
call MPI_abort(MPI_comm_world, 1, ierr)
#else
write (stdout, *) 'Exiting.......'
write (stdout, '(1x,a)') trim(error_msg)
close (stdout)
write (*, '(1x,a)') trim(error_msg)
write (*, '(A)') "Error: examine the output/error file for details"
#endif
#ifdef EXIT_FLAG
call exit(1)
#else
STOP
#endif
end subroutine io_error