Fortran on a Mac
First let me say I’m not a big Fortran user but any blog posts about Fortran always seem to be very popular, and I do get asked regularly about how to compile Fortran applications.
If you have followed the instructions on Cheminformatics on a Mac you already have Xcode, Command Line tools and gfortran installed using Homebrew. Alternatively you can install GCC 6.2 (auto-vectorizing gcc with OpenMP) which includes gfortran (free, open source, GNU Fortran 95 compiler), gcc (GNU C) and g++ (GNU C++) compilers that can perform auto-vectorization (i.e. modify code to take advantage of AltiVec/SSE, automatically) and other sophisticated optimizations like OpenMP. There are detailed instructions here, last updated Sept 2016 (El Capitan & Sierra).
PGI optimizing multi-core x64 compilers for Linux, MacOS & Windows with support for debugging and profiling of local MPI processes. A complete OpenMP/MPI SDK for high performance computing on the latest Intel and AMD CPUs. On Intel Haswell CPUs with OpenMP, PGI delivers multicore performance more than 50% faster than the latest GCC compilers. That’s like buying a cluster with 50% more compute nodes.
There is also a free version of the PGI compiler
Absoft Pro Fortran 2014 v14 Absoft Pro Fortran 2014 v14 Compiler Suite For Mac OS X
Absoft's Pro Fortran tool suite automates building extremely fast parallel code on multi-core systems. Compiler features include: APO, IPO, PGFDO optimizers and auto vectorization, Absoft's exclusive Dynamic AP load balancing technology - performance increases up to 20% on multi-core systems, SMP graphical code analyzer and OpenMP 3.0 support, Absoft Window Environment (AWE), External Libraries and Tools Plug-in, expanded F2003 & F2008 support and enhanced Fx3 graphical debugger.
Arguably the best fortran compiler for Intel macs are the Intel compilers ifort.
offer an industry-leading C compiler, C++ compiler, and Fortran compiler, including optimization features and multithreading capabilities; highly optimized performance libraries; and error-checking, security, and profiling tools, allowing developers to create multithreaded applications and maximize application performance, security, and reliability.
They can build pretty much any fortran code including very old fortran (as far back as fortran 66) and support the latest fortran standards. And in many people’s experience produce the fastest runtime executables. They also integrate directly into Xcode and tend to be the most up to date in terms of compatibility with the apple dev tools. They are also link compatible with both gcc and clang. ifort also includes a fortran version of their MLK library.
They provide redistribute libraries for dynamically linked binaries, but they also support static linking, so in either case binaries can be distributed to people without the compiler installed. They aren't free on Mac (they are free on Linux), but the academic price is relatively inexpensive. Additionally they have a C/C++ compiler suite, but the performance gain over clang is no longer there. They are better than gcc in terms of codgen, however. So if you aren't using MLK there may be no benefit.
NAG Fortran Compiler.
The NAG Fortran Compiler (derived from the world's first Fortran 90 compiler which was developed by NAG in 1991) is robust, highly tested, and valued by developers all over the globe for its checking capabilities and detailed error reporting. The compiler is available on Unix platforms as well as for Microsoft Windows and Mac OS X. Release 5.3.1 has extensive support for both legacy and modern Fortran features, and also supports parallel programming with OpenMP.
Given the move towards parallel processing it is useful to note that most of the compilers support OpenMP, OpenMP is a specification for a set of compiler directives, library routines, and environment variables that can be used to specify high-level parallelism in Fortran and C/C++ programs.
Compiling Fortran applications on a Mac
If you have Homebrew installed then the easiest way to install gfortran is as part of gcc. I’ve written a page of instructions for setting up a Mac using Homebrew here.
brew update brew install gcc
We can check gfortran is installed using, in the Terminal type
man -k fortran gfortran(1) - GNU Fortran compiler
and the location
which gfortran /usr/local/bin/gfortran
which should be an alias to "/usr/local/Cellar/gcc/4.8.3/bin/gfortran"
Critic2: A program for real-space analysis of quantum chemical interactions in solids DOI
Download critic2 from: http://gatsby.ucmerced.edu/downloads/critic2/critic2-1.0.tar.gz
cd critic2-1.0 ./configure make install
This compiles and installs:
- critic2, basin2off, off2off, charges.sh executables to /usr/local/bin
- data files to /usr/local/share/critic2
- help files to /usr/local/share/doc/critic2
A couple of Fortran experts have contacted me and suggested I include these flags that are often very useful for developers.
-static-libgcc : includes all necessary system routines in the binary and thus avoids error messages at runtime when some library is missing on the user computer
-mmacosx-version-min=10.1 : generates binaries able to work under several os x versions
-fno-underscoring : supresses the trailing undersore for names of functions and subroutines (but then you must take care about conflicting names)
Useful Fortran Programs
Critic2 is a program for the topological analysis of real-space scalar fields in periodic systems
DALTON two powerful molecular electronic structure programs, Dalton and lsDalton. Together, the two programs provide an extensive functionality for the calculations of molecular properties at the HF, DFT, MCSCF, and CC levels of theory. Many of these properties are ONLY available in the DALTON2013 suite.
GAMESS General ab-initio quantum chemistry package.
Postg is a program that implements the calculation of the dispersion energy and related quantities using the exchange-hole dipole moment model.
Quantum Expresso is an integrated suite of Open-Source computer codes for electronic-structure calculations and materials modeling at the nanoscale. It is based on density-functional theory, plane waves, and pseudopotentials
Molecular simulation packages from the Mezei lab
Molpro a complete system of ab initio programs for molecular electronic structure calculations
NWChem aims to provide its users with computational chemistry tools that are scalable both in their ability to treat large scientific computational chemistry problems efficiently, and in their use of available parallel computing resources from high-performance parallel supercomputers to conventional workstation clusters
TINKER a general package for molecular mechanics and dynamics.
Photran is an IDE and refactoring tool for Fortran based on Eclipse
CLFORTRAN – Pure Fortran Interface to OpenCL
FTranProjectBuilder Mac's only native Fortran programming environment (IDE)
Simply Fortran includes the GNU Fortran compiler, an advanced development environment including project management, and an integrated debugger for fast and easy installation.
HPC Mac OSX High performance computing on a Mac
gXXforrtran is available on GitHub This package provides a “pgf77” script that emulates the Portland Group’s PGI fortran 77 compiler, instead using the Free Software Foundation’s GNU gfortran compiler instead. This emulation is sufficient to allow packages such as Gaussian03, that would otherwise require a commercial compiler, to be built using open source tools.
CUDA Fortran for Scientists and Engineers shows how high-performance application developers can leverage the power of GPUs using Fortran
Updated 21 August 2017