- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are a lot of directives and compiler options for FP control.
Specifically, for which #pragma do you want a Fortran equivalent?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, because icc wants to be compatible with Microsoft C. My point was that these were implementation extensions, not part of the base language.

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