Message from discussion example of KIND to replace DOUBLE PRECISION
From: Jason Blevins <jrble...@sdf.lonestar.org>
Subject: Re: example of KIND to replace DOUBLE PRECISION
Date: Sat, 09 May 2009 13:27:26 -0400
Organization: Duke University, Durham, NC, USA
Content-Type: text/plain; charset=us-ascii
X-Trace: gargoyle.oit.duke.edu 1241890046 30000 126.96.36.199 (9 May 2009 17:27:26 GMT)
NNTP-Posting-Date: Sat, 9 May 2009 17:27:26 +0000 (UTC)
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.93 (gnu/linux)
On May 8, 2009, at 1:27 PM, Richard Maine wrote:
> Dick Hendrickson <dick.hendrick...@att.net> wrote:
>> The purpose of the KIND system is to allow you to specify what
>> you need or want for the precision of floating point variables.
> Also, a thing that I particularly like about the KIND system is its
> consistency. (A thing that I dislike about it is the use of integers for
> KIND numbers, which promulgates nonportable practices as well as just
> plain mistakes; oh well). Look at what is involved in adding a new
> precision, such as the quad precision that is moderately common these
> days. With the "old-fashioned" way, this involves quite a lot of new
> syntax. You need a new declaration statement, an exponent letter
> (certainly in the source code, and often also for formatted I/O), a
> bunch of new intrinsic names, and I forget what else.
> Try taking a program that was written for one precision and converting
> it to use another one. That can come up for many reasons. Perhaps you
> are on a compiler where single and double precision are different from
> the compiler the code was written for. Or perhaps you are applying the
> code to problems that require larger precision than the probleme
> envisioned when the code was written. In my youth, I used to spend quite
> a lot of time doing precision conversions like that (most often as a
> consequence of moving to a new computer with a different default
> precision). I can testify that it can be a *LOT* of work in some cases.
> It is possible to write code that converts easily, but you have to be
> very deliberate about the intention of making it easy to convert.
> With KIND parameters, you can define the kind parameter value on a
> single line in a module. Then it is a one-line change to convert the
> entire program. (Ok, programs that use multiple precisions can be more
> complicated than that in some cases.) All the syntax is unchanged; the
> same syntax works for single, double, quad, or any other oddball
> precision that you might have.
It's still a little unclear to me how to manage kinds in the context of
a program that uses multiple libraries, each with their own working
precision kind parameters defined.
In the context of a single self-contained program or library, I would
simply define a working precision kind parameter and use it uniformly
throughout the program. For a program which uses a single external
library, say LAPACK95, I would probably use the precision parameters
defined by the library:
use la_precision, only: wp
However, what do you do when you need to use multiple libraries?
(Or, when you're designing a library that would likely be used
with others?) Let's say that library_a defined
integer, parameter :: a_wp = selected_real_kind(1.d0)
while library_b uses
integer, parameter :: b_wp = selected_real_kind(15, 307)
In some cases these will be the same, but you can't assume they
What kind should you use in your program? If, say, you use the
precision from library_a:
use library_a, wp => a_wp
real(wp) :: x, y
What happens if I call a routine from library_b using x and y
if the kinds happen to be different?
call b_routine(x, y)
Is this handled automatically by casting or does it only work if the
kind parameters are identical?
I guess my main questions are what are the best practices for selecting
kind parameters when designing a library (I tend to like the renaming
facility of LAPACK95) and how should you handle (potentially) different
precisions from different libraries in a single program?
Ph.D. Candidate, Department of Economics, Duke University