Re: Portable isfinite for gfortran 4.0.3 and ifort 8.1/9.0



The following can often be used to do so. I tested g95 and ifort 9.0.

! false for +inf, -inf and nans if things don't trap
LOGICAL FUNCTION isfinite(a)
REAL :: a
isfinite = (a-a).EQ.0
END FUNCTION isfinite

LOGICAL :: isfinite
write(6,*) isfinite(1.0/1.0)
write(6,*) isfinite(1.0/0.0)
write(6,*) isfinite(0.0/0.0)
END

You can use optimisation (e.g. -O3) but with ifort you need the flag
-mp while you should not use -ffast-math if using g95. Needless to say
that the above is not foolproof if compiled with random compiler
options or compilers.

BTW: Is it possible to determine the name of the compiler from inside
the code?

sometimes it is possible in combination with preprocessing. E.g. :

#if defined(__G95__)
write(6,*) " g95 in use"
#fi

will include the write statement if you use 'g95 -cpp' to compile (or
use .F90 as a filename extension) whereas the line will not be present
if you preprocess with a different compiler. Other compilers have
similar features.

Cheers,

Joost

.



Relevant Pages

  • Re: How to Make F77 Program Faster (g95 compiler) ??
    ... The g95 compiler has the following Option Synopsis: ... and 3 means more aggressive optimization, ... the computation of polynomials in your code. ...
    (comp.lang.fortran)
  • Re: How to Make F77 Program Faster (g95 compiler) ??
    ... The g95 compiler has the following Option Synopsis: ... and 3 means more aggressive optimization, ... count the number of times a routine is called and the execution, ...
    (comp.lang.fortran)
  • Re: Compiling LAPACK with ATLAS on cygwin using g95
    ... I normally compile it using Intel Fortran and link it against the Intel MKL, which takes care of all the LAPACK and BLAS calls. ... To make the comparison fairer I would like to employ a well-optimized set of BLAS, i.e., the ATLAS BLAS, when I compile and link with g95. ... is there a way to compile/install the ATLAS BLAS under cygwin in a way that is compatible with g95? ... are there any gotchas to look out for when compiling LAPACK under cygwin with the g95 compiler? ...
    (comp.lang.fortran)
  • Re: Updateing old fortran code
    ... The old compiler is "Microsoft fortran 77 3.2" which is quite ... I found g95 from the Free Software Foundation but I've been ... input a file from the command line. ...
    (comp.lang.fortran)
  • Updateing old fortran code
    ... I'm of the opinion that using a new compiler will likely solve this ... The old compiler is "Microsoft fortran 77 3.2" which is quite ... I found g95 from the Free Software Foundation but I've been ... no longer functions. ...
    (comp.lang.fortran)