Академический Документы
Профессиональный Документы
Культура Документы
Bob
1 Ease of Learning
Python and Fortran are both relatively easy-to-learn languages. Its probably easier to find good
Python learning materials than good Fortran learning materials because Python is used more widely,
and Fortran is currently considered a specialty language for numerical computing.
I believe the transition from Python to Fortran would be easier. Python is an interpreted language,
so the number of steps it takes to get your first program running is smaller (open the interpreter, type
print(Hello, world!) at the prompt) than it is for Fortran (write a Hello world program, compile,
run). I also think that there are better materials to teach object-oriented style in Python than in
Fortran, and theres more Python code available on GitHub than Fortran code.
1
then wrapping it with a Python interface. There are libraries that facilitate this process (like Cython
and f2py), and tutorials to help you; it is generally not onerous.
4 Scope of Use
Python is used more widely overall as a general-purpose language. Fortran is largely limited to
numerical and scientific computing, and is mainly competing with C and C++ for users in that
domain.
In computational science, Python typically doesnt compete directly with compiled languages
due to the performance penalties I mentioned. You would use Python for cases where you want
high productivity and performance is a secondary consideration, such as in prototyping numerically
intensive algorithms, data processing, and visualization. You would use Fortran (or another compiled
language) when you have a good idea of what your algorithm and application design should be, youre
willing to spend more time writing and debugging your code, and performance is paramount. (For
instance, performance is a limiting step in your simulation process, or it is a key deliverable in your
research.) A common strategy is to mix Python and a compiled language (usually C or C++, but
Fortran has been used also), and only use the compiled language for the most performance-sensitive
parts of the code; the development cost is, of course, that its harder to write and debug a program
in two languages than a program in a single language.
In terms of parallelism, the current MPI standard (MPI-3) has native Fortran and C bindings.
The MPI-2 standard had native C++ bindings, but MPI-3 does not, and you would have to use the
C bindings. Third-party MPI bindings exist, such as mpi4py. Ive used mpi4py; it works well, and is
straightforward to use. For large-scale parallelism (tens of thousands of cores), youd probably want
to use a compiled language because things like dynamically loading the Python modules will bite you
in the ass at scale if you do it in a nave way. There are ways to get around that bottleneck, as
demonstrated by the PyClaw developers, but its simpler to avoid it.
5 Portability
The biggest advantage of interpreted source code over compiled source code is portability.
If your source code is compiled, you need to compile a different executable for each type of processor
and/or platform that you want your program to run on (e.g. one for Windows x86, one for Windows
x64, one for Linux x64, and so on). Furthermore, unless your code is completely standards compliant
and does not use any platform-specific functions/libraries, you will actually need to write and maintain
multiple code bases!
If your source code is interpreted, you only need to write it once and it can be interpreted and
executed by an appropriate interpreter on any platform! Its portable! Note that an interpreter itself
is an executable program that is written and compiled for a specific platform.
An advantage of compiled code is that it hides the source code from the end user (which might
be intellectual property) because instead of deploying the original human-readable source code, you
deploy an obscure binary executable file.