https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83436
--- Comment #5 from Daan van Vugt <daanvanvugt at gmail dot com> ---
Okay, turned out I missed the critical lines in my bug report...
Could you try again with this example?
module mod_random_seed
implicit none
contains
!> Read an int from /dev/urandom
subroutine read_urandom_int(seed, ierr)
implicit none
integer, intent(out) :: seed
integer, intent(out) :: ierr
integer :: un
character(len=80) :: restart_file
write(restart_file,'(A,A)') 'jorek', '_restart.h5'
open(newunit=un, file="/dev/urandom", access="stream", &
form="unformatted", action="read", status="old", iostat=ierr)
if (ierr == 0) then
read(un) seed
close(un)
end if
end subroutine read_urandom_int
end module mod_random_seed
program test_random_seed
use mod_random_seed
integer :: seed, ierr
call read_urandom_int(seed, ierr)
write(*,*) seed, ierr
end program test_random_seed
I have compiled it as:
mpif90 -march=native -cpp -fopenmp -Wall -Wextra -Wno-unused-variable -g -Og
-ggdb -Wunused-variable -Wintrinsics-std -Wcharacter-truncation -Wsurprising
-Wno-tabs -ffree-line-length-none -fcheck=all -ffpe-trap=invalid,zero,overflow
-ftrapv -finit-real=snan -finit-integer=12345678 -Wimplicit-interface
-Wimplicit-procedure -Wconversion -fimplicit-none read_urandom.f90 -o
read_urandom
This produces for me:
At line 16 of file read_urandom.f90
Fortran runtime error: Internal file cannot be accessed by UNFORMATTED data
transfer
Error termination. Backtrace:
#0 0x14fc70240043 in data_transfer_init
at /build/gcc/src/gcc/libgfortran/io/transfer.c:2822
#1 0x55c83ae10e31 in __mod_random_seed_MOD_read_urandom_int
at
/media/data/Projects/gfortran/bugs/internal_file_urandom/read_urandom.f90:16
#2 0x55c83ae10ebd in test_random_seed
at
/media/data/Projects/gfortran/bugs/internal_file_urandom/read_urandom.f90:25
#3 0x55c83ae10f63 in main
at
/media/data/Projects/gfortran/bugs/internal_file_urandom/read_urandom.f90:23