There were programs here that had been written five thousand years ago, before Humankind ever left Earth. The wonder of it–the horror of it, Sura said–was that unlike the useless wrecks of Canberra’s past, these programs still worked! And via a million million circuitous threads of inheritance, many of the oldest programs still ran in the bowels of the Qeng Ho system.
–Vernor Vinge, A Deepness in the Sky
Since the early 1990s, we’ve seen an explosion of new programming languages and frameworks, mainly driven by the widespread use of the internet and, later, mobile devices. C++ took over computer science departments, Java has been revered in the enterprise, JavaScript redefined the modern web, R became the mother tongue of statisticians, and Python took the machine learning world by storm. Where does Fortran fit in all this? Through steady revisions of the language, Fortran has maintained a solid footing in its niche domain, high-performance computing (HPC). Its computational efficiency is still unparalleled, with only C and C++ coming close. Unlike C and C++, Fortran has been designed for array-oriented calculations, and is, in my opinion, significantly easier to learn and program. A more recent strong argument for Fortran has come about through its native support for parallel programming.
What is high-performance computing?
High-performance computing (HPC) is the practice of combining computer resources to solve computational problems that would otherwise not be possible with a single desktop computer. HPC systems typically aggregate hundreds or thousands of servers and connect them with fast networks. Most HPC systems today run some flavor of Linux OS.
Despite being a decades-old technology, Fortran has several attractive features that make it indispensable, even compared to more recent languages:
- Array-oriented –Fortran provides whole-array arithmetic and operations, which greatly simplify element-wise operations. Consider the task of multiplying two two-dimensional arrays:do j = 1, jm do i = 1, im c(i,j) = a(i,j) * b(i,j) end do end doWith Fortran’s whole-array arithmetic, you writec = a * bThis is not only more expressive and readable code, it also hints to the compiler that it can choose the optimal way to perform the operation. Arrays lend themselves well to CPU architectures and computer memory because they’re contiguous sequences of numbers, and thus mirror the physical layout of the memory. Fortran compilers are capable of generating extremely efficient machine code, thanks to the assumptions that they can safely make.
- The only parallel language developed by a standards committee (ISO) –The Fortran standards committee ensures that the development of Fortran goes in the direction that supports its target audience: computational scientists and engineers.
- Mature libraries for science, engineering, and math –Fortran started in the 1950s as the programming language for science, engineering, and mathematics. Decades later, we have a rich legacy of robust and trusted libraries for linear algebra, numerical differentiation and integration, and other mathematical problems. These libraries have been used and tested by generations of programmers, to the point that they are guaranteed to be almost bug-free.
- Growing general-purpose library ecosystem –In the past decade, Fortran has also seen a growing ecosystem of general-purpose libraries: text parsing and manipulation, I/O libraries for many data formats, working with dates and times, collections and data structures, and so on. Any programming language is as powerful as its libraries, and the growing number of Fortran libraries make it more useful today than ever before.
- Unmatched performance –Compiled Fortran programs are as close to the metal as it gets with high-level programming languages. This is thanks to both its array-oriented design and mature compilers that continuously improve at optimizing code. If you’re working on a problem that does math on large arrays, few other languages come close to Fortran’s performance.
In summary, learn Fortran if you need to implement efficient and parallel numerical operations on large multidimensional arrays.