Getting double precision in fortran 90 using Intel compiler 11.1

I have a very large code that installs and iteratively solves a system of nonlinear partial differential equations written in fortran. I need all variables to be double precision. In the add-on module that I wrote for the code, I declare all the variables as a double precision type, but my module still uses the variables from the old source code declared as real. So my question is: what happens when a variable with one precision is multiplied by a double precision variable in fortran? Is the result double precision if the variable used to store the value is declared double precision? And what if the double precision value is multiplied by a constant without “D0” at the end? Can I set the compiler option in Intel 11.1,to do all real / double precision / double precision constants?

+3
source share
4 answers

So my question is: what happens when a variable with one precision is multiplied by a double precision variable in fortran? Single precision contributes to double precision, and the operation is performed with double precision.

Is the result double precision if the variable used to store the value is declared double precision? Not necessary. The right side is an expression that does not “know” about the accuracy of the variable on the left side in which it will be stored. If you have Double = SingleA * SingleB (using names to indicate types), the calculation will be performed with only precision, and then converted to double for storage. This will not give additional accuracy for the calculation!

, "D0" ? , , , . , - , , , . , DoubleVar * 3.14159265359 , - DoubleVar * 3.14159, .

, , . Fortran 90 , , , 14 :

integer, parameter :: DoubleReal_K = selected_real_kind (14)
real (DoubleReal_K) :: A
A = 5.0_DoubleReal_K
A = A * 3.14159265359_DoubleReal_K
+4

Fortran ; , , . , . ,

( ) + ( ) → (double)

( ) * ( ) → (double)

( ) * ( ) → (double)

.

, , . , .

, , , DBLE():

DBLE ( ) → double

+3

0.1D0, , , 0,1, . :

program main
implicit none
real(8) a,b,c
a=0.2D0
b=0.2
c=0.1*a
print *,a,b,c
end program

ifort main.f90

:

0.200000000000000       0.200000002980232       2.000000029802322E-002

ifort -r8 main.f90

:

0.200000000000000       0.200000000000000       2.000000000000000E-002

IBM XLF,

xlf -qautodbl=dbl4 main.f90
+2

Jonathan Dursi's answer is correct - the other part of your question would be if there was a way to make all real variables double precision.

You can accomplish this with the ifort compiler using the options -i8(for integers) and -r8(for real). I'm not sure if there is a way to get the compiler to interpret literals as double precision without specifying them as such (for example, changing 3.14159265359 to 3.14159265359D0). We again faced this problem.

+1
source

All Articles