autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: flags for different fortran compilers


From: Ralf Wildenhues
Subject: Re: flags for different fortran compilers
Date: Wed, 2 Feb 2011 08:22:21 +0100
User-agent: Mutt/1.5.20 (2010-08-04)

* Eve-Marie Devaliere wrote on Tue, Feb 01, 2011 at 10:43:00PM CET:
> > Well, we've already clarified that you should drop -c.
> yes , my bad, I just copied what they had in the rules.macros file
> > For any gfortran-specific flag that there is no good macro for, you can
> > start off by wrapping it in this if clause:
> >
> > if test $ac_cv_fc_compiler_gnu = yes; then
> >   FCFLAGS="$FCFLAGS -fbounds-check -fconvert=big-endian ..."
> > fi
> so would you suggest doing this instead of the macro you suggested
> earlier? a combination of both (I am thinking macros for flags that are
> common to more than one compiler and if tests for the ones specific for
> each compiler ; (if I can ever figure out which flags are which....))?
> In their original setup, they had support for the following compilers: 
> xlf95, f95, f90 (SGI IRIX64 MIPSpro, Absoft and  HP-UX), gfortran,
> ifort, pgf95, lf95, g95.

Well, maybe you can then fill the table below of possible flags, and
we can try writing macros for them.

> if you still think I should go the macro way for at least some of the
> compiler flags, would you have an example to suggest to put me on the
> way? I couldn't find the source code of AC_FC_FREEFORM to try figuring
> out...

If your autoconf is installed in $prefix/bin, then the source of that is
usually in $prefix/share/autoconf/autoconf/fortran.m4.


Here's a set of notes about flags I could find from looking at manuals
(cf. <http://www.mail-archive.com/address@hidden/msg16210.html>):

- Endian conversion:
  GCC: -fconvert=big-endian
  Portland: -byteswapio  -Mbyteswapio (in conjunction with AC_C_BIGENDIAN?)
  Intel: F_UFMTENDIAN={big|little} environment variable setting
http://www.tacc.utexas.edu/services/userguides/intel8/fc/f_ug2/cmp_endi.htm
  HP: -convert big_endian
     FORT_CONVERT{,<unit>}=Big_Endian environment variables


- Trap handling:
  GCC: -ffpe-trap=overflow,zero[,invalid,underflow,precision,denormal]
  Portland: -Ktrap=ovf,divz[,inv,unf,inexact,denorm,fp]
            -Kieee
            -Ktrap
  HP: +FP[V][Z][O][U][I][D]
    (upper-case enables, lower-case disables
     invalid fp ops, divide by zero, overflow, underflow, inexact)
  Lahey: -[n]trap [d][i][o][u]  (divide-by-zero, invalid op. overflow, 
underflow)
  IBM: -qflttrap=zerodivide:enable -qsigtrap
       -qnoflttrap
        (zerodivide, underflow, overflow, invalid, inexact, enable,
        imprecise, nanq)
        -qflttrap without suboptions is equivalent to
        -qflttrap=inv:inex:ov:und:zero
        -qsigtrap

   Sun/Oracle: -ftrap=%all,no%inexact
     %all, %none, common, [no%]invalid, [no%]overflow, [no%]underflow,
     %[no%]division, [no%]inexact.
    -ftrap=common is a macro for -ftrap=invalid,overflow,division.


- Array bounds checking:
   GCC: -fbounds-check
   Intel: -check bounds  or -CB
   Portland: -Mbounds
   HP: +check=all  -check_bounds/-nocheck_bounds
   IBM: -qcheck  -C
   Sun/Oracle: -C
   SGI MIPSpro: -C -check_bounds


Array bounds checking would seem fairly easy to cover more or less like
below (modeled more or less like the other tests in fortran.m4); the
biggest issue would be how to effectively test that array bounds
checking is actually working: the test source should fail only when
bounds checking is in place, but pass otherwise.  For now I've merely
taken some example source found on the net, but that can probably be
made shorter, and should ideally conform to both fixed-format as well as
free-format (or adjust itself according to whether AC_FC_FREE_FORMAT has
been called previously or not).

With these things fixed, the macro can IMVHO go into Autoconf.

Cheers,
Ralf

# AC_FC_CHECK_BOUNDS([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
# ----------------------------------------------------------------------
# Look for a compiler flag to turn on array bounds checking for the
# Fortran (FC) compiler, and adds it to FCFLAGS.  Call
# ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
# compile code using new extension) and ACTION-IF-FAILURE (defaults to
# failing with an error message) if not.  (Defined via DEFUN_ONCE to
# prevent flag from being added to FCFLAGS multiple times.)
#
# The known flags are:
#     -fbounds-check: GNU g77, gfortran
# -CB, -check bounds: Intel compiler (icc, ecc, ifort)
#                 -C: Sun/Oracle compiler (f95)
#        -C, -qcheck: IBM compiler (xlf)
#           -Mbounds: Portland Group compiler
#  -C, -check_bounds: SGI compiler
# -check_bounds, +check=all: HP Fortran
AC_DEFUN_ONCE([AC_FC_CHECK_BOUNDS],
[AC_LANG_PUSH([Fortran])dnl
AC_CACHE_CHECK([for Fortran flag to enable array-bounds checking],
               [ac_cv_fc_check_bounds],
[ac_cv_fc_check_bounds=unknown
ac_fc_check_bounds_FCFLAGS_save=$FCFLAGS
for ac_flag in -fbounds-check -check_bounds -Mbounds -qcheck \
               '-check bounds' -CB -C
do
  FCFLAGS="$ac_fc_check_bounds_FCFLAGS_save $ac_flag"
  AC_LINK_IFELSE([[
      subroutine copy(a,b)
      integer a(:), b(:), i
      do i = lbound(a,1), ubound(a,1)
         a(i) = b(i)
      end do
      end subroutine

      program main
      integer, parameter :: n = 20
      integer a(1:n), b(1:n-1), i  ! notice b is declared 1:n-1
      interface
         subroutine copy(a,b)
         integer a(:), b(:), i
         end subroutine
      end interface

      call copy(a,b)
      end program]],
    [# If we can run the program, require failure at run time.
     # In cross-compiling mode, we rely on the compiler not accepting
     # unknown options.
     AS_IF([test "$cross_compiling" = yes],
       [ac_cv_fc_check_bounds=$ac_flag; break],
       [AS_IF([_AC_DO_TOKENS(./conftest$ac_exeext)],
          [],
          [ac_cv_fc_check_bounds=$ac_flag; break])])])
done
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
FCFLAGS=$ac_fc_check_bounds_FCFLAGS_save
])
if test "x$ac_cv_fc_check_bounds" = xunknown; then
  m4_default([$2],
             [AC_MSG_ERROR([no Fortran flag for bounds checking found], 77)])
else
  if test "x$ac_cv_fc_check_bounds" != xnone; then
    FCFLAGS="$FCFLAGS $ac_cv_fc_check_bounds"
  fi
  $1
fi
AC_LANG_POP([Fortran])dnl
])# AC_FC_CHECK_BOUNDS



reply via email to

[Prev in Thread] Current Thread [Next in Thread]