gnu optimization: -O3 for Fortran flags, -O2 for C flags?
Tom Roche
Tom_Roche@pobox.com
Mon Nov 21 22:17:00 GMT 2011
Tom Roche Mon, 21 Nov 2011 10:22:12 -0500
>>> [A legacy code's] 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?
Steve Kargl Mon, 21 Nov 2011 07:31:48 -0800
>> 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,
good point--it is
>> I'll suggest that -march=native is a good idea.
>> MFLAGS = -m64 -march=native
>> COPTFLAGS = -O2 ${MFLAGS} -funroll-loops -ftree-vectorize -Wall
>> FOPTFLAGS = ${COPTFLAGS}
Tim Prince Mon, 21 Nov 2011 11:13:05 -0500
> 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.
Unfortunately I don't currently know that much about this code.
> 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 [which] are best not used without full testing.
For this build, I'm trying
MFLAGS = -m64 -march=native
OPTFLAGS = -O2 ${MFLAGS} -funroll-loops --param max-unroll-times=4 -ftree-vectorize
COPTFLAGS = ${OPTFLAGS} -Wall
FOPTFLAGS = ${OPTFLAGS}
which hopefully is neither too conservative nor too aggressive.
Please lemme know if anything looks obviously wrong, other than -Wall:
unfortunately gfortran goes nuts (and I go scrollblind) on this
old code with -Wall.
your assistance is appreciated! Tom Roche <Tom_Roche@pobox.com>
More information about the Fortran
mailing list