A Mac Fortran Bakeoff

With six Mac Fortran compilers to chose from, the obvious question is “Which one should I get?” Each compiler comes with its own libraries, tools and options. One compiler may be easier to use than another. One may cost less than another. Another may have better 2003/2008 support. But ultimately, I know I want to get the one that produces the fastest executable for my code on my computer.

Fortran benchmarks can be found for Windows and Linux machines at www.polyhedron.com. If you go there and look, you’ll see a wide variation in which compiler gives the fastest code over the 17 tests that they ran. You’ll also see that the results depend strongly on the processor used. This is why the operative phrase is “my code on my computer”. 

I haven’t found compiler benchmarks elsewhere for the Mac, so I decided to put together my experiences with the six Mac Fortran compilers on one of my codes on my computer. As they say, YMMV.

The Test Code

My tests here use one of my high order discontinuous Galerkin spectral element codes that I developed to solve PDEs in conservation law form. It consists of 8000 lines of code in 30 files, but the kernel - the part that gets executed over and over - is about 800 lines. The project is an object oriented Fortran implementation of the algorithms described in the book “Implementing Spectral Methods: Algorithms for Scientists and Engineers”. The test problem that I solve is the classic aerodynamics computation of compressible flow over a NACA0012 airfoil. This isn’t the most complex code that I have, and it was written for flexibility, not raw speed, but it is representative for my needs. 

I used the -O3 option for optimization on each compiler. I did not tweak the options to hunt for the subset that produced the ultimate and super performance. As I noted in my last blog entry, my view as a scientist is that the compiler guys should know more than me.

The Computer

It’s a Mac! To be precise, the system profiler says

  Model Name: iMac

  Model Identifier: iMac8,1

  Processor Name: Intel Core 2 Duo

  Processor Speed: 2.8 GHz

  Number of Processors: 1

  Total Number of Cores: 2

  L2 Cache: 6 MB

  Memory: 4 GB

  Bus Speed: 1.07 GHz

You’ll notice that I don’t buy a new machine every year, or every three years for that matter. But then my machine at my day job is even older. I might expect different results on a newer chip, but I’ll do the tests again when I get one. Finally, I'm running these tests on OS X Lion 10.7.3.

The Results

(This is where you started reading. Right? I know that’s what I do.)

There is a large variation in the code generated by the different compilers. To me, 10% or 20% is not significant, but 50% or factors of two are. Factors of ten are right out.

 In my first graph of the results I plot the CPU time ordered from fastest to slowest:

We see that my code takes ten times longer when compiled with g95 than with the Intel ifort compiler, which was the fastest. g95 is quite the outlier so in the next plot, which shows the time relative to the fastest, I leave it out of the comparison:


So we see that the speed of my code varies by as much as a factor of two and a half depending on which compiler is used. I was surprised and, I guess pleased, that the free gfortran compiler does not fare badly in comparison with other commercial compilers as one might expect. (Or you can turn that around the other way.) Nevertheless, there is a strong argument for spending the money to buy the Intel compiler.

Concluding Remarks

If you look at the Polyhedron comparisons you see that on the Intel Linux tests, every compiler produces the fastest code on at least one benchmark, except for g95. My results are consistent with the overall conclusion that the Intel compiler produces the fastest code and g95 the slowest. For me the decision for the Intel ifort compiler is clear. However, the relative rankings might change from one code to the next. Since each of the commercial compilers has a free trial period, it makes sense to try them out and see how they perform on your own code on your own computer. On the other hand, it won't hurt to install the free gfortran compiler, either. It's performance was consistent with commercial compilers, although it may not come with installed libraries or, for that matter, support.

© Nocturnal Aviation Software 2011-2016. Mac and Mac OS are trademarks of Apple Inc., registered in the U.S. and other countries. iMac drawing by dinodigital. All other trademarks are the property of their respective owners. Privacy Policy. Press Releases.