函数调用在包含写入语句时停止/挂起,但仅在编译期间与某些库链接时停止/挂起 [英] Function call stopping/hanging when containing a write-statement, but only when linking with certain libraries during compilation

查看:119
本文介绍了函数调用在包含写入语句时停止/挂起,但仅在编译期间与某些库链接时停止/挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我最小的例子:

 程序测试
隐式无
真:: testfunc $
write(*,*)testfunc()
结束程序测试

函数testfunc()result(y)
real :: y
write(*,*)从函数g写入
y = 1.0
返回
结束函数testfunc



使用简单的

  gfortran test.f90 

或者包含像Slatec这样的库

  gfortran test.f90 -lslatec 

它工作正常。



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



现在奇怪的是,如果我在testfunc()中注释掉write语句,所以我的问题是:这些库能否真的阻止我在自己的函数中打印?为什么?怎么样?



(我实际上正在研究一个需要lapack和blas的大型程序,所以我显然不能停止链接到它们。)

解决方案

至于我记得,它不符合递归调用WRITE关键字的标准。



为了纠正你的程序,稍微修改你的主程序

 程序测试
隐式无
真正的:: testfunc,结果
写(*,*)从主写入
结果= testfunc()
写(*,*)结果
结束程序测试

从我的观点来看,您遇到的麻烦与使用的库无关,而是在这种情况下,错误可能会发生变化(从显然没有错误到崩溃)。


Here is my minimal example:

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

When compiling with a simple

gfortran test.f90

or when including a library like Slatec

gfortran test.f90 -lslatec

It works fine.

However, when changing the library to -llapack of -lblas, then the program hangs at runtime when calling testfunc(). Note that my example code here does not actually use any of these libraries. The last thing i see is "Writing from main", then nothing happens, and i have to CTRL-C to regain control. When hanging, the process does not appear to be using any CPU cycles.

The strange thing now is that, if i comment out the write statement inside testfunc(), it works all the time.

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.)

解决方案

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).

这篇关于函数调用在包含写入语句时停止/挂起,但仅在编译期间与某些库链接时停止/挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆