Python and fortran Interface suggestion

Chris Angelico rosuav at gmail.com
Sun Apr 19 17:23:05 CEST 2015


On Mon, Apr 20, 2015 at 12:48 AM, pauld11718 <pauld11718 at gmail.com> wrote:
> I am developing a code under Ubuntu(64bit) with python using various libraries. Once done, I need to generate an executable which shall be interfaced with fortran program on account of further collaboration. The python executable shall be used with windows(32bit).
>
> So, I guess everytime my python executable is called by the fortran code on each time step, all those
> from **** import *'s
> will be executed and are time consuming (which is not at all required). Moreover, creating executable for windows, using linux is that possible by any means?
>
> What is a better methodology for addresing such interfacing?

Hmm. Let's divide that into several parts.

1) You need to have a Python program that interfaces with Fortran.

Does it need to call functions from a Fortran library, or is it simply
invoked by the Fortran program and that's it? If the latter, it's not
hard. But if you're concerned about startup time, you may want to
consider having your Python program keep running indefinitely, and
have some alternative means of communicating between them. For
instance, Python might create a socket or pipe, which the Fortran
program opens and writes to, and then reads a response. (If you can't
edit the Fortran code at all, it's pretty easy to write a slim stub
executable that does the socket/pipe handling.) Or alternatively,
install Python onto a RAM disk, to improve startup time that way.

2) You need to run the whole kit and caboodle on Windows. The best way
to do this is simply to write clean Python code, and then install a
Windows Python, and everything will work just fine. However, Windows
does tend to have far worse disk cache management than Linux has,
which will exacerbate your startup delays.

3) Above all, you need to know exactly how long things are taking.
Before you start trying to speed things up, first figure out where
it's actually slow. You never know, it might already be fast enough!

Check out some details, see how things go. On the face of it, I'd
guess that what you want to do will be quite doable.

ChrisA



More information about the Python-list mailing list