- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
We also tried it from our end and it worked as expected.
Please refer to below screenshot for more details:
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:
Thanks & Regards,
Noorjahan.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
We also tried it from our end and it worked as expected.
Please refer to below screenshot for more details:
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:
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page