[petsc-dev] fortran literals

Munson, Todd tmunson at mcs.anl.gov
Fri Sep 2 11:40:34 CDT 2016

I am confused by Blaise's statement.  "selected_real_kind(5)" is well defined across
compilers; it returns an integer value that can be used in the kind statements and
selected real numbers with at least 5 digits of precision.

With the exception of -1, -2, and -3 (plus -4 and -5 in Fortran 2008) indicating
no support.  The actual integer values returned are compiler specific.

If we wanted to have a better chance of getting ieee single, double, and quad,
we should probably use something like:


in PETSc.  You would still need to do some testing during configuration to
really ensure that


is the same as a C float, double, and __float128 respectively?


Its not until Fortran 2008 that the standard has constants for REAL32, REAL64,
and REAL128 defined in the ISO_FORTRAN_ENV module.  However, if we are using
Fortran 2008 features, go all out and use the ISO_C_BINDING module with
the C_FLOAT and C_DOUBLE constants!  Some compilers, such as the gnu
compilers. extend the constants and include C_FLOAT128.

I have attached a simple program to output the kinds.  Try it on your machine.
On my machine with gfortran from gcc version 4.8.5 (MacPorts gcc48 4.8.5_0), I
get the following:

 C_FLOAT   :            4
 C_DOUBLE  :            8
 C_FLOAT128:           16
 REAL32    :            4
 REAL64    :            8
 REAL128   :           10
 sel(6)    :            4
 sel(15)   :            8
 sel(16)   :           10
 sel(33)   :           16

The integers provide the number of bytes on my machine.  Note REAL128 is
apparently an 80-bit long double and not a 128-bit __float128!!  The
type using selected_real_kind appears correct though.  The same
happens for REAL128 with gfortran from gcc 4.9.3, gcc 5.4.0,
and gcc 6.1.0 on my machine.


> On Sep 2, 2016, at 12:51 AM, William Gropp <wgropp at illinois.edu> wrote:
> This is true.  The meaning of integer values of kind is up to the implementation, and at least two choices are in use.
> Bill
> William Gropp
> Acting Director and Chief Scientist, NCSA
> Director, Parallel Computing Institute
> Thomas M. Siebel Chair in Computer Science
> University of Illinois Urbana-Champaign
> On Sep 1, 2016, at 6:15 PM, Blaise A Bourdin <bourdin at lsu.edu> wrote:
>> If I recall correctly, fortran does not mandate that "selected_real_kind(5)" means the same across compilers, so that hardcoding kind values may not be portable.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20160902/11989f77/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mytest.f
Type: application/octet-stream
Size: 647 bytes
Desc: mytest.f
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20160902/11989f77/attachment.obj>

More information about the petsc-dev mailing list