Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

fortran compiler differences

cvnravi
Beginner
416 Views
Hi,

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

ex:
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? Please explain me?

0 Kudos
1 Solution
TimP
Honored Contributor III
416 Views
If the results are different on a case as simple as this, the earlier compiler must have set an extension which treats constants as double precision, as well as using double precision evaluation of expressions. You could set /fpconstant /arch:IA32 in order to get closer to the numerical behavior of the older compiler. You still could not trust the results, if they depend on extensions beyond single precision. You might perform a check with /real-size:64 , rather than attempting to duplicate the old results.

View solution in original post

0 Kudos
3 Replies
Steven_L_Intel1
Employee
416 Views

The values you have are right at the borderline in terms of significant digits for single-precision. The Microsoft 4.0 compiler always used the X87 floating point instructions which would do single-precision arithmetic in double-precision. Intel Fortran 11.0 and later uses the faster SSE instructions which use the precision you declared. The two values you show are different in the last fraction bit, probably due to rounding.

In general, you can't rely on bit-for-bit identical results between two different implementations when optimizations and different instruction sets are used. Your program probably should be using double precision if it cares about results to that many digits.
0 Kudos
TimP
Honored Contributor III
417 Views
If the results are different on a case as simple as this, the earlier compiler must have set an extension which treats constants as double precision, as well as using double precision evaluation of expressions. You could set /fpconstant /arch:IA32 in order to get closer to the numerical behavior of the older compiler. You still could not trust the results, if they depend on extensions beyond single precision. You might perform a check with /real-size:64 , rather than attempting to duplicate the old results.
0 Kudos
Les_Neilson
Valued Contributor II
416 Views
Quoting - cvnravi

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? Please explain me?

If a difference of 0.000002 ( which is less than 0.0003 % ) makes a "huge difference" in the overall result then youshould really rethink the algorithm. Because floating point numbers are not generally representable exactly in binary, sensitivity to such small differences is not A Good Thing. Rounding error accumulation, optimization, etc may cause such differences in the last bit(s) of real numbers.

Les
0 Kudos
Reply