Search code examples
fortranintel-fortran

Different program result depending on how program is linked


I'm working on a large-ish numerical simulation program, mainly written in Fortran, that is compiled with Intel Fortran compiler (v18.0.3).

Recently, I have come across a mysterious issue: if I link the program with the external libraries as absolute paths, the numerical results are slightly different when compared to the program linked with -L/path/to/lib -lnameOfLib

I have checked the following:

  • runtime loading of shared libraries: I checked with strace and in both cases the same libraries are loaded and they are loaded in the same order;
  • unitialized variables: when compiled with -check all -ftrapuv there are no warnings or errors;
  • both binaries were run with valgrind and no memory issues were found, other than in external libraries;
  • the binaries are different when using diff on them.

I am out of options to check why this happens. I would be glad if someone could suggest further how to deal with this problem and where the differences could originate.


Solution

  • I'm going to conclude the following, based on this explanation. When linking with /usr/lib/libm.so, the platform libm.so will be used. When linking with -lm, the Intel compiler will alter the linking command to also link the Intel math library libimf.so. Apparently, these different implementations will give numerical roundoff error leading to the differences.