gnu optimization: -O3 for Fortran flags, -O2 for C flags?
Tim Prince
n8tm@aol.com
Mon Nov 21 16:13:00 GMT 2011
On 11/21/2011 10:22 AM, Tom Roche wrote:
>
> Apologies if the following is off-topic for this list (feel free to
> redirect) or unduly lacking in expertise (my background is mostly
> java/perl/python):
>
> I'm recompiling legacy atmospheric-modeling code with gcc/gfortran
> that has previously been done (and is almost entirely documented)
> using icc/ifc (except for the *really* out-of-date docs, which use
> PGI). I've been told to try to rebuild the entire chain with
> consistent flags, which makes sense, so I'm doing a lot of Makefile-
> reading. I'm noticing: the build's fortran flags typically use -O3,
> while its C flags typically use -O2, e.g.
>
> MFLAGS = -m64
> COPTFLAGS = -O2 ${MFLAGS} -ffast-math -funroll-loops -Wall
> FOPTFLAGS = -O3 ${MFLAGS}
>
> Is this generally sensible for gcc/gfortran? Or is this usage something
> that might be application-specific? Or this usage just inappropriate?
>
> TIA, Tom Roche<Tom_Roche@pobox.com>
The answer would definitely be application specific. In the frequently
occurring situation where the performance critical auto-vectorizable
code is all in Fortran, it makes sense to set -O3 for gfortran and a
lower option for C, but then it may not make sense to set the aggressive
-ffast-math and -funroll-loops options for C. Current versions of
gcc/gfortran are safer with -ffast-math than past ones. Some experts on
gfortran recommend setting -O2 -ftree-vectorize so as to get the
auto-vectorization without -O3. In my experience, on recent CPUs,
-funroll-loops is better used with the modifiers --param
max-unroll-times=4; with those modifiers, it works well with gfortran.
-ffast-math (without further modifiers) gives you limited range complex,
reciprocal-math, and auto-vectorization of sum reduction. Those are
best not used without full testing.
--
Tim Prince
More information about the Fortran
mailing list