On Fri, 26 Jun 1998, Pierre Hugonnet wrote:
<snip>
> If each package uses its own
> selected_real_kind('wanted precision','wanted range')
> it will be not far from a nightmare for us, the users: we will
> have to work with the same kinds as in the packages, and if we
> use several packages we will spend a large part of our time
> to do conversions between kinds or to check the kind
> correspondances...
>
> That's why a commonly accepted set of kind definitions would be useful.
> It would combine the advantage of DOUBLE PRECISION (common definition
> for everybody), and the advantages of the modern features introduced
> by F90 (selection of a kind according to its precision/range)
>
> Of course we would have to limit to a few real kinds, which would
> cover 99.9% of the needs. For instance:
>
> ISO_REAL_KIND_1 = selected_real_kind(p= 6,r= 25)
> ISO_REAL_KIND_2 = selected_real_kind(p=12,r= 250)
> ISO_REAL_KIND_3 = selected_real_kind(p=24,r=2500)
On this point I fully agree with Pierre. In all practical circumstances
there will be at most three different floating point precisions
single (mostly now IEEE 32-bit with p=6,r=37)
double 64-bit p=15,r=307
quadruple/extended 128 or 80 p>20, r>??
(on DEC Alphas: 128-bit, p=33,r=4031)
There is no reason not to set a recommended name and minimal precision.
The same applies also to integers, typically 2,3 or 4 kinds( 8,16,32,64 bits).
Another reason is the binding to C (e.g. in MPI, OpenGL, etc.). This
will become/is an important issue and, as Pierre pointed out, the Babel
of KIND parameters in various packages could be a minor nightmare.
The Standard Committee is in the best position to recommend (written by someone
else?) a module (a la ISO_VARYING_STRING) that sets and defines names for
floating/integer/character kinds.
Every Fortran compiler would have to provide this module adopted and
ready for use on the computer in question.
Cheers,
Werner
PS: the code below lets you check the various kinds of integers and
floating points implemented on your machine. It is also F compatible.
-----------------------------------------------------------------------
module kind_type
implicit none
type, public :: fp_kind
integer :: p, r, k
end type fp_kind
type, public :: int_kind
integer :: r, k
end type int_kind
end module kind_type
program kinds
! Displays all floating point and integer kinds implemented
! on a machine together with range and precision.
use kind_type
implicit none
type(int_kind), dimension(20) :: ik
type(fp_kind), dimension(20) :: fp
integer :: dp, er, i, f1,f2
fp = fp_kind(0,0,0)
ik = int_kind(0,0)
! Floating Points implemented
! Find Precisions.
dp = 1
i = 0
do
f1 = selected_real_kind( p = dp )
f2 = selected_real_kind( p = dp +1 )
if( f1 < 1 ) then ! Precision >=dp is not implemented
exit
else if( f1/=f2 ) then
i = i +1
fp(i)%p = dp
fp(i)%k = f1
end if
dp = dp +1
end do
! Find Ranges:
er = 1
i = 0
do
f1 = selected_real_kind( r = er )
f2 = selected_real_kind( r = er +1 )
if( f1 < 1 ) then ! Range >=er is not implemented
exit
else if( f1/=f2 ) then
i = i +1
fp(i)%r = er
fp(i)%k = f1
end if
er = er +1
end do
! Integer Ranges:
er = 1
i = 0
do
f1 = selected_int_kind( er )
f2 = selected_int_kind( er +1 )
if( f1 < 1 ) then ! Range >=er is not implemented
exit
else if( f1/=f2 ) then
i = i +1
ik(i)%r = er
ik(i)%k = f1
end if
er = er +1
end do
! Output
write(unit=*,fmt="(A//A)") &
" Floating Point Kinds implemented:" &
," Kind Precision Range"
do i=1,count( fp%p>0 )
write(unit=*,fmt="(I5,I12,I10)") fp(i)%k, fp(i)%p, fp(i)%r
end do
write(unit=*,fmt="(//A//A)") &
" Integer Kinds implemented:" &
," Kind Range"
do i=1,count( ik%r>0 )
write(unit=*,fmt="(I5,I8)") ik(i)%k, ik(i)%r
end do
end program kinds
-----------------------------------------------------------------------
| Werner W Schulz |
| Dept of Chemistry email: [log in to unmask] |
| University of Cambridge Phone: (+44) (0)1223 336 502 |
| Lensfield Road Secretary: 1223 336 338 |
| Cambridge CB2 1EW Fax: 1223 336 536 |
| United Kingdom WWW: |
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|