Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28385 Discussions

forrtl: severe (174): SIGSEGV, segmentation fault occurred

bchang001
Beginner
479 Views
Hi all,
My customer has rnd_generator.f90 calling ran3.f and it sigsegv on the assignment statement idum=1 in the ran3.f.
The program runs if I comment out the idum in the ran3.f.



ifort rnd_generators_test.f90 ran3.f
./a.out
[qttg@frontend test]$ ./a.out
test_ran3->after open
test_ran3->random_loop
idum is -15 i is 1
ran3->after if
ran3->inext=0
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 0000000000402C7F Unknown Unknown Unknown
a.out 0000000000402956 Unknown Unknown Unknown
a.out 00000000004026EA Unknown Unknown Unknown
libc.so.6 0000003E63A1C4BB Unknown Unknown Unknown
a.out 000000000040262A Unknown Unknown Unknown
[qttg@frontend test]$ cat rnd_generators_test.f90
program test_ran3

! This program shows how to properly call ran3.f
! To compile the program together with ran3.f (which is
! a FORTRAN 77 function) put ran3.f in the same directory
! and use: ifort rnd_generators_test.f90 ran3.f -O3

implicit none

integer, parameter :: double=8

! Here idum is integer variable whose value defines (reproducible) sequence of
! "pseudorandom" numbers
integer, parameter :: idum=-15

integer :: i, no_random=100000

real (kind=double) :: ran3
real (kind=double) :: r1,r2,r3,r4,r5

open(unit=12,file="ran3_square_test.dat",status="unknown",form="formatted")
open(unit=14,file="random_square_test.dat",status="unknown",form="formatted")

print *,'test_ran3->after open'

random_loop: do i=1,no_random
print *,'test_ran3->random_loop'
print *,'idum is ',idum, 'i is ', i

r1=ran3(idum); r2=ran3(idum)

! r3=(r2-0.5)*0.6
! print *,r3

call random_number(r4); call random_number(r5)
print *,'test_ran3->random_number'

write(12,*) r1,r2

write(14,*) r4,r5

end do random_loop

end program test_ran3
[qttg@frontend test]$ cat ran3.f
FUNCTION ran3(idum)
INTEGER idum
INTEGER MBIG,MSEED,MZ
C REAL MBIG,MSEED,MZ
REAL ran3,FAC
PARAMETER (MBIG=1000000000,MSEED=161803398,MZ=0,FAC=1./MBIG)
C PARAMETER (MBIG=4000000.,MSEED=1618033.,MZ=0.,FAC=1./MBIG)
INTEGER i,iff,ii,inext,inextp,k
INTEGER mj,mk,ma(55)
C REAL mj,mk,ma(55)
SAVE iff,inext,inextp,ma
DATA iff /0/
if(idum.lt.0.or.iff.eq.0)then
iff=1
mj=MSEED-iabs(idum)
mj=mod(mj,MBIG)
ma(55)=mj
mk=1
print *,'ran3->after if'
do 11 i=1,54
C print *,'ran3->do 11 i=1,54 i=', i
ii=mod(21*i,55)
ma(ii)=mk
mk=mj-mk
if(mk.lt.MZ)mk=mk+MBIG
mj=ma(ii)
11 continue
do 13 k=1,4
C print *,'ran3->do 13 k=1,4 begin k=',k
do 12 i=1,55
C print *,'ran3->do 12 i=1,55 begin i=',i
ma(i)=ma(i)-ma(1+mod(i+30,55))
if(ma(i).lt.MZ)ma(i)=ma(i)+MBIG
12 continue

C print *,'ran3->do 12 i=1,55 end'
13 continue
C print *,'ran3->do 13 k=1,4 end k=',k
inext=0
inextp=31
print *,'ran3->inext=0'
idum=1
print *,'ran3->idum=',idum
endif
inext=inext+1
if(inext.eq.56)inext=1
inextp=inextp+1
if(inextp.eq.56)inextp=1
mj=ma(inext)-ma(inextp)
if(mj.lt.MZ)mj=mj+MBIG
ma(inext)=mj
ran3=mj*FAC
return
END
C (C) Copr. 1986-92 Numerical Recipes Software ,o>29'?0>!+W.
0 Kudos
1 Reply
Lorri_M_Intel
Employee
479 Views
You're trying to write into a literal.
In the calling program, "idum" is declared to be an INTEGER PARAMETER, which means it has been put into read-only memory.
In the called program, you try to change the value of the argument passed (also named "idum") but you get an access violation because now you're trying to write into read-only memory.
- Lorri
0 Kudos
Reply