why change “complex*16” to “complex(16)” cause the runtime increased unreasonably in fortran?

此生再无相见时 提交于 2019-12-19 04:32:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32935743/why-change-complex16-to-complex16-cause-the-runtime-increased-unreasonabl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!