fortran compiler differences

fortran compiler differences

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?

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.

Steve
Best Reply

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.

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

Login to leave a comment.