On 10/7/19 6:15 AM, JCampbell wrote:
> On Monday, October 7, 2019 at 3:01:43 AM UTC+11, Ron Shepard wrote:
>> On 10/6/19 2:26 AM, JCampbell wrote:
>>> I do not know of any computers that support Fortran 90+ that don't support IEEE754.
>>> For this reason I suggest that KIND should be marked as an Obsolescent feature, as there is no longer any need for this syntax.
>>
>> I think that KIND is one of the best features of fortran compared to
>> other programming languages. It allows the precision of an entire
>> program, millions of lines of code, to be changed by modifying a single
>> statement, and it allows very precise control of the precision of
>> intermediates within expressions.
>
> Ron, Thanks for your comments, although I do disagree.
>
> Rather than the “best”, I would consider the idea of being able to change the precision of "millions of lines of code" as the worst of outcomes. This ignores that the algorithms in this code have been developed for a particular precision. The suitability of the algorithm or approach is dependent on that precision being used. Change the precision and the algorithm is probably no longer suitable or "tuned".
This is a numerical analysis issue, not a language issue. The use of
KINDs allows the programmer to write robust portable code, but it alone
does not address all aspects of the numerical analysis. Furthermore,
when combined with explicit interfaces (modules, contained procedures,
etc.), fortran does catch many types of mixed precision problems at
compile time through TKR matching.
> For my applied analysis, there is only one practical option: hardware implemented 64-bit. (I could certainly be interested in hardware implemented 128-bit vector instructions, although I wonder what it would deliver.)
> Back in 1970's when there was significant variation in the precisions on offer, changing the hardware not only required change to the type declarations but also required much care with numeric parameters used in the code.
If you don't do mixed precision programming, if all you do is hardware
implemented 64-bit, then the use of fortran KINDS is not really an issue
is it?
> You also state that KIND "allows very precise control of the precision of intermediates within expressions". I don't think this is the case. It is a dangerous illusion.
> For Selected_Real_Kind, while there are two parameters “p” and “r”, the reality is there are typically only 2 hardware supported precisions available, while other options come with a significant performance (128 bit) or implementation penalty (eg: gFortran's 80 bit on 64-bit OS).
Yes, fortran requires only two supported precisions, and even then, it
is not too picky about the details. There would be downsides if the
language required more, just as there would be downsides to it
prohibiting more. The KINDs approach seems to be a nice, practical, open
ended, compromise.
>
> If you review most presented coders use of Selected_Real_Kind, the values of p and r are not chosen based on the precision required of the algorithm, but on the precision identified for the required practical option, hence the typical coding of:
>
> integer, parameter :: rp = Selected_Real_Kind ( 6, 37 )
> integer, parameter :: dp = Selected_Real_Kind ( 15, 307 )
Yes, of course, we all do that in certain programs when that is all that
is required.
> I would like to select a higher precision accumulator for dot_product, but with the performance required of vector instructions, this is not a practicality. While Selected_Real_Kind implies many options, the practical reality is very different.
I agree about this issue. At present, in order to write a higher
precision dot product, you must do something like:
real(ep) :: se, xe, ye
...
se = 0.0_ep
do i = 1, N
xe = x(i)
ye = y(i)
se = se + xe * ye
enddo
This requires that the optimizer does a lot for you that you cannot
specify directly in the language. What you might really want is to
replace that last statement with something like
se = se + dprod(x(i),y(i),kind=ep)
with the appropriately generalized version of the dprod() intrinsic. For
some reason, this has not been done. Or, to go a step further, perhaps
something like
se = dot_product(x,y,kind=ep)
if you want a higher-level implementation of the operation.
In any case, the KIND facility of fortran is not the limitation, as the
above hypothetical expressions show.
> FORALL is a good example of a coding approach that has not kept up with the recent changes in multi-thread programming. KIND is going the same way, as it is a clumsy approach to support of available precisions.
FORALL was never what programmers wanted or needed in the first place in
the 1980s. There were already numerous implementations of parallel do
loops using compiler directives that were available to show what was
needed, but the standards committee ignored all that and did something
else entirely.
We can just agree to disagree about the flexibility and utility of KIND.
$.02 -Ron Shepard