You are not logged in.

#1 2014-08-27 06:12:40

dakane
Member
Registered: 2014-08-18
Posts: 7

Gfortran with f08 standard and 128 bit real variables

Hello all,

I've been using Arch for a week now, and love it so far. The wiki has kept me from posting here since there is so much great documentation there.

So, at first I was just trying to compile a simple program with gfortran, taking advantage of the 128 bit real (floating point) variables in fortran 2008. I got this error:

  real(128) a,b,c
          1
Error: Kind 128 not supported for type REAL at (1)

So, after some reading I found that you can get a list of supported real kinds (for those who don't know fortran, a kind is the number of bits in a variable) like this:

use, intrinsic :: iso_fortran_env
write(*,*) REAL_KINDS

My output from that is 4 8 10 16. I expected it to include 32, 64, and 128 as well. EDIT: This is not affected by running gfortran with the -march=corei7 option as https://gcc.gnu.org/gcc-4.6/changes.html makes me think might be needed as I have an i3.
I read in the gfortran manual about the -std=fxx option, and noticed that using the -std=f95 option makes it compile programs that are in fortran 95. However, using the option -std=f03 or -std=f08 I get this error:

gfortran: error: unrecognized command line option ‘-std=f03’

Of course f03 is replaced by f08 if I use that option.
According to https://gcc.gnu.org/ml/fortran/2011-07/msg00061.html 128 bit reals should be available from gfortran 4.6. gfortran --version reveals that I have version 4.9.1 installed, which should be the newest one since I installed it a couple of hours ago via pacman.

Do I have to install something special to get support for the newer fortran standards? I don't really know much about this, I'm not a Linux or GCC or Fortran expert.

Last edited by dakane (2014-08-27 06:29:20)

Offline

#2 2014-08-27 06:42:16

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: Gfortran with f08 standard and 128 bit real variables

Moving to Programming and Scripting...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2014-08-28 04:33:49

dakane
Member
Registered: 2014-08-18
Posts: 7

Re: Gfortran with f08 standard and 128 bit real variables

I figured it out, mostly. 16 (or any other kind at least for REAL type variables) in gfortran means the number of bytes, not bits in a variable. I previously thought it was the number of bits which is wrong. So, kind=16 means that the variable indeed has 16 bytes (128 bits=16 bytes). Incidentally, kind=10 also causes variables to have 128 bytes. This applies only to gfortran, other compilers may well be different, I don't know.

Furthermore, the correct ways to compile in gfortran with the fortran 2003 or 2008 standards are:

gfortran -std=f2008 foo.f08
gfortran -std=f2003 bar.f03

and not -std=f08 or f03 as I previously thought.

Gfortran shouldn't actually need the -std argument, it should be able to tell based on the file extension. I know it compiles that way but don't know how to test thoroughly whether or not it is using the correct standard.

However, this leads me to a new question: This gfortan page
https://gcc.gnu.org/onlinedocs/gfortran … 5fENV.html
refers to real kinds 32, 64, and 128. What does one have to do to use those kinds?

Offline

#4 2014-11-28 10:27:26

raul_l
Member
From: Amsterdam
Registered: 2014-11-04
Posts: 58

Re: Gfortran with f08 standard and 128 bit real variables

dakane wrote:

What does one have to do to use those kinds?

You import them from the iso_fortran_env module, like this

use, intrinsic :: iso_fortran_env, only: real128

Variables are then declared using

real(real128) :: x

It should be noted that currently in gfortran real128 actually refers to the kind of a 10 byte variable - that means the extended and not the true quad precision. This is unlike the Intel compiler where real128 has the correct meaning.


Raul Laasner

Offline

Board footer

Powered by FluxBB