gfortran.org


With all the gfortran options available, how do you pick one that gives
you the best performance ?

Plus, you have a couple of different 'classes' of optimisations.  Most
everyone is familiar with the overall optimisation levels, -01,-02,-O3,
but options also exist for specific chips and instruction sets.

A good all around option, which gives fast code without taking too many
dangerous shortcuts is -O2.   -fast-math is for those that who want the 
fastest possible code; not the most correct code.  -O2 should compile 
in a reasonable amount of time and a source level debugger should be
usable (like gdb).

Another place to optimise, is to compile for the specific chip set you
intend on running the code (which may or may not be the chip set you are
using to compile the code).  i386 will work on a wide range of systems, but
for fastest code match the arch with the chip you intend to use for running 
the compiled code.

Here are the architecture options:

  "generic",
  "i386",
  "i486",
  "pentium",
  "pentium-mmx",
  "pentiumpro",
  "pentium2",
  "pentium3",
  "pentium4",
  "pentium-m",
  "prescott",
  "nocona",
  "core2",
  "geode",
  "k6",
  "k6-2",
  "k6-3",
  "athlon",
  "athlon-4",
  "k8",
  "amdfam10"

  gfortran -O2 -g -march=core2 xxx.f -o xxx

Since GCC 4.2 there exists the architecture option "native", so to optimize
for the host architecture you can simply use

  gfortran -O2 -g -march=native xxx.f -o xxx


On this site

Contact

bdavis9659@sbcglobal.net
Google