Re: real*4 array, wrong output compile with pgf77 -r8

From: Paul Van Delst (paul.vandelst_at_noaa.gov)
Date: 04/07/04


Date: Wed, 07 Apr 2004 11:35:47 -0400

Lei Shi wrote:
> Hi all, I use pgf77 to compile my fortran code. I did a test in a super
> cluster (32),
>
> Program one: declare real array use real. compile use 1) pgf77 -r4 2)
> pgf77
> -r8. Both produce accurate result.
>
> Program two: identical program, except specify all real array to real*4
> (intend to save cpu). compile use 1) pgf77 -r4 produce accurate result
> 2)
> pgf77 -r8 produce wrong result.
>
> Any one has knowledge of that or similar experience? Why and how to
> slove the problem.
>
> The reason why I do this is trying to save cpu time by specify real*4.

How is this saving cpu time?

> the program is part of a large parallel fortran code which has to be
> compile with -r8.

-r4 and -r8 mean to interpret "DOUBLE PRECISION" variables as "REAL" (-r4) or "REAL"
variables as "DOUBLE PRECISION" (-r8). My experience has shown that these compiler
switches only operate on the *DEFAULT* definitions. If you also have declarations that use
REAL*4 or REAL*8 (which are non-standard btw) _*they will not be affected*_ by the -r4 or
-r8 switch.

This can have a catastrophic effect on common blocks and argument lists depending on how
diligent you are in your variable declarations.

I think you should decide to use either REAL, REAL*4, or REAL*8 but not to mix them (in
general). Sometimes defining specific types is necessary (say for I/O routines), but these
should be totally isolated and well documented and be able to handle the consequences of
using a -r4 or -r8 type of switch.

Just my personal observations using pgf90 on a linux box and xlf on an AIX box. I don't
know how universal the treatment of automatic promotion/demotion of types is.

cheers,

paulv

p.s. Same applies to -i2, -i4, and -i8 options also. If you have
        INTEGER*4 myint
      and use -i2, myint *won't* "become" a 2-byte integer. It will
      still be a 4-byte int.



Relevant Pages