log function compatibility


I’m working with a scientific model that implements a numerical method, and I’m currently using the Intel compiler, but now I want to use CUDA Fortran that is available in the PGI compiler.

Some of the model results running on CPU (first tests without using CUDA) didn’t match between the compilers, and after debugging I saw that the problem is the log function that does not return the same value for a particular computation. As the numerical method depends on a convergence condition after many calculations, the errors from the log function are accumulated at each step, thus producing the differences in the final results. I need to use the Intel results as the reference.

Below is a simple program that illustrates one of the computations the method uses, and that differ in results. For val1 results are different, but for val2 don’t. Why val1 produces different results?

System: Intel Core i7 7820x, Linux CentOS 7.5.1804
Compilers: Intel Fortran (ifort), PGI Fortran 19.10-0 (pgf90)
Compilation: Intel -> ifort -o log.ifort log.f90; PGI -> pgf90 -o log.pgf90 log.f90

val1: 0.0553500428796
val2: 5.0572290420532
val1: 0.0553499311209
val2: 5.0572290420532

program calclog
    real :: val1, val2

    val1 = 12.5
    val2 = 0.5
    write(*,'(A,F16.13)') 'val1: ', log((10.-val1*0.67)/(val1*0.123))
    write(*,'(A,F16.13)') 'val2: ', log((10.-val2*0.67)/(val2*0.123))

end program calclog

Is it possible for PGI to match Intel results? I’d appreciate any help.


Hi Henrique,

I think the compiler by default will try to apply some processor-specific optimization here, which is causing the results to diverge slightly. You can get the same results as ifort with -tp=px to instruct that the generated code is compatible across any x86 processor.

Thanks for your reply. Now the results of the log functions are matching. However, I found a similar problem in another part of the code where the power operator is used. I posted another message with the details.