Mac Fortran Compilers

Finally, I get to start writing about using Fortran on a Mac!  In this post, I’ll give a short survey of the Fortran compilers that are available on the Mac. In the next, I plan to compare their performance on one of my codes.

Compiler availability has never been better for Mac Fortran users. In the pre-Intel days there might have been only one or two Fortran compilers available at any given time. Today there are six to choose from. Two of these are free; four are commercial products. And since Macs have been multi-core and multiprocessor for several years, we can now write HPC parallel programs using MPI or OpenMP that run on our desktops. GPU programming, the hot topic of the day, is also possible with a couple of the compilers. 

The six Fortran compilers for the Mac are:

  • Absoft Pro Fortran
  • GNU gfortran
  • g95
  • Intel ifort
  • NAG nagfor
  • PGI pgfortran

I'd like to thank the Absoft, NAG and PGI folks for the trial versions of their compilers, which allowed me to support them in FTranProjectBuilder. 

The Free Fortran Compilers

The two free Fortran compilers, gfortran and g95, run on Macs.


The free gfortran is part of the gnu compiler suite and can be downloaded from Installation is painless using a standard package installer. The compiler is easy to use and runs great. I was a little apprehensive about using a compiler that is as young as it is, but those fears were unfounded. The compiler has many of my favorite Fortran 2003 and 2008 features implemented, plus it has OpenMP support. A full list of those features can be found at After only a few weeks, I’ve decided that I really like using gfortran for my less computationally expensive problems. It is simple to set up and use.


The free g95 compiler can be downloaded from Unlike gfortran, g95 installation does not use a standard installer, and requires one to go into for some command line magic. But it is not too bad. I first unpacked the .tar file that I downloaded in new a directory. Then I navigated to that directory in Finally, I had to insert a symbolic link by typing sudo ln -s $PWD/g95-install/bin/i686-apple-darwin10.3.0-g95 /usr/bin/g95 (for the current version) to put a link in the standard directories. That completed the installation. The current binaries date to August of 2010, which seems a bit old to me. The g95 web site notes that some parts of the 2003 standard have been implemented, but I didn’t find a list of what those parts were. A table dating to the end of 2011 that presents which 2003 features have been implemented for the g95 compiler and others can be found at

The Commercial Fortran Compilers

Four commercial compilers are available for the Mac. The jump to a commercial compiler means support for questions, precompiled libraries like LAPACK and specialized “performance libraries,” e.g. for vector and parallel processing. The prices that I quote below for each compiler are for a single user license. Except for the nagfor compiler, the prices are directly from the companys' web sites.

Absoft ProFortran ($699 Commercial/$299 Academic)

Absoft's is the granddaddy of Fortran compilers on the Mac. They had the first “real” Fortran compiler for the Mac. I still have a 400K disk for the compiler that I bought for my Fat Mac right after the compiler came out of Beta in 1985. Over the years, Absoft has continued to support the Mac with compilers under various names, including “Microsoft Fortran”. 

The Absoft compiler installs with a standard package installer and weighs in at a hefty 685 Mb. (It comes with a lot of goodies.) The tools install in the Applications directory rather than the standard /usr/bin. For that reason, environment variables need to be set for UNIX tools to find them. Part of the standard installation recommends having those variables installed for command line access. Say yes. The license management is unobtrusive and just requires typing in the license key during the installation process.

Absoft’s is the only Fortran compiler for the Mac that comes with an IDE. For awhile in the past, the IDE was a native Mac app. For the last few years, however, Absoft has been supplying a “cross platform” IDE, implemented in Qt. Although touted as a feature, cross-platform means that menu items are not in their usual places and operations like drag and drop and saving don’t work as expected. For those reasons and more, I haven’t used the new version much.

Absoft’s compiler has full F90/95 support plus support for OpenMP. The included BLAS and LAPACK libraries mean that one does not have to download, compile and link those oneself. F2003 support, however, appears to be very limited, especially compared to the other compilers, including the free ones.

Intel ifort ($699 Commercial/$280 Academic/$49 Student)

Mac users got to use the ifort compiler once Apple switched to Intel CPUs. Like the other commercial compilers, ifort packs a punch with the MKL library, BLAS, LAPACK and vector operations. On my codes, this compiler gives the best performance, up to three times faster than gfortran. For high performance computing the compiler supports MPI, OpenMP, OpenCL and coarrays. The compiler has support for nearly all the F2003 features and some of the F2008 ones. Of particular note is the incredible student price. For the performance gains that it gives over the free compilers, buying ifort should be a no-brainer for a student.

Installation is done with a standard installer. Like Absoft’s approach, license management is taken care of by typing in the license key during the installation process. The compiler is installed in a standard location in /opt. ifort does not have its own IDE, but does integrate with Xcode.

The ifort compiler can be extremely complex to use. It supports a huge number of options and environment variables. Whereas, for example, running a program in parallel using OpenMP with the gfortran compiler is a simple matter of compiling with the proper compiler flags, the ifort compiler requires several environment variables to be set, too. To help figure out what options to set for a given build, Intel has a web page where you can select options from pulldown menus and it will list the linker and compiler options.

For instance, to compile and run using LAPACK and BLAS on my iMac it tells me to link with

 $(MKLROOT)/lib/libmkl_blas95_ilp64.a  $(MKLROOT)/lib/libmkl_lapack95_ilp64.a $(MKLROOT)/lib/libmkl_intel_ilp64.a $(MKLROOT)/lib/libmkl_sequential.a $(MKLROOT)/lib/libmkl_core.a -lpthread -lm

and use the compiler options

-i8 -I$(MKLROOT)/include/intel64/ilp64  -I$(MKLROOT)/include

It adds the following notes:

o Set the INCLUDE, MKLROOT, DYLD_LIBRARY_PATH, LIBRARY_PATH, CPATH, FPATH and NLSPATH environment variables in the command shell using one of mklvars script files in the 'bin' subdirectory of the Intel(R) MKL installation directory. Please see also Intel(R) MKL User Guide.

o Please be sure that you have used the recommended compiler options for the selected interface layer. Warning: linking Intel(R) MKL libraries with your objects compiled for different interface layer may lead to run-time errors.

All-in-all, configuring the ifort compiler for a given build can be extremely frustrating, and support is done through user forums. As a scientist, I would expect that the compiler writers would be far better equipped than me to decide what options should be set for my machine. From my user’s point of view, linking to LAPACK should be no more complicated than setting a single flag: -LAPACK. Just a suggestion.

NAG nagfor ($1000)

The Numerical Algorithms Group produces the famous NAG Library and also produced one of the first F90 compilers. The current release supports most of F2003, including, for instance, FINAL subroutines that others currently don't. The NAG Fortran compiler also supports OpenMP.

The nagfor compiler is the most expensive of the commercial Mac Compilers, and the only one that does not come with a standard installer. You have to contact NAG directly to find out the prices for different license options. The price that I was quoted was for a commercial single user license.  

Installation is done on the command line by running a shell script. The instructions that came with the download information were for a generic unix/linux installation, not for Mac installation. Setting up the license is done manually and requires finding the hostid of the Mac by running a supplied command in the terminal. I get the feeling that NAG expects their products to be installed by an organization’s systems group rather than by individual users.

Support is done by email. I had one support question regarding unit 6 output buffering, which cannot be turned off globally. The question was answered right away confirming this fact. I was really impressed when I got a follow-up email a few days later that forwarded a code example from the lead developer showing how to use a C call to turn off buffering. They also said that they would probably add an environment variable in the next release to do this. That’s great support.  

PGI pgfortran ($699 Commercial/$359 Academic)

The Portland Group focuses on high performance computing applications with their compilers. It installs, for instance, mpif90 and mpif77 as part of the default installation. The pgfortran compiler also supports OpenMP and CUDA Fortran. Unlike the other  compilers, PGI’s Fortran has full support for F2003. The compiler ships with optimized LAPACK, BLAS and FFT libraries, too. One can optionally buy the well-known IMSL library along with the Fortran compiler.

Installation is performed using a package installer, which, like the ifort installer, places the components in the /opt directory. A path environment variable has to be set for UNIX tools to find the components. PGI supplies a PGI2012.terminal document that automatically set up the shell for me.  

PGI has the most complicated license management of the six compilers. A background daemon is used to manage the license. It must be installed manually, including putting it in the startup folder. The directions for setting up the license daemon take four pages in the installation manual! There is a separate chapter for Mac installation, so we know that PGI takes Mac programmers seriously.

A week after I got the compiler I got a phone call from the sales office asking if everything was going OK and if I had any questions. Again, I had questions about handling output buffering and I was transferred to a live support person. The question needed a consultation with the developer group, and I got an email the next day describing what I had to do. I was impressed with the personal attention. PGI also has a user forum for support.  

Parting Comments.

That's my quick description of the six compilers now available on the Mac. We are a lot better off now than we used to be. I am most familiar with the Absoft and ifort compilers, and have been using the gfortran compiler more and more. The g95 compiler produces too many warning errors like "-macosx_version_min not specified." I don't have as much experience with the NAG and PGI compilers on my Mac, but I have been impressed with both companies' support. The lack of an installer and Mac specific installation instructions for the NAG compiler, especially for the price, makes me wary about that company's commitment to the platform. I'd be happy for them to convince me that I am wrong, because the compiler generates some pretty fast code.

© Nocturnal Aviation Software 2011-2017. 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.