Why do I get Fortran 'End of record' error on PC with Fedora, but not on Macbook? - fedora

I have a program which works well when using Macbook, but as soon as I try it on PC with Fedora 28, I get this error:
At line 107 of file transport.f08
Fortran runtime error: End of record
Error termination. Backtrace:
#0 0x7f2e56fe039a
#1 0x7f2e56fe0f09
#2 0x7f2e56fe1711
#3 0x7f2e571e6818
#4 0x7f2e571f2022
#5 0x7f2e571e97fa
#6 0x7f2e571e9c14
#7 0x403e5a
#8 0x405d0c
#9 0x405e65
#10 0x7f2e5643b1ba
#11 0x400bc9
#12 0xffffffffffffffff
Here is the block of code with problematic line 107:
subroutine outputs(i_out)
integer, intent(in) :: i_out
integer :: iunit, ierr
integer :: i
character(len=8) :: chout
write(chout,fmt='(I0.4)') i_out ! LINE 107
open(newunit=iunit,file="./outputs/Houtput"//trim(chout)//".dat",&
action="write", iostat=ierr)
if( ierr /= 0) then
print *, " > There was an error while opening output file ", i_out
print *, " > Exiting..."
stop
endif
do i=1,Nr
write(iunit,fmt='(20E14.6)') r_cell(i), velocity(i), pressure(i), density(i)
enddo
close(iunit)
end subroutine outputs

As francescalus pointed out in the comments, I had to drop i_out length to 8 or less digits. It solved the error.
I still don't know why it worked on Mac before, but having the error solved is enough for me :)
Thanks.

Related

Unable to call Device function in Cuda Fortran

I am trying to create a Linked list in Cuda Fortran, but when I am trying to call device functions from the kernel, I get a compilation error. Could someone please explain to me why …?
Sample code calling function InsertList is pasted below.
file :p5.f95
MODULE ListModule
IMPLICIT NONE
TYPE ListElem
REAL :: value;
TYPE(ListElem), POINTER :: next;
END TYPE ListElem
CONTAINS
ATTRIBUTES(DEVICE) FUNCTION InsertList(head, elem)
IMPLICIT NONE
type( ListElem ), pointer :: head, elem
type( ListElem ), pointer :: InsertList
elem%next => head
InsertList => elem
END FUNCTION InsertList
END MODULE
MODULE Test
CONTAINS
ATTRIBUTES(GLOBAL) SUBROUTINE KERNEL()
USE ListModule
IMPLICIT NONE
type( ListElem ), pointer :: head
type( ListElem ), pointer :: newElem, h
integer :: i,N = 4
INTEGER(KIND=4),ALLOCATABLE::ND(:)
nullify( head )
allocate( newElem )
newElem%value=1
PRINT*,newElem%value
head => InsertList(head, newElem)
END SUBROUTINE
END MODULE Test
PROGRAM LinkedList
USE TEST
USE CUDAFOR
integer :: N
CALL KERNEL<<<1,1>>>()
N=cudaDeviceSynchronize()
END PROGRAM LinkedList
compilation command:pgf95 -cuda -gpu=rdc p5.f95
Error:
nvvmCompileProgram error 9: NVVM_ERROR_COMPILATION.
Error: /tmp/pgcudaforNnQ1wgcS2LZ.gpu (27, 26): parse use of undefined value '%sym_insertlist_p_356'
ptxas /tmp/pgcudaforxnQf5cb9zEu.ptx, line 1; fatal : Missing .version directive at start of file '/tmp/pgcudaforxnQf5cb9zEu.ptx'
ptxas fatal : Ptx assembly aborted due to errors
NVFORTRAN-F-0155-Compiler failed to translate accelerator region (see -Minfo messages): Device compiler exited with error status code (p5.f95: 1)
NVFORTRAN/x86-64 Linux 21.7-0: compilation aborted

octave ode program produces an unexplained error

Have a file called f.m which has the following:
function xdot = f (x,t)
xdot = -exp(-t)*x^2;
endfunction
x=lsode("f",2,(t=linspace(0,5,50)'));
plot(t,x)
Running in octave 4.2.2 or 4.2.1 produces the following error:
error: 't' undefined near line 2 column 14
error: called from
f at line 2 column 6

pass function as argument to subroutine using interface doesn't work in Plato Fortran 90

I created a fortran 90 program that I used on a linux machine and compiled using gfortran. It worked fine on the linux machine with gfortran but provides the error
error 327 - In the INTERFACE to SECANTMETHOD (from MODULE SECMETH), the ninth dummy argument (F) was of type REAL(KIND=2) FUNCTION, whereas the actual argument is of type REAL(KIND=2)
when using the Plato compiler (FTN95). Does anyone know how I would need to change my code to work in Plato? I tried to read up on this error and there was some mention of pointers but from what I tried that did not work. I have figured out some workarounds but they make it so that the subroutine can no longer accept any function as an argument - which is pretty much useless. Any help would be greatly appreciated. My code is below.
!--! A module to define a real number precision.
module types
integer, parameter :: dp=selected_real_kind(15)
end module types
module secFuncs
contains
function colebrookWhite(T)
use types
real(dp) :: colebrookWhite
real(dp), intent(in) :: T
colebrookwhite=25-T**2
return
end function colebrookWhite
end module secFuncs
module secMeth
contains
subroutine secantMethod(xolder,xold,xnew,epsi1,epsi2,maxit,exitFlag,numit,f)
use types
use secFuncs
implicit none
interface
function f(T)
use types
real(dp) :: f
real(dp), intent(in) :: T
end function f
end interface
real(dp), intent(in) :: epsi1, epsi2
real(dp), intent(inout) :: xolder, xold
real(dp), intent(out) :: xnew
integer, intent(in) :: maxit
integer, intent(out) :: numit, exitFlag
real(dp) :: fxold, fxolder, fxnew
integer :: i
fxolder = f(xolder)
fxold = f(xold)
i = 0
do
i = i + 1
xnew = xold - fxold*(xold-xolder)/(fxold-fxolder)
fxnew = f(xnew)
if (i == maxit) then
exitFlag = 1
numit = i
return
else if (abs(fxnew) < epsi1) then
exitFlag = 2
numit = i
return
else if (abs(xnew - xold) < epsi2) then
exitFlag = 3
numit = i
return
end if
xolder = xold
xold = xnew
fxolder = fxold
fxold = fxnew
end do
end subroutine secantMethod
end module secMeth
program secantRoots
use types
use secMeth
use secFuncs
implicit none
real(dp) :: x1, x2, xfinal, epsi1, epsi2
integer :: ioerror, maxit, numit, exitFlag
do
write(*,'(A)',advance="no")"Please enter two initial root estimates, 2epsi's, and maxit: "
read(*,*,iostat=ioerror) x1, x2, epsi1, epsi2, maxit
if (ioerror /= 0) then
write(*,*)"Invalid input."
else
exit
end if
end do
call secantMethod(x1,x2,xfinal,epsi1,epsi2,maxit,exitFlag,numit,colebrookWhite)
if (exitFlag == 1) then
write(*,*)"The maximum number of iterations was reached."
else if (exitFlag == 2) then
write(*,'(a,f5.3,a,i3,a)')"The root is ", xfinal, ", which was reached in ", numit, " iterations."
else if (exitFlag == 3) then
write(*,'(a,i3,a)')"There is slow or no progress at ", numit, " iterations."
end if
end program secantRoots
Current gfortran detects the error in the call to the secantMethod procedure, where you have parentheses, but no argument list, following the colebrookWhite function name.
If you want to pass a function as an argument (as opposed to the result of evaluating a function), which is what you want to do here, you do not follow the function name with a parenthesis pair.
call secantMethod(x1,x2,xfinal,epsi1,epsi2,maxit,exitFlag,numit,colebrookWhite )
! ^
I ended up just switching from Plato to Geany IDE (I actually like Geany WAY better now that I've used it for a couple hours), setting up gfortran with Geany, and the code works with that setup. I'm guessing the reason I'm getting the error with Plato is that its compiler is actually a fortran95 compiler while gfortran is a fortran90 compiler. It took a while to get everything working but once I downloaded mingw-w64 for gfortran and set the path user (not system) environment variable to the correct location everything works great. I would still be interested in seeing if there is a way to get the code working with the FTN95 compiler, but in the end I'm still sticking with gfortran and Geany.

gdb bt frame disassemble

My Program terminated with signal 11, Segmentation fault.
Here is the backtrace:
(gdb) bt
#0 0x0e77af34 in show_stats(req_obj_s*, stats_s*, int*) () from /lib/libpd_ip.so.0.0
#1 0x0e78ad40 in bdPktMgrGetNext () from /lib/libpd_ip.so.0.0
#2 0x0e78b888 in bdPktMgr(void*) () from /lib/libpd_ip.so.0.0
#3 0x0e6f4f94 in pd_thread_creation () from /lib/libpd_api.so.0.0
#4 0x0fa893b0 in ?? () from /lib/librbn_pthread_np.so.0.0
#5 0x0d592210 in start_thread () from /lib/libpthread.so.0
#6 0x0d3d11d0 in clone () from /lib/libc.so.6
(gdb) frame 2
#2 0x0e78b888 in bdPktMgr(void*) () from /opt/ipos/lib/libpd_ip.so.0.0
(gdb)
(gdb) disassemble
Dump of assembler code for function _Z9bdPktMgrPv:
My question is that why the function is different in frame 2.
My question is that why the function is different in frame 2.
It's not. Read about name mangling here.

Fortran does not understand call statement

I am attempting to use PGFortran for CUDA. I installed PGFortran on my computer and linked everything up to the best of my knowledge. To get going I decided to follow a tutorial listed here. When trying to compile the code:
module mathOps
contains
attributes(global) subroutine saxpy(x, y, a)
implicit none
real :: x(:), y(:)
real, value :: a
integer :: i, n
n = size(x)
i = blockDim%x * (blockIdx%x - 1) + threadIdx%x
if (i <= n) y(i) = y(i) + a*x(i)
end subroutine saxpy
end module mathOps
program testSaxpy
use mathOps
use cudafor
implicit none
integer, parameter :: N = 40000
real :: x(N), y(N), a
real, device :: x_d(N), y_d(N)
type(dim3) :: grid, tBlock
tBlock = dim3(256,1,1)
grid = dim3(ceiling(real(N)/tBlock%x),1,1)
x = 1.0; y = 2.0; a = 2.0
x_d = x
y_d = y
call saxpy<<<grid, tblock="">>>(x_d, y_d, a)
y = y_d
write(*,*) 'Max error: ', maxval(abs(y-4.0))
end program testSaxpy
I got:
PGF90-S-0034-Syntax error at or near identifier saxpy (main.cuf: 29)
0 inform, 0 warnings, 1 severes, 0 fatal for testsaxpy
The error points to the line call saxpy<<<grid, tblock="">>>(x_d, y_d, a). For some reason it apparently hates the fact that I am using <<< and >>>? Going by the tutorial those triple chevrons are meant to be there:
The information between the triple chevrons is the execution
configuration, which dictates how many device threads execute the
kernel in parallel.
Removing these chevrons would not make any sense since they are the purpose of the program. So why does PGFortran dislike this?
As for the compilation. I have followed the tutorial by using
pgf90 -o saxpy main.cuf. But since that gave an error I also tried pgf90 -Mcuda -o saxpy main.cuf. Same results.
There does seem to be a text error in that blog at the kernel invocation line:
call saxpy<<<grid, tblock="">>>(x_d, y_d, a)
tblock="" is not correct. You'll notice elsewhere in that blog text, the kernel invocation line is given correctly as:
call saxpy<<<grid,tBlock>>>(x_d, y_d, a)
So if you change that line accordingly in your actual code, I think you'll have better results.