I am experimenting with writing vectorized FORTRAN subroutines to be incorporated in the Abaqus finite element solver. Some learning materials define constant numbers which are used in formulae as parameters in the beginning of the code, e.g.:
parameter ( zero = 0.d0, one = 1.d0, two = 2.d0, third = 1.d0 / 3.d0, half = 0.5d0, op5 = 1.5d0)
So instead of writing 0.5 * a
one would write half * a
. Is there a performance advantage to this?
EDIT: I dug deeper and found this in page 11 (slide A3.22) of this file:
The PARAMETER assignments yield accurate floating point constant definitions on any platform.
No, there is no performance difference whatsoever. The generated code will be exactly the same. It is probably used just to make using these numbers more convenient or (supposedly) readable.
BUT you must be careful. Just 0.5 is a (default) single precision number. You must use the way used in the constant definition. 0.5d0
is double precision and the constant will help you not to forget the d0
. In binary number formats 0.5 is exactly re presentable anyway but one third, for example, is not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With