Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7875 Discussions

Differences in division between ifort and icc

HenriqueRenno
Beginner
509 Views

I'm translating a Fortran code that implements a scientific model to the C language. There is a computation that involves the pow function in C, which in Fortran is computed using the ** operator.

 

I noticed that the problem is related to a constant that is computed differently between the ifort and icc compilers. However, the gcc compiler gives me the same result as ifort.

 

By analyzing the assembly instructions from the Fortran code (.s file), I saw that the constant was treated as a single-precision value. Therefore, I added the f in front of the constant numbers in the C code.

 

These are the results, where A is real*8 in Fortran and double in C. The values are formatted to include 12 decimal places.

 

* ifort

A = 24.639999389648

2.0/3.0 = 0.666666686535

A**(2.0/3.0) = 8.467603026548

* gcc

A = 24.639999389648

2.0f/3.0f = 0.666666686535

pow(A, 2.0f/3.0f) = 8.467603026548

* icc

A = 24.639999389648

2.0f/3.0f = 0.666666666667 (2.0/3.0 returns the same value)

pow(A, 2.0f/3.0f) = 8.467602487457

 

Is there a way that the icc and ifort compilers could return the same results, considering that the Fortran result is the reference? Why icc differs from ifort, but gcc doesn't?

 

Is there some specific flag that changes how floating-point arithmetic is performed? The only flag I used in all cases is -O2.

 

I know that the difference is small, but this pow value is used in another computation, which differs even more, and as the numerical method is iterated, the difference gets larger and larger.

 

There are many other parts of the code where results still differ, but this process of translating from Fortran to C takes time. I want to use only ifort and icc in the future, and I don't want to depend on gcc.

 

Thanks for your help

0 Kudos
1 Solution
NoorjahanSk_Intel
Moderator
408 Views

Hi,

 

Thanks for providing the details.

 

Could you please try with -fp-model=precise flag with icc compiler? As this flag tells the compiler to strictly adhere to value-safe optimizations for floating point operations.

Please refer to the below link for more details:

https://www.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/floating-point-options/fp-model-fp.html

 

We also tried it from our end and it worked as expected.

Please refer to below screenshot for more details:

NoorjahanSk_Intel_0-1669106356297.png

We also tried with icx compiler and it is working as expected without any additional flags. We recommend you migrate to icx as the classic compiler(icc/icl) is deprecated now and will be removed in Intel oneAPI 2023.

Please refer to below screenshot for more details:

NoorjahanSk_Intel_1-1669106373423.png

 

Thanks & Regards,

Noorjahan.

 

View solution in original post

0 Kudos
4 Replies
NoorjahanSk_Intel
Moderator
470 Views

Hi,


Thanks for reaching out to us.


Could you please provide us with the sample reproducer code along with the steps to reproduce the issue?


And also, please let us know the compiler versions being used.


Thanks & Regards,

Noorjahan.


0 Kudos
HenriqueRenno
Beginner
459 Views

Please, find attached the following files: powerF.f90, powerC.c

 

Compilation:

- ifort: ifort -o powerIFORT.x powerF.f90

- icc: icc -o powerICC.x powerC.c

- gcc: gcc -lm -o powerGCC.x powerC.c

 

Compilers (ifort and icc are stand-alone versions):

- ifort -v: ifort version 2021.6.0

- icc -v: icc version 2021.7.1 (gcc version 8.3.1 compatibility)

- gcc -v: gcc version 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC)

 

These codes simply compute the power mentioned in the previous message. Both ifort and gcc compilers report the same results, but icc doesn't.

 

Thanks

0 Kudos
NoorjahanSk_Intel
Moderator
409 Views

Hi,

 

Thanks for providing the details.

 

Could you please try with -fp-model=precise flag with icc compiler? As this flag tells the compiler to strictly adhere to value-safe optimizations for floating point operations.

Please refer to the below link for more details:

https://www.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/floating-point-options/fp-model-fp.html

 

We also tried it from our end and it worked as expected.

Please refer to below screenshot for more details:

NoorjahanSk_Intel_0-1669106356297.png

We also tried with icx compiler and it is working as expected without any additional flags. We recommend you migrate to icx as the classic compiler(icc/icl) is deprecated now and will be removed in Intel oneAPI 2023.

Please refer to below screenshot for more details:

NoorjahanSk_Intel_1-1669106373423.png

 

Thanks & Regards,

Noorjahan.

 

0 Kudos
NoorjahanSk_Intel
Moderator
383 Views

Hi,


Thanks for accepting our solution.

As this issue has been resolved, we will no longer respond to this thread. If you need any additional information, please post a new question


Thanks & Regards,

Noorjahan.


0 Kudos
Reply