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.
29282 Discussions

Any way to globally change DOUBLE constants to SINGLE?

art-croucher
Beginner
986 Views
I have a program that does all its calculations in double precision. The model is decades old and nobody is sure that the double precision is really necessary. Due to performance issues (cache thrashing) I want to run the model at single precision and see if there are any problems.
It is easy enough to redo the variable declarations, but I don't know a way to change the type of the in-code constants (2.0D0, etc). Intel says the compiler flags and KIND can only increase the precision of floating point types, not decrease it.
Is there any alternative to going through the code manually to change the typing of the constants?
Thanks,
Art
0 Kudos
6 Replies
TimP
Honored Contributor III
986 Views
It may be worth while to test with single precision arrays and double precision constants. Cache usage is probably affected most by array declarations. If you do have a precision dependence, there is a possibility, in some applications, that local promotion to double will help it.
0 Kudos
Steven_L_Intel1
Employee
986 Views
To answer the question as posed, no, there is no way to cause the compiler to interpret constants explicitly designated double as if they were single.
0 Kudos
anthonyrichards
New Contributor III
986 Views
Can you not do global edits to replace 0d0, 1d0, 2d0, etc. and 0d+, 0d-, 1d+ , etc. to strings with E replacing d and D ?
0 Kudos
art-croucher
Beginner
986 Views
Thanks for the replies.

I had checked with Fortran Support before posting, so I was pretty sure there was no way to globally deprecate DOUBLE to SINGLE.

Because this isn't code I wrote, I was afraid to do global replaces of the constants based on some *D* mask. I might have fouled something else up and had a hard time finding it. (One of these days I will convince my org to get CM software...)

I know that the array declarations use a lot more memory than the constants, but I recalled that in Fortran the result of mixed-mode math is of the higher precision type. So a big R*4 array multiplied by an R*8 constant produces an R*8 array, and then bigimplicit type conversions during either ?? the assignment or the return from the subroutine??. Based on TIM18's reply, I wondered if I understood the problem well enough.

So I did a little more RTFM and found in the Users Guide Part 2:
--------
You can use different sizes of the same general data type in an expression with >>minimal or no effect on run-time performance<<. For example, using REAL, DOUBLE PRECISION, and COMPLEX floating-point numbers in the same floating-point arithmetic expression has minimal or no effect on run-time performance. However, this practice of mixing different sizes of the same general data type in an expression can lead to unexpected results due to operations being performed in a lower precision than desired.
--------
So I will just globally change the variable declarations, leave the constants as R*8, and see what happens.

Thanks,

Art
0 Kudos
anthonyrichards
New Contributor III
986 Views
In my experience, changing REAL*8 to REAL*4 will give you different answers...and they will be more inaccurate. Beware!
0 Kudos
art-croucher
Beginner
986 Views
Yep, I know I will have a lot of V&V to do if I go to R*4. There isn't a lot of sensitive math in the model (large linear systems, or small differences of big numbers), so I have hope.

Anyway, I'll do the easy test first. If the program doesn't run significantly faster as SINGLE than DOUBLE, then I won't have to bother.

Art
0 Kudos
Reply