tags:

views:

97

answers:

3

Hi,

I am porting an application from fortran older version (4.0) to new version (11.0). While porting I am facing some problems with real*4 variables:

real*4 a,b,c

a=0.9876875
b=0.6754345

c=a*b

value for c in old compiler 0.667118, which is correct value. But with new compiler I am getting a small variation from the output(c variable) like 0.667120. Though it is a small variation, I am using these values in some other calculation. So the overall output has a huge difference. How to overcome this issue?

A: 

I assume you are using Intel. Try to compile without optimization..

WorldCitizeN
+2  A: 

You are, I'm assuming, going from Microsoft Fortran Powerstation 4 to Intel Visual Fortran 11.xx ?

Anyways, try this:

program test32

integer, parameter :: iwp = selected_real_kind(15,300)

real(iwp) :: a,b,c

a=0.9876875
b=0.6754345

c=a*b
write(*,'(3f12.8)')a,b,c

end program test32

which gives out:

0.98768753  0.67543453  0.66711826

I will not explain selected_real_kind, not because I do not wish, but because the help will probably do it much better. But, do ask if something in here is not clear.

p.s. The representation of real*4, or any type of real is processor dependent, and compiler dependent and that is one of the reasons why you're getting different results.

ldigas
+2  A: 

Discussion of changes in Intel visual Fortran compiler version 11 here:

http://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/68587/

The upshot is that older versions of the Fortran compiler would implicitly promote single-precision values to double-precision before performing an operation. The default behavior in version 11 is to perform the operation with single-precision. There are compiler options (/arch:ia32) to enable the old behavior in the new compiler.

mobrule