Pierre Hugonne wrote:
> robin wrote:
> >
> > > Phillip Helbig wrote:
> > >
> > > In fact the SELECTED_***_KIND functions have little practical
> > > value
> >
> > On the contrary, they enable the writing of portable codes
> > that use sufficient of the processor's hardware to satisfy
> > the user's requirement. For example, if you want 15-digit
> > accuracy, then you would specify "selected_real_kind(15)"
> > On a 32-bit machine, you would get 64-bit precision, but on a
> > 64-bit machine, you would get single precision (64 bits) -- the same
> > accuracy, approximately.
>
> I know how to use SELECTED_REAL_KIND() :-)
>
> The point is that all the program I've written up to now make
> some calls to external libraries, and in that case SELECTED_REAL_KIND
> brings more problems than solutions:
>
> if I declare two arrays:
>
> REAL(selected_real_kind(12)) :: a(n), b(n)
>
> I want to compute their dot product using BLAS routines: which
> one should I call: SDOT or DDOT ??
For the dot product, there's the intrinsic DOT_PRODUCT for which the
problem doesn't arise.
In any case, it would seem that a wrapper is needed, so that the
specific call is decided by the compiler [generic subroutine].
> I don't know to which one
> between REAL or DOUBLE PRECISION does correspond selected_real_kind(12).
> It could be also none of them on some systems!
It's possible to test whether it corresponds to
single or double precision. (just compare the kinds):
if ( kind (1.0) == selected_real_kind(12) ) then . . .
Similarly for kind (1.0d0)....
> This is just one example of potential problems, I've several others...
> > >, unless you write fortran-only code, without any call to
> > > external libraries such as LAPACK. I gave up with them and I came
> > > back to REAL and DOUBLE PRECISION
> >
> > Neither gives precision beyond "double" when you're
> > using a system that supports three classes of floating-point.
> > Again, SRK gives you access to the extra precision.
>
> Correct (even if I've never used "beyond double").
>
> I agree that SELECTED_REAL_KIND() is potentially a very powerful
> and attractive feature, perhaps one of the best ideas in F90. But
> unfortunatly it lacks something to be practically used (something
> like "standard" -or commonly accepted- kind values).
I gave a practical use above: It can "choose" to use
64-bit floating-point regardless of whether the machine is
32-bit or 64 bit.
It can also be used to ensure that a guaranteed minimim precision
is selected.
It can also be used to select automatically the maximum precision
available on the machine.
> > > (OK, for integers you have to use
> > > SELECTED_INT_KIND, since there are no other standard way to
> > > declare long integers).
> >
> > Sort of shoots holes in your statement above.....
> Best regards,
> +-----------------------------------+----------------------------+
> | Pierre Hugonnet | mail....CGG |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|