2

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?

user15964
  • 2,507
  • 2
  • 31
  • 57
  • 1
    Please create a minimal program that shows your issues and **include** that source code here. Aside from being the best thing to do, I can't even see your link. – Peter M Oct 04 '15 at 16:33
  • @PeterM the source file is just there. The only hyperlink in my question – user15964 Oct 04 '15 at 16:38
  • But the usual habit on SO is to include relevant parts of source code *inside* the question (without any hyperlink). BTW, did you try some other compiler (like `gfortran` from a *recent* [GCC](http://gcc.gnu.org/), e.g. [GCC 5](http://gcc.gnu.org/gcc-5/) with warnings and optimizations enabled ... `gfortran -O2 -Wall`....) – Basile Starynkevitch Oct 04 '15 at 16:39
  • @PeterM I am sorry, I really don't know how to give minimal program that can show my issue in this specific case. It is related to runtime. – user15964 Oct 04 '15 at 16:40
  • @BasileStarynkevitch yeah, I tried gfortran. It shows more error, even the compilation can't be finished. – user15964 Oct 04 '15 at 16:41
  • Then you should correct the errors... – Basile Starynkevitch Oct 04 '15 at 16:42
  • And here is the first problem. I can't even access your source code. I get "This webpage is not available" error. This is the reason whey source code should be included in the question. That, and things like "Will your source code still be there in 5 years time?". Because if it is not then your question becomes wasted space. – Peter M Oct 04 '15 at 16:44
  • @PeterM I can't find a useful file sharing website. So I use google drive, I can open it without problem. Can you recommand another working file host? I really want to know the answer, please. Thank you so much – user15964 Oct 04 '15 at 16:46
  • @PeterM what about this link "http://www.321webs.com/download/98398.htm", are you still there? Hello – user15964 Oct 04 '15 at 16:51
  • The only real solution is for you to figure out what the minimal program is that causes your issues and include that source code in your question. This is for 2 reasons: 1. So that the source code will always be available, and 2: No one on SO wants to work through 1000 lines of source code to try and understand what your program does and to separate the real issue from everything else. – Peter M Oct 04 '15 at 16:53
  • And no, I cannot see that link either. I am at work right now and that site is blocked. – Peter M Oct 04 '15 at 16:53
  • @PeterM Ok, Thank you all the same^ ^ – user15964 Oct 04 '15 at 16:55

1 Answers1

11

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.

Community
  • 1
  • 1
Ian Bush
  • 6,996
  • 1
  • 21
  • 27
  • Do you mean `complex*16` is not the same as `complex(16)`? – user15964 Oct 04 '15 at 17:03
  • OK, I just tried it. You are right. Complex*16 is equal to complex(8), it is written in intel fortran doc. I asked a silly question waste hours on it ! Thank you so much! I just knew it, someone can point out my mistake, but it suprised me that you even don't have to look at my source code. – user15964 Oct 04 '15 at 17:10
  • 2
    @user15964 you shouldn't be hardcoding numbers in as your type kinds e.g. `complex(8)` or `complex(16)`, as they can mean completely different things to different compilers -- they are *not* standardized. If you want to specify specific storage requirements in a portable way, see the named kind constants in the `iso_fortran_env` that are part of the Fortran 2008 standard. – casey Oct 04 '15 at 20:40
  • 2
    If you don't have iso_fortran_env available another was is via Selected_real_kind (and Selected_Int_kind) – Ian Bush Oct 05 '15 at 07:08