Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Analog of #pragma float_control(precise,on), #pragma fp_contract ( { on | off } ), etc. in FPP

AlexLLE
Beginner
2,013 Views

Does FORTRAN preprocess offers floating point control similar to C/C++?

I need to prevent compiler from rearranging and optimizing a single formula in a source file.

 

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
1,928 Views

I'll note that those pragmas are specific to Microsoft Visual C/C++ and not the C/C++ language.  Standard Fortran does provide intrinsic modules IEEE_ARITHMETIC, IEEE_EXCEPTIONS and IEEE_FEATURES that provide some level of control. Only the fp_contract pragma is something Fortran doesn't offer.

Intel Fortran DOES have some directives (pragmas) that can control things on a more granular level, including turning FMA on and off, and disabling loop fusion. For a list, see General Compiler Directives (intel.com)

View solution in original post

7 Replies
Steve_Lionel
Honored Contributor III
1,982 Views

In Fortran, that level of control is not provided. You can specify /fp:strict (-fp-model strict) for that one source file.  Also, have a read through of Improving Numerical Reproducibility in C/C++/Fortran

0 Kudos
AlexLLE
Beginner
1,971 Views

Thanks, Steve, for the reply and the link!

It is unfortunate that C/C++ have it and FORTRAN doesn't.

Solutions involving special casing the make process just for one single file

is inelegant and harder to maintain. Disabling optimizations 

on the whole source file just for one single formula is not a right approach either.

Is there a plan to add the feature in future releases?

Can/should I submit a feature request?

Thanks.

0 Kudos
Ron_Green
Moderator
1,957 Views

There are a lot of directives and compiler options for FP control.

Specifically, for which #pragma do you want a Fortran equivalent?

0 Kudos
AlexLLE
Beginner
1,950 Views

#pragma float_control(except, {on|off})

#pragma float_control(precise, {on|off})

#pragma fenv_access({on|off})

#pragma fp_contract({on|off})

...

 

See:

https://learn.microsoft.com/en-us/cpp/preprocessor/float-control?view=msvc-170

 

Thanks.

0 Kudos
Steve_Lionel
Honored Contributor III
1,929 Views

I'll note that those pragmas are specific to Microsoft Visual C/C++ and not the C/C++ language.  Standard Fortran does provide intrinsic modules IEEE_ARITHMETIC, IEEE_EXCEPTIONS and IEEE_FEATURES that provide some level of control. Only the fp_contract pragma is something Fortran doesn't offer.

Intel Fortran DOES have some directives (pragmas) that can control things on a more granular level, including turning FMA on and off, and disabling loop fusion. For a list, see General Compiler Directives (intel.com)

AlexLLE
Beginner
1,920 Views

Thanks for the references.

Intel icc C++ compiler supports fp_control etc. pragma's too.

https://www.intel.com/content/dam/develop/external/us/en/documents/fp-control-2012-08.pdf

 

Here we used in our our GPU/CPU code before.

#if defined(__INTEL_COMPILER)
#pragma message("Using float_control pragma")
#pragma float_control(source,on,push)
#endif
__host__ __device__ __inline__
floatlle clfun(cell& c,int sm1,floatlle x,floatlle y){
return CLFUN(c,sm1,x,y);
}
__host__ __device__ __inline__
floatlle clfun_plus_1(cell& c,int sm1,floatlle x,floatlle y){
return CLFUN(c,sm1,x,y) + 1;
}
#if defined(__INTEL_COMPILER)
#pragma float_control(pop)
#endif

 

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,901 Views

Yes, because icc wants to be compatible with Microsoft C. My point was that these were implementation extensions, not part of the base language.

0 Kudos
Reply