为什么要更改“ complex * 16”到“ complex(16)”;导致运行时间在fortran中不合理地增加了? [英] why change "complex*16" to "complex(16)" cause the runtime increased unreasonably in fortran?

查看:449
本文介绍了为什么要更改“ complex * 16”到“ complex(16)”;导致运行时间在fortran中不合理地增加了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此fortran代码最初以Fortran 77格式编写(我将在以后显示)。得到它之后,我通过转换工具将其更改为f90免费格式。使用 intel fortran编译器 ifort ,补偿和运行与以前一样好。



然后我想做更多,我想转换非标准的,过时的数据类型声明f77样式,例如: real * 8 complex * 16 等转换为f90标准的 real(8) complex(16)



但是我发现了一件令人难以置信的事情。 我将一个 complex * 16更改为 complex(16),然后运行时间从10秒增加到2分钟。




以下是详细信息



可以下载源文件 源代码下载链接1 生成代码下载链接2



首先,您可以使用ifort编译f90文件,而忽略所有警告

  ifort -w test-16.f90 

并运行

 。/a.out 

它将在大约10秒内完成(取决于您的计算机)。



现在,我们做出一点改变。转到734行,该行读取

 复合* 16 ch,clamda,czero,cspw,com,phase,ctemp 

它是f77过时的样式,因此请将其更改为f90标准

  Complex(16)ch,clamda,czero,cspw,com,phase,ctemp 

并以相同的方式编译,ifort将显示错误

  / tmp / ifortvaXMFi。 o:在函数'fite4_'中:
test-(16).f90 :(。text + 0x9ecf):未定义对'dimag_'
test-(16).f90 :(。text + 0xa354的引用):未定义对 dimag_的引用

我不知道为什么,但是我知道在744行中是一个非常可疑的句子

  aimag(ctemp)= dimag(ctemp)

我真的不明白这是什么意思。但是整个代码只有三个地方出现 ctemp。因此,显然,这条线是多余的。因此,我们可以安全地删除它。



因此,删除第744行之后,编译就可以了。但是,正如我之前所说,运行时间增加到2分钟以上。真是令人难以置信,这是怎么了?

解决方案

哦,亲爱的。种类值与变量占用的字节数不同。在大多数(但不是全部)编译器中,complex(16)具有四倍精度(在支持的情况下),这就是为什么您的运行时间会花很多时间的原因。请了解种类值,例如



Fortran 90种类参数



开始,然后了解对于复杂变量而言,种类值与构成它的实际值的种类相同



老实说,如果有人发布了一个相对较长的程序,然后告诉我在编译过程中忽略警告,然后进行排序,我就不多说了。解决他们的问题,好吧,我不愿意付出太大的努力。修正警告,将程序最多缩减到几十行,然后我和我怀疑大多数其他人会更加谨慎


This fortran code was originally written in Fortran 77 format(I will show it later). After I got it, I changed it into f90 free format via a converting tool. Using intel fortran compiler ifort, the compiation and running is just as fine as before.

Then I want to do more, I want to transform nonstandard,obsolete data type declaration f77 style like: real*8, complex*16 etc into f90 standard real(8), complex(16).

But I found an unbelievable thing. I just changed one "complex*16" into "complex(16)", then the running time increased from 10 seconds to 2 minutes. How could it be!!?? Can someone explain this abnormal behaviour in fortran?


Below is the details

The source file can be downloaded source code download link 1 or souce code download link 2

first, you could compile the f90 file using ifort, ignoring all the warning as

ifort -w test-16.f90

and run

./a.out

it will be finished in about 10 second (depends on your computer).

Now, we make a small change. Go to line 734, this line reads

  Complex *16 ch, clamda, czero, cspw, com, phase, ctemp

it is f77 obsolete style, so change it into f90 standard

  Complex(16) ch, clamda, czero, cspw, com, phase, ctemp

and compile in the same way, ifort will show an error

/tmp/ifortvaXMFi.o: In function `fite4_':
test-(16).f90:(.text+0x9ecf): undefined reference to `dimag_'
test-(16).f90:(.text+0xa354): undefined reference to `dimag_'

I don't know why, but I figure out that there is a very suspicious sentence in line 744

  aimag(ctemp) = dimag(ctemp)

I really don't understand what does mean. But the whole code only has three places that "ctemp" appear. So apparently, this line is rebundant. So we can safely delete it.

So after deleting line 744, the compilation is OK. But the running time as I said before increased to more than 2 minutes. It is really unbelievable, what is wrong here?

解决方案

Oh dear. A kind value is not the same number as the bytes that a variable occupies. In most (but not all) compilers complex(16) is quadruple precision (where supported), and that is why your run time goes through the roof. Please learn about kind values, see for instance

Fortran 90 kind parameter

to get started, and then understand that for complex variables the kind values are the same as the kinds of the real values that constitute it.

I'm not going to say more as, to be honest, if somebody posts a relatively long program and then tells me to ignore the warnings during compilation and then sort out their problem, well I don't feel that inclined to put much effort in. Fix the warnings, cut the program down to at most a few tens of lines, and then I, and I suspect most other people, will look more carefully.

这篇关于为什么要更改“ complex * 16”到“ complex(16)”;导致运行时间在fortran中不合理地增加了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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