vendredi 19 février 2016

ranlib.f gfortran broken ignpoi

I am using gfortran: GNU Fortran (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4 on linux.

I am trying to use ignpoi from ranlib.f in this source http://ift.tt/1WwBeCX (http://ift.tt/1oQ9rTw)

I compile the library using

   gfortran -O2 -c *.f
   ar cr libranlib.a *.o

When I write simple program to test ignpoi (Poisson deviate generator)

  program test
  implicit none
  integer seed1, seed2, i
  real av
  integer ignpoi

  seed1=123456
  seed2=654321
  call setall(seed1,seed2)

  av=8.0
  do i=1,10
     print *, ignpoi(av)
  enddo

  end

with the same average it gives segmentation fault after one or many deviates.

          12
           7

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7F077F1D3E48
#1  0x7F077F1D2FD0
#2  0x7F077E9042EF
#3  0x401288 in ignpoi_
#4  0x400A3D in MAIN__ at test.f:?
Segmentation fault (core dumped)

This is how I compile the test with no compilation error.

gfortran test.f libranlib.a

Oddly enough, when I ask for different number every time, there is no problem. When I comment lines 104-105

IF (mu.EQ.muprev) GO TO 10     
IF (mu.LT.10.0) GO TO 120

of ignpoi.f, the problem is gone.

Can this be replicated?

What cause the errors?

I get that line 104-105 are to save calculation time. How can I modify the current function to benefit from the pre-calculation without that problem of calling the function with the same average multiple time?




Aucun commentaire:

Enregistrer un commentaire