5

这是我的最小示例:

program test    
  implicit none
  real :: testfunc
  write(*,*) "Writing from main"
  write(*,*) testfunc()
end program test

function testfunc() result(y)
  real             :: y
  write(*,*) "Write from function g"
  y=1.0
  return
end function testfunc

使用简单的编译时

gfortran test.f90

或者当包括像 Slatec 这样的库时

gfortran test.f90 -lslatec

它工作正常。

但是,当将库更改为 -lblas 的 -llapack 时,程序在调用 testfunc() 时会在运行时挂起。请注意,我在此处的示例代码实际上并未使用任何这些库。我看到的最后一件事是“从 main 写入”,然后什么也没有发生,我必须按 CTRL-C 才能重新获得控制权。挂起时,该进程似乎没有使用任何 CPU 周期。

现在奇怪的是,如果我注释掉 testfunc() 中的 write 语句,它会一直工作。

So my question is really: Can these libraries really prevent me from printing inside my own functions? Why? How?

(I'm actually working on a larger program which needs lapack and blas, so i obviously can't just stop linking to them.)

4

1 回答 1

9

As far as I remember, it is not standard conforming to call recursively the WRITE keyword.

To correct you program, modify slightly your main program

program test    
  implicit none
  real :: testfunc,result
  write(*,*) "Writing from main"
  result=testfunc()
  write(*,*) result
end program test

From my point of new, the trouble you met has therefore nothing to do with the used libraries but the symptoms of the mistake may change in that case (from apparently no bug to a crash).

于 2011-10-05T14:05:44.667 回答