Fortran to Python

  • Thread starter Jeroen Ruigrok van der Werven
  • Start date
J

Jeroen Ruigrok van der Werven

I got someone who asked me to make changes in an old Fortran program she is
using for some calculations.
The calculations are pretty standard aside from 2 calls to DLINCG (an IMSL
numerical_libraries function to calculate an inverse matrix).

What I wonder about, does anybody have a Fortran to Python conversion page
somewhere to map some of the basic types to Python equivalents?
What kind of speed difference should I expect?
 
D

Dennis Lee Bieber

What I wonder about, does anybody have a Fortran to Python conversion page
somewhere to map some of the basic types to Python equivalents?
What kind of speed difference should I expect?

integer => integer
real/double => float
complex/double-complex => complex

If the FORTRAN is using single precision reals, I'd expect a
slow-down in Python just on that alone, as Python uses doubles as the
only float type. There is also the overhead of object access for each.

There is a reason FORTRAN hasn't died... namely a LOT of highly
optimized number crunching!
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
M

MartinRinehart

Jeroen said:
I got someone who asked me to make changes in an old Fortran program she is
using for some calculations.

Why convert? Modern Fortran is an object oriented, structured language
with the singular advantage that it can run old Fortran programs.
 
J

Jeroen Ruigrok van der Werven

-On [20080105 11:21] said:
Why convert? Modern Fortran is an object oriented, structured language
with the singular advantage that it can run old Fortran programs.

With all due respect to Fortran but I find the syntax to be utterly
horrendous. :)

Furthermore, the code is not really heavy number crunching in that it seems to
warrant explicit use in Fortran. At most it takes about 2 seconds on a current
day PC to calculate some of these values.

Furthermore it currently has a dependency on the Visual Numerics IMSL library.
For just some calculations to warrant the cost of both this library and a
Fortran compiler seems a bit excessive.

Given we use Matlab in-house, next to C# (and perhaps F# in the future), and
some Python it makes more sense to stick to your domain-specific knowledge
rather than maintaining some relic from the past.
 
J

Jeroen Ruigrok van der Werven

-On [20080104 19:21] said:
If the FORTRAN is using single precision reals, I'd expect a
slow-down in Python just on that alone, as Python uses doubles as the
only float type. There is also the overhead of object access for each.

In this case it uses complex*16 and real*8. Is a real*8 a single precision
real?
 
R

Robert Kern

Jeroen said:
-On [20080104 19:21] said:
If the FORTRAN is using single precision reals, I'd expect a
slow-down in Python just on that alone, as Python uses doubles as the
only float type. There is also the overhead of object access for each.

In this case it uses complex*16 and real*8. Is a real*8 a single precision
real?

Double precision. These map to the Python complex and float types exactly.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
E

Evgenii Rudnyi

I got someone who asked me to make changes in an old Fortran program she is
using for some calculations.
The calculations are pretty standard aside from 2 calls to DLINCG (an IMSL
numerical_libraries function to calculate an inverse matrix).

What I wonder about, does anybody have a Fortran to Python conversion page
somewhere to map some of the basic types to Python equivalents?
What kind of speed difference should I expect?

When it comes to matrices the difference can be quite big. You can
find the comparison of NumPy, Fortran 77, C, and C++ for matrix
multiplication with and without optimized BLAS at

http://matrixprogramming.com/MatrixMultiply/

NumPy interfaces optimized BLAS, and you can find a LAPACK interface
in SciPy, so it is a good choice.

Evgenii
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top