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 8.3 (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 April 2019 (Mojave).
Although scientific programs use a variety of languages (basic, pascal, c, java, perl, python, ...), a substantial base of scientific code is written in fortran. Most (though not all) computational engines supported by WebMO are written in fortran. This resource concentrates on fortran compilers and the tools needed to support them.
g77 is the gnu fortran77 compiler. It was last produced with gnu compiler collection (gcc) 3.4, and has since been supplanted with gfortran which supports fortran95. Because of the free-cost and high quality of the gnu copmpilers, a significant amount of software has been developed for and compiled with the g77 compiler.
gfortran is the new gnu fortran compiler, which attempts to follow the fortran95 standard. As such, it should be backward compatible with fortran77 and fortran90. It also promises to attempt following future fortran standards, such as fortran2003. gfortran replaces the gnu g77 compiler and is included with gnu compiler collection (gcc) 4.0 and higher.
Although Apple XCode Tools includes gcc 4.X, it is not a complete implementation and lacks gfortran. However, various implementations of gfortran have been compiled and are available at GCC Wiki GFortranBinaries, Tools - R (and Fortran) for Mac OS X, or High Performance Computing for Mac OS X. These implementations vary by version, platform supported, and integration with XCode Tools. Important: Install only one implementation of gfortran, as each version would overwrite portions of the others!
f2c TRANSLATOR / f77 COMPILERf2c is a fortran77-to-c source code translator. Because f2c is written in c and its ouput is c, both of which can be compiled natively on unix operating systems, f2c offers a very transportable compiler solution for compiling fortran programs. f2c also offers a means of converting large fortran libraries, such as LAPACK, into c. f2c is still actively maintained and is available at
f77 was the first complete fortran77 compiler and was written in c. The original f77 program is no longer available for current computer architectures. However, f2c is based on the original f77 program, and the f2c distribution contains a f77 wrapper script that combines the f2c translation and c compilation steps. The f77 script also supports many command line options commonly associated with fortran compilers. Since the f77 script calls f2c, which in turn is based upon the original f77 program, the f77 script within the f2c distribution represents the most current implementation of the original f77 program.
Gcc is part of Xcode. You can download it from the App Store. Once it is installed and you start it, it will ask you to install command line tools. Once it is installed, you can open a terminal window and check if it has been installed:
macOS Sierra (10.12): download gfortran 6.3OS X El Capitan (10.11): download gfortran 6.1OS X Yosemite (10.10): download gfortran 5.2 or gfortran 4.9.2OS X Mavericks (10.9): download gfortran 4.9.0 or gfortran 4.8.2OS X Mountain Lion (10.8): download gfortran 4.8.2OS X Lion (10.7): download gfortran 4.8.2
If you want the version of gfortran to match the versions of gcc, g++, etc. installed on your machine, download the appropriate version of gfortran from here. The R developers and SciPy developers recommend this method.
Disclaimer: I'm part of the EasyBuild team. Building GCC (with gfortran included) should work on OS X, but other builds may be troublesome. We're working on it, do let us know if you run into trouble.
DISCLAIMER: I provide this information here to aid my memory and in thehope that others will find it a useful resource based on my experiences of installing a gfortran compiler on Macs. I am not a computer scientist orFortran guru and, as such, am unlikely to be able to help you with Fortran code,compilation or runtime problems.
I currently choose to use the relevant gfortran installer (.dmg) packagesprovided through the GCC Wiki (opens in new window). Note that the files areinstalled in /usr/local system directories which require the administratorpassword.
I no longer use this distribution since the upgrade to GCC 4.6(.2), withwhich I have experienced execution problems that I do not understand withprograms compiled using it. For instance, specifically and oddly, the SOLVEmodule of GAMIT hangs and never completes after returning the status message\"SOLVE/lsquar: Finding and removing dependent biases\" when compiled with thisversion of GCC. I have also found this same behaviour with gfortran 4.6.1 onFedora Linux systems and this may well be a problem with this version on othersystems too. A solution seems to be to add the \"-fno-whole-file\" flag to FFLAGSin libraries/Makefile.config, which disables a feature that is switched on bydefault with GCC 4.6.
There are also various tar-files of gfortran distributions provided at the High PerformanceComputing web page. There are up-to-date distributions for some systems(only Mac OS X 10.7 (Lion), 10.8 (Mountain Lion), 10.9 (Mavericks) and 10.10(Yosemite) as of the last update of this page).
I recommend not to choose a package containing a version that is not a stable version accordingto the main GCC web site. Furthermore, for simplicity, I would recommendonly to install the relevant \"gfortran only\" distributions.
Previously, I had preferred to use the gfortran packages distributed inassociation with the R Project. These can be found in the \"Apple Xcode gcc-42add-ons\" section of their Tools web page (opens in new window) or via the direct linksbelow. These gfortran packages and updates are specifically built to matchApple's own gcc builds. This does mean that the version is back at GCC 4.2,which is undoubtedly where it will stay since GCC changed their licensing andApple has stopped updating their GCC distribution with Xcode. Nonetheless, myexperience shows that this distribution is one that always works.
It is slightly more difficult to uninstall the R Project or HPC distribution. HPC distributes gfortran as a tar-file. Therefore each file contained in thetar-file should be removed. The easiest way to do this is probably to run thecommand:
where [tar-file] is the package, for example gfortran-4.7-bin.tar.gz,gfortran-lion.tar.gz, gfortran-snwleo-intel-bin.tar.gz, etc. This will removeall files but not directories, which may contain other files that are not to be removed. To remove empty directories only, then run the command:
The R Project distribution is a .pkg file and this adds another level ofcomplication. To list the files that were installed from this package, oneneeds to locate the \"receipt\", which is a .bom file. On my system (Mac OS X10.8, Mountain Lion) the file is located at/private/var/db/receipts/org.r-project.gcc-42.darwin11.pkg.bom (was/private/var/db/receipts/org.r-project.gnuFortran42.lion.usr.pkg.bom for Mac OSX 10.7, Lion; or /private/var/db/receipts/org.r-project.mac.tools.gfortran.bom for Mac OS X 10.6, Snow Leopard). To find the file, run a command such as:
Highly efficient machine-specific implementations of the BLAS are available formany modern high-performance computers. For details of known vendor- orISV-provided BLAS, consult the BLAS FAQ. Alternatively, the user can downloadATLAS to automatically generate an optimized BLAS library for the architecture.A Fortran 77 reference implementation of the BLAS is available from netlib;however, its use is discouraged as it will not perform as well as a specificallytuned implementation.
Finally, you can switch between different versions or set the default one with the update-alternatives (see manpage). There are many online tutorials on how to use this feature. A well structured one using as an example C and C++ can be found here, you can apply the same logic by replacing either gcc or g++ with gfortran.
OpenCoarrays is an open-source software project that produces an application binary interface (ABI) used by the GNU Compiler Collection (GCC) Fortran front-end to build executable programs that leverage the parallel programming features of Fortran 2018. Since OpenCoarrays is not a separate compiler, we include it here, under gfortran.
While with gfortran you can compile perfectly valid code using coarrays, the generated binaries will only run in a single image (image is a Fortran term for a parallel process), that is, in serial mode. OpenCoarrays allows running code in parallel on shared- and distributed-memory machines, similar to MPI:
GCC 4, 5, 7, 8, 9, 10, 11, 12 (auto-vectorizing gcc with OpenMP):Compiled using source code from the GNU servers. This contains current versions (8.3 is the stable release) of 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. For more information, see this webpage. Download my binaries, and cd to the download folder. Then gunzip gcc-12.1-m1-bin.tar.gz (if your browser didn't do so already) and then sudo tar -xvf gcc-12.1-m1-bin.tar -C /. It installs everything in /usr/local. You can invoke the Fortran 95 compiler by simply typing gfortran. You will also need to have Apple's XCode Tools installed from the Mac App Store. With XCode 4 or better you will need to download the command-line tools as an additional step. You will find the option to download the command-line tools in XCode's Prefere