gnu optimization: -O3 for Fortran flags, -O2 for C flags?

Steve Kargl sgk@troutmask.apl.washington.edu
Mon Nov 21 15:32:00 GMT 2011


On Mon, Nov 21, 2011 at 10:22:12AM -0500, Tom Roche wrote:
> 
> 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?
> 

With my own applications, I have rarely seen any advantage
to using -O3 over -O2 with gfortran.  I would howver recommend
adding adding -funroll-loops and -ftree-vectorize to your
options and the removal of -ffast-math.  Also, if your code
is being compiled to run on a specific system, I'll suggest
that -march=native is a good idea.

MFLAGS    = -m64 -march=native
COPTFLAGS = -O2 ${MFLAGS} -funroll-loops -ftree-vectorize -Wall
FOPTFLAGS = ${COPTFLAGS}

-- 
Steve



More information about the Fortran mailing list