Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a performance advantage to defining numbers as parameters in FORTRAN

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.

like image 494
Mohammadreza Khoshbin Avatar asked Jan 01 '23 12:01

Mohammadreza Khoshbin


1 Answers

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.

like image 87
Vladimir F Героям слава Avatar answered Jan 31 '23 05:01

Vladimir F Героям слава