You are on page 1of 2

Python vs Fortran in Scientific Computing

AddThis
Share to Sharing Buttons to TwitterShare to Facebook32Share to Google+
LinkedIn18Share
An in-depth look at critical coding choices for todays scientific and
math problems

Python is huge, free and open source, but FORTRAN is the oldest
computer language still in common use. Which is better for todays
scientific and math programming tasks? Slashdot Media Contributing
Editor David Bolton walks through the decision-making process for you.

On the face of it, this is a one sided battle. Its putting a heavily optimized static
typed compiler for the worlds oldest yet still used programming language
(Fortran) against a dynamic typed newcomer dating back to 1991 (Python).

Now if it was just a straightforward comparison Python would win hands down;
its increasingly more popular in 5th place in the Tiobe Index for April 2016,
reflecting how mainstream its become. Fortran is at position 26. Websites such
as Dice.com show nearly 7,000 Python jobs across the USA. (Fortran has 87 at
the time of writing). And the fact that Intel is releasing a Python interpreter
speaks volumes.

But in Fortrans favor, it is the poster boy for scientific computing with the only
real alternative being C++. In fact those were the only languages not counting C
that Intel supported until their Python came along and the same two languages
that Open MPI was developed for. Theres a vast amount of scientific and
engineering code written in Fortran and still in use. A survey of Fortran users in
2015 had 100% thinking theyd still be using Fortran in five years time.
Given the cost of redeveloping older software, its very likely that they will
indeed be still have the same software.

Scientific Computing

Scientific Computing aka computational science draws on the areas of algorithms


and computer science along with the hardware infrastructure to develop and run
software to solve scientific problems. Those are typically problems that arent
easily solved by theory or practice. Computer simulations replace or compliment
physical and/or theoretical work.
One early example of this was someone who I knew personally while I was doing
my degree. He was the late Professor Gordon Blair who was modeling
combustion in motorcycle engines. His modified Yamaha-engine bikes
outperformed Yamahas bikes in major races so they joined forces. That was in
the late 70s, so he was well ahead of the field. The hardware he used was a
mainframe, software was written in Fortran IV with the NAG library.

Areas that scientific computing includes atmospheric science, seismology,


structural analysis, chemical processes, fluid flow, climate modeling, nanotech,
aerospace, environmental studies and nuclear engineering of weapons and
reactors. Its probably fair to say that the bulk of this code was written in Fortran
and there is a lot of it about.

Why Python?
Although people think of the execution time as the most important factor, theres
also the question of how long it takes to learn the programming language in the
first place and then write the software. Back in the 1960s and 1970s before
microcomputers, computer processing time was an expensive resource.
Programmers were cheap by comparison and it didnt matter that they took
longer to develop the software and optimize it, saving money from reduced
execution time when running it.

Theres also the question of how much processing power is actually needed.
Perhaps only 5% of the code needs 95% of the processing time. The rest of the
code might be concerned with managing the data, doing data I/O and doesnt
need to be so optimal. So it can be written in Python and linked in to NumPy or
even Fortran or C libraries for the really fast code. Or use Cython (Compiled
Python) when possible.

Now though its programming time that is expensive and Python is a lot easier to
learn than Fortran. Unlike Fortran, Pythons arrays are not fast. In fact they are
probably a 100 times slower but the NumPy library largely reduces this. I
suspect, that if it is out and out performance you want, then Fortran will win but
Python with SciPy and NumPy is a very potent combination. Add to this the
nearly 80,000 packages in pypi (the Python Package Index) which includes 16
sub-categories of the Scientific/Engineering category (from AI to visualization)
and Python looks very promising indeed.

Other reasons to consider languages other than Fortran might be if the program
need symbolic programming. Python has the SymPy library for symbolic
mathematics. Other languages in this space include Lisp and Haskell.

Conclusion

Fortran will be around for a few years, as long as existing software needs
maintained. But starting from scratch, you probably wouldnt want to use
Fortran. Python seems to be a very good alternative. Its free, open source and
there are a lot of packages available.
Another language though still in its early days that would seem to fit in the
scientific computing space is Julia which can call Python, Fortran and C functions
and produces very fast code machine code.

You might also like