castingfortranintel-fortran

Should casting from ``real`` to ``double precision`` in FORTRAN be affected by the compiler?


I have a FORTRAN code that I need to run on a server. I noticed that the results are a little different between the two machines. Looking into it, I learned that the difference rise from a function which return a real value to a double precision variable. On the locale machine I use old compiler (gnu f95 4.1.2) and on the remote machine I use ifort.


Solution

  • You should expect small difference between the same program compiled by different compilers. Finite precision arithmetic doesn't obey the rules that we expect for real numbers. So if the compilers change the order of operations, the results may differ slightly.

    That said, gfortran 4.1 is very old to point of being obsolete. I wouldn't use a version of gfortran earlier than 4.3. I strongly recommend upgrading.